gov.sns.tools.messaging
Class MessageCenter

java.lang.Object
  |
  +--gov.sns.tools.messaging.MessageCenter

public class MessageCenter
extends java.lang.Object

MessageCenter provides an interface to the messaging system with lots of convenience methods for easy access to messaging features.


Nested Class Summary
 class MessageCenter.MessageCenterException
          Generic class for all MessageCenter related exceptions
 class MessageCenter.NullSourceException
          Exception when an attempt is made to register a null source
 class MessageCenter.NullTargetException
          Exception when an attempt is made to register a null source
 class MessageCenter.UnimplementedProtocolException
          Exception when an attempt is made to register a target for a protocol not implemented by its class.
 
Constructor Summary
MessageCenter()
          Creates new MessageCenter
MessageCenter(int threadPoolSize)
          Create a new MessageCenter with given thread pool size
MessageCenter(java.lang.String newName)
          Create a new MessageCenter with given name
MessageCenter(java.lang.String newName, int newThreadPoolSize)
          Create a new MessageCenter with given name and thread pool size
 
Method Summary
static MessageCenter defaultCenter()
          default message center instance
 java.lang.Object getProxy(java.lang.Object source, java.lang.Class protocol)
          get the proxy for the specified source and protocol
 java.lang.String name()
          get the name of the MessageCenter instance
static MessageCenter newCenter()
          Create a new MessageCenter
static MessageCenter newCenter(int newThreadPoolSize)
          Create a new MessageCenter
static MessageCenter newCenter(java.lang.String newName)
          Create a new MessageCenter
static MessageCenter newCenter(java.lang.String newName, int newThreadPoolSize)
          Create a new MessageCenter
 java.lang.Object registerSource(java.lang.Object source, java.lang.Class protocol)
          register the specified source to be associated with the specified event protocol defaults to synchronous messaging
 java.lang.Object registerSource(java.lang.Object source, java.lang.Class protocol, boolean isSynchronous)
          register the specified source to be associated with the specified event protocol and using synchronous (true) or asynchronous messaging (false)
 void registerTarget(java.lang.Object target, java.lang.Class protocol)
          register target for messages from any source which posts to the interface
 void registerTarget(java.lang.Object target, java.lang.Object source, java.lang.Class protocol)
          register target for messages from the source and for the specified interface
 void removeSource(java.lang.Object source, java.lang.Class protocol)
          Remove source registration which means the proxy for the source/protocol pair is no longer able to broadcast messages.
 void removeTarget(java.lang.Object target, java.lang.Class protocol)
          Removes the target from listening for the specified protocol.
 void removeTarget(java.lang.Object target, java.util.Collection sources, java.lang.Class protocol)
          Unregister the target from listening to the specified protocol from the specified collection of sources.
 void removeTarget(java.lang.Object target, java.lang.Object source, java.lang.Class protocol)
          remove target from listening to specified source with specified protocol
 void removeTargetFromAllSources(java.lang.Object target, java.lang.Class protocol)
          Remove the target from every source that broadcasts the specified protocol
 java.lang.String toString()
          Override toString() to return a description of the message center.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageCenter

public MessageCenter()
Creates new MessageCenter


MessageCenter

public MessageCenter(java.lang.String newName)
Create a new MessageCenter with given name

Parameters:
newName - The name of this Message Center.

MessageCenter

public MessageCenter(int threadPoolSize)
Create a new MessageCenter with given thread pool size

Parameters:
threadPoolSize - The thread pool size of this message center

MessageCenter

public MessageCenter(java.lang.String newName,
                     int newThreadPoolSize)
Create a new MessageCenter with given name and thread pool size

Parameters:
newName - The name of this message center
newThreadPoolSize - The thread pool size of this message center
Method Detail

defaultCenter

public static MessageCenter defaultCenter()
default message center instance

Returns:
the default message center

newCenter

public static MessageCenter newCenter()
Create a new MessageCenter

Returns:
a new message center

newCenter

public static MessageCenter newCenter(java.lang.String newName)
Create a new MessageCenter

Parameters:
newName - the name to assign this message center
Returns:
a new message center

newCenter

public static MessageCenter newCenter(int newThreadPoolSize)
Create a new MessageCenter

Parameters:
newThreadPoolSize - The thread pool size of this message center
Returns:
a new message center

newCenter

public static MessageCenter newCenter(java.lang.String newName,
                                      int newThreadPoolSize)
Create a new MessageCenter

Parameters:
newName - The name of this message center
newThreadPoolSize - The thread pool size of this message center
Returns:
a new message center

registerTarget

public void registerTarget(java.lang.Object target,
                           java.lang.Object source,
                           java.lang.Class protocol)
register target for messages from the source and for the specified interface

Parameters:
target - The target to receive messages
source - The source from which we wish to receive messages
protocol - The protocol identifying the message type to receive

registerTarget

public void registerTarget(java.lang.Object target,
                           java.lang.Class protocol)
register target for messages from any source which posts to the interface

Parameters:
target - The target to receive messages
protocol - The protocol identifying the message type to receive

removeTarget

public void removeTarget(java.lang.Object target,
                         java.lang.Object source,
                         java.lang.Class protocol)
remove target from listening to specified source with specified protocol

Parameters:
target - The target receiving messages
source - The source from which we are receiving messages
protocol - The protocol identifying the message type being received

removeTargetFromAllSources

public void removeTargetFromAllSources(java.lang.Object target,
                                       java.lang.Class protocol)
Remove the target from every source that broadcasts the specified protocol

Parameters:
target - The target receiving messages
protocol - The protocol identifying the message type being received

removeTarget

public void removeTarget(java.lang.Object target,
                         java.util.Collection sources,
                         java.lang.Class protocol)
Unregister the target from listening to the specified protocol from the specified collection of sources.

Parameters:
target - The target receiving messages
sources - The sources from which we are receiving messages
protocol - The protocol identifying the message type being received

removeTarget

public void removeTarget(java.lang.Object target,
                         java.lang.Class protocol)
Removes the target from listening for the specified protocol. It only removes the target from listening to the protocol from anonymous sources. For example, it unregisters a call of registerTarget(target, protocol). This method does NOT remove the target from listenting to directly registered sources.

Parameters:
target - The target receiving messages
protocol - The protocol identifying the message type being received

registerSource

public java.lang.Object registerSource(java.lang.Object source,
                                       java.lang.Class protocol)
register the specified source to be associated with the specified event protocol defaults to synchronous messaging

Parameters:
source - The source of the message
protocol - The type and interface of the messages the source will send
Returns:
The proxy (implementing protocol) to call to broadcast messages

registerSource

public java.lang.Object registerSource(java.lang.Object source,
                                       java.lang.Class protocol,
                                       boolean isSynchronous)
register the specified source to be associated with the specified event protocol and using synchronous (true) or asynchronous messaging (false)

Parameters:
source - The source of the message
protocol - The type and interface of the messages the source will send
isSynchronous - true to enable synchronous messaging and false for asynchronous messaging
Returns:
The proxy (implementing protocol) to call to broadcast messages

removeSource

public void removeSource(java.lang.Object source,
                         java.lang.Class protocol)
Remove source registration which means the proxy for the source/protocol pair is no longer able to broadcast messages. The handler for this source/protocol pair will be removed.

Parameters:
source - The source of messages
protocol - The interface/type of messages

getProxy

public java.lang.Object getProxy(java.lang.Object source,
                                 java.lang.Class protocol)
get the proxy for the specified source and protocol

Parameters:
source - The source on behalf of which messages will be broadcast
protocol - The interface/type of message implemented by the proxy
Returns:
The proxy (implementing protocol) to call on behalf of the source to broadcast messages

name

public java.lang.String name()
get the name of the MessageCenter instance

Returns:
the name of the message center

toString

public java.lang.String toString()
Override toString() to return a description of the message center. At this point it simply returns the name of the message center.

Overrides:
toString in class java.lang.Object
Returns:
the description of the MessageCenter instance