I have an alternative idea (and basic implementation) for communicating between modules. I have dabbled with j2ee web services and enterprise message buses before, and the problem seems similar. One service needs to talk to another, and to mitigate coupling between the services, they communicate via a Message Bus.
Here's a (hopefully) brief description of what I've implemented thus far. I want to get feed back to see if this is a utility that could be contributed to puremvc. I will use the utility regardless, but I wanted to contribute if possible.
The utility consists of the following classes:
MessageBus : Facades register themselves with this singleton class upon creation. In addition, facades will declare here what messages they are interested in, and optionally a transformer to translate the Messages into Notifications.
IMessageTransformer : interface that can be implemented to provide a way of transforming message types into notifications specific to each Module's ApplicationFacade.
MessageTransformer : a default implementation of IMessageTransformer. This is added by default if no transformer is specified.
Here's an example of how to interact with the MessageBus in my current implementation:
override protected function initializeFacade() : void
{
super.initializeFacade();
// Setup message bus connection.
var messageBus : MessageBus = MessageBus.getInstance();
messageBus.registerFacade(NAME, this);
messageBus.registerTransformer(NAME, SessionMessage.LOGIN, new SessionMessageTransformer());
messageBus.registerTransformer(NAME, SessionMessage.LOGOUT, new SessionMessageTransformer());
}
And here's an example of sending a message
MessageBus.getInstance().sendMessage(new SessionMessage(SessionMessage.LOGIN));
The message bus receives the message, uses the module-provided transformer to transform the message into a notification specific to the module, and uses the module's facade to send it.
In this way, all messages sent are propagated as notifications to each Facade registered to the message bus.
The only coupling between modules is to the MessageBus, and to the Messages that will be shared between Modules of an application.
Let me know if this would be a valuable contribution to the project!
Russ