|
Project Information
Featured
Downloads
Links
|
The Dash Framework enables Java components to be developed with clear and documentable external dependencies on configuration, component wiring, and runtime context. Dash ObtainDashObtain: Provides lazy, thread-safe acquisition of fields with the @Obtain annotation. Like dependency injection, but more declarative. Example @Obtain use (without error handling...): public class Forwarder implements MessageListener {
@Obtain MessageProducer forwardTo;
public void onMessage(Message message) {
forwardTo.send(message);
}
}Dash ContextDashContext: Provides 'safe' global variables: a public static @Context field can be exposed in a thread-safe, thread-local, and execution scoped manner. An example is authenticated User. Contextual and execution scoped access to the current principal user is easy to show: public class Authentication {
@Context static Principal principal;
}
public class Forwarder implements MessageListener {
...
public void onMessage(Message message) {
Processor userDefault = getProcessorFor(Authentication.principal);
...
}
}The reference to Authentication.principal will occur within the scoped execution of a message handler. Within that scope the principal can be setup and reliably removed like this: public class PojoMessageDispatcher {
@WithinContext
public void dispatchMessage(Message message, MessageListener listener) {
Authentication principal = lookupPrincipalFromChannel();
listener.onMessage(message);
}
}The @WithinContext will ensure that principal, once set, will be null-ed out after the dispatchMessage method returns. Implementation TechnologyThese Dash projects are implemented with Java 5 and AspectJ. They support compile and load-time weaving. |