net.sf.bus
Class MessageBus
java.lang.Object
|
+--net.sf.bus.MessageBus
- Direct Known Subclasses:
- MessageBusImpl
- public abstract class MessageBus
- extends java.lang.Object
The purpose of The Message Bus is to allow components to be loosely coupled, by enabling them to
send and receive messages(or events) without knowing what components the messages are intended
for or who sent them.
- Version:
- $Revision: 1.7 $
- Author:
- James Higginbotham
Field Summary |
static java.lang.String |
DEFAULT_CHANNEL
Defines the channel name for the default channel that is always available |
Method Summary |
abstract void |
publish(java.lang.String channel,
java.lang.Object message)
Publishes a message to The Message Bus that will be distributed to all subscribers that meet
the following requirements:
They are subscribed to the same channel
They are subscribed to messages of the same type
They didn't supply a filter during the subscription process, or the filter they supplied
determines that the message should be passed to the subscriber. |
abstract void |
subscribe(MessageBusSubscriber subscriber,
java.lang.String channel,
java.lang.Class messageType)
Enables a component to subscribe to the given channel and message type. |
abstract void |
subscribe(MessageBusSubscriber subscriber,
java.lang.String channel,
java.lang.Class messageType,
Filter filter)
Enables a component to subscribe to the given channel, message type, and add an additional
filter. |
abstract void |
unsubscribe(MessageBusSubscriber subscriber,
java.lang.String channel,
java.lang.Class messageType)
Removes a component from an existing subscription |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_CHANNEL
public static final java.lang.String DEFAULT_CHANNEL
- Defines the channel name for the default channel that is always available
MessageBus
public MessageBus()
subscribe
public abstract void subscribe(MessageBusSubscriber subscriber,
java.lang.String channel,
java.lang.Class messageType)
- Enables a component to subscribe to the given channel and message type. A unique subscriber is
a combination of the subscriber, channel, and message. This
distinction enables a component to register multiple times to a channel but with different
message types.
- Parameters:
subscriber
- the MessageBusSubscriber
that will receive the callbackchannel
- the Channel
to subscribe tomessageType
- the Message Class
type to listen for
subscribe
public abstract void subscribe(MessageBusSubscriber subscriber,
java.lang.String channel,
java.lang.Class messageType,
Filter filter)
- Enables a component to subscribe to the given channel, message type, and add an additional
filter. A unique subscriber is a combination of the subscriber, channel, and message. This
distinction enables a component to register multiple times to a channel but with different
message types.
- Parameters:
subscriber
- the MessageBusSubscriber
that will receive the callbackchannel
- the Channel
to subscribe tomessageType
- the Message Class
type to listen forfilter
- an Filter
to assist in further filtering the messages received
unsubscribe
public abstract void unsubscribe(MessageBusSubscriber subscriber,
java.lang.String channel,
java.lang.Class messageType)
- Removes a component from an existing subscription
- Parameters:
subscriber
- the MessageBusSubscriber
that will receive the callbackchannel
- the Channel
to unsubscribe frommessageType
- the Message Class
type to stop listening for
publish
public abstract void publish(java.lang.String channel,
java.lang.Object message)
- Publishes a message to The Message Bus that will be distributed to all subscribers that meet
the following requirements:
- They are subscribed to the same channel
- They are subscribed to messages of the same type
- They didn't supply a filter during the subscription process, or the filter they supplied
determines that the message should be passed to the subscriber.
- Parameters:
channel
- the Channel
to broadcast the message onmessage
- an EventObject
to broadcast
This code may be freely distributed and modified under the terms of the GNU Lesser General Public Licence..