Package xal.tools.messaging
Class MessageCenter
java.lang.Object
xal.tools.messaging.MessageCenter
- All Implemented Interfaces:
Serializable
MessageCenter provides an interface to the messaging system with lots of
convenience methods for easy access to messaging features.
- Author:
- tap
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Generic class for all MessageCenter related exceptionsclass
Exception when an attempt is made to register a null sourceclass
Exception when an attempt is made to register a null sourceclass
Exception when an attempt is made to register a target for a protocol not implemented by its class. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
forward events from a new threadstatic final int
forward fresh events (drop old unprocessed pending events) on a common thread per protocolstatic final int
forward events on the invoking thread -
Constructor Summary
ConstructorsConstructorDescriptionCreates new MessageCenterMessageCenter
(int threadPoolSize) Create a new MessageCenter with given thread pool sizeMessageCenter
(String newName) Create a new MessageCenter with given nameMessageCenter
(String newName, int newThreadPoolSize) Create a new MessageCenter with given name and thread pool size -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageCenter
default message center instance<T> T
get the proxy for the specified source and protocolname()
get the name of the MessageCenter instancestatic MessageCenter
Create a new MessageCenterstatic MessageCenter
newCenter
(int newThreadPoolSize) Create a new MessageCenterstatic MessageCenter
Create a new MessageCenterstatic MessageCenter
Create a new MessageCenter<T> T
registerSource
(Object source, Class<T> protocol) register the specified source to be associated with the specified event protocol defaults to synchronous messaging<T> T
registerSource
(Object source, Class<T> protocol, boolean isSynchronous) Deprecated.Use the version of this method that takes the synchronous type instead<T> T
registerSource
(Object source, Class<T> protocol, int synchronousType) Register the specified source to be associated with the specified event protocol and processed as the synchronous type<T> void
registerTarget
(T target, Class<T> protocol) register target for messages from any source which posts to the interface<T> void
registerTarget
(T target, Object source, Class<T> protocol) register target for messages from the source and for the specified interface<T> void
removeSource
(Object source, Class<T> protocol) Remove source registration which means the proxy for the source/protocol pair is no longer able to broadcast messages.<T> void
removeTarget
(T target, Class<T> protocol) Removes the target from listening for the specified protocol.<T> void
removeTarget
(T target, Object source, Class<T> protocol) remove target from listening to specified source with specified protocol<T> void
removeTarget
(T target, Collection<? extends Object> sources, Class<T> protocol) Unregister the target from listening to the specified protocol from the specified collection of sources.<T> void
removeTargetFromAllSources
(T target, Class<T> protocol) Remove the target from every source that broadcasts the specified protocoltoString()
Override toString() to return a description of the message center.
-
Field Details
-
SYNCHRONOUS
public static final int SYNCHRONOUSforward events on the invoking thread- See Also:
-
ASYNCHRONOUS
public static final int ASYNCHRONOUSforward events from a new thread- See Also:
-
FRESH
public static final int FRESHforward fresh events (drop old unprocessed pending events) on a common thread per protocol- See Also:
-
-
Constructor Details
-
MessageCenter
public MessageCenter()Creates new MessageCenter -
MessageCenter
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
Create a new MessageCenter with given name and thread pool size- Parameters:
newName
- The name of this message centernewThreadPoolSize
- The thread pool size of this message center
-
-
Method Details
-
defaultCenter
default message center instance- Returns:
- the default message center
-
newCenter
Create a new MessageCenter- Returns:
- a new message center
-
newCenter
Create a new MessageCenter- Parameters:
newName
- the name to assign this message center- Returns:
- a new message center
-
newCenter
Create a new MessageCenter- Parameters:
newThreadPoolSize
- The thread pool size of this message center- Returns:
- a new message center
-
newCenter
Create a new MessageCenter- Parameters:
newName
- The name of this message centernewThreadPoolSize
- The thread pool size of this message center- Returns:
- a new message center
-
registerTarget
register target for messages from the source and for the specified interface- Parameters:
target
- The target to receive messagessource
- The source from which we wish to receive messagesprotocol
- The protocol identifying the message type to receive
-
registerTarget
register target for messages from any source which posts to the interface- Parameters:
target
- The target to receive messagesprotocol
- The protocol identifying the message type to receive
-
removeTarget
remove target from listening to specified source with specified protocol- Parameters:
target
- The target receiving messagessource
- The source from which we are receiving messagesprotocol
- The protocol identifying the message type being received
-
removeTargetFromAllSources
Remove the target from every source that broadcasts the specified protocol- Parameters:
target
- The target receiving messagesprotocol
- The protocol identifying the message type being received
-
removeTarget
Unregister the target from listening to the specified protocol from the specified collection of sources.- Parameters:
target
- The target receiving messagessources
- The sources from which we are receiving messagesprotocol
- The protocol identifying the message type being received
-
removeTarget
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 listening to directly registered sources.- Parameters:
target
- The target receiving messagesprotocol
- The protocol identifying the message type being received
-
registerSource
register the specified source to be associated with the specified event protocol defaults to synchronous messaging- Parameters:
source
- The source of the messageprotocol
- The type and interface of the messages the source will send- Returns:
- The proxy (implementing protocol) to call to broadcast messages
-
registerSource
Deprecated.Use the version of this method that takes the synchronous type insteadRegister 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 messageprotocol
- The type and interface of the messages the source will sendisSynchronous
- true to enable synchronous messaging and false for asynchronous messaging- Returns:
- The proxy (implementing protocol) to call to broadcast messages
-
registerSource
Register the specified source to be associated with the specified event protocol and processed as the synchronous type- Parameters:
source
- The source of the messageprotocol
- The type and interface of the messages the source will sendsynchronousType
- one of SYNCHRONOUS, ASYNCHRONOUS or FRESH to indicate how events are processed- Returns:
- The proxy (implementing protocol) to call to broadcast messages
-
removeSource
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 messagesprotocol
- The interface/type of messages
-
getProxy
get the proxy for the specified source and protocol- Parameters:
source
- The source on behalf of which messages will be broadcastprotocol
- 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
get the name of the MessageCenter instance- Returns:
- the name of the message center
-
toString
Override toString() to return a description of the message center. At this point it simply returns the name of the message center.
-