public class SimpleMessageBus
extends java.lang.Object
SimpleMessageBus.MessageHandler
and when a publisher posts a new
message then the receivers will be notified with the message contents.
This is a simplified design pattern for the Event Bus concept. You can read more about the concept from
Google's GWT site. http://code.google.com/webtoolkit/articles/mvp-architecture.html#events
Keep in mind that Message does not refer to user messages that get displayed to the user, but rather they are communication messages.
Because of the simplicity of the Message Bus, a message can be a simple string with no other parameters, or it can be complex object. It is
up the listener/publisher to decide on message and it's contents.Modifier and Type | Class and Description |
---|---|
static interface |
SimpleMessageBus.MessageHandler
A Message Receiver must implement this interface in order to handle a message that is posted.
|
Constructor and Description |
---|
SimpleMessageBus() |
Modifier and Type | Method and Description |
---|---|
java.util.List<SimpleMessageBus.MessageHandler> |
getHandlers(java.lang.String id)
Returns the list of MessageHandlers registers for a given id
|
static SimpleMessageBus |
getInstance() |
void |
postMessage(java.lang.String msgId,
java.lang.Object... args)
Post a message/event for the given message id.
|
void |
registerListener(java.lang.String id,
SimpleMessageBus.MessageHandler handler,
boolean single)
Register a message receiver that will receive messages that posted.
|
void |
removeListener(java.lang.String msgId,
SimpleMessageBus.MessageHandler handler)
Remove the given message handler from the listeners of the given message id.
|
void |
reset()
Resets the event bus.
|
public static SimpleMessageBus getInstance()
public void registerListener(java.lang.String id, SimpleMessageBus.MessageHandler handler, boolean single)
SimpleMessageBus.MessageHandler
instance will
be the only class type that will receive the messages.id
- Message to which this SimpleMessageBus.MessageHandler
will be assignedhandler
- The SimpleMessageBus.MessageHandler
instance that will receive the messagesingle
- if true, then only a single type of SimpleMessageBus.MessageHandler
will be allowed.public void postMessage(java.lang.String msgId, java.lang.Object... args)
msgId
- Unique message idargs
- Message Arguments that specific to each message id typepublic void removeListener(java.lang.String msgId, SimpleMessageBus.MessageHandler handler)
msgId
- Message id from which to remove this SimpleMessageBus.MessageHandler
handler
- SimpleMessageBus.MessageHandler
to removepublic void reset()
public java.util.List<SimpleMessageBus.MessageHandler> getHandlers(java.lang.String id)
id
-