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
 
Constructor Summary
MessageBus()
           
 
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
 

Field Detail

DEFAULT_CHANNEL

public static final java.lang.String DEFAULT_CHANNEL
Defines the channel name for the default channel that is always available
Constructor Detail

MessageBus

public MessageBus()
Method Detail

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 callback
channel - the Channel to subscribe to
messageType - 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 callback
channel - the Channel to subscribe to
messageType - the Message Class type to listen for
filter - 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 callback
channel - the Channel to unsubscribe from
messageType - 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:
  1. They are subscribed to the same channel
  2. They are subscribed to messages of the same type
  3. 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 on
message - an EventObject to broadcast


This code may be freely distributed and modified under the terms of the GNU Lesser General Public Licence..