Package org.apache.uima.pear.util
Class MessageRouter
- java.lang.Object
-
- org.apache.uima.pear.util.MessageRouter
-
- All Implemented Interfaces:
java.lang.Runnable
public class MessageRouter extends java.lang.Object implements java.lang.RunnableTheMessageRouterclass facilitates intra-process message routing. It provides application classes with convenient access to the message channels via thePrintWriterclass. TheMessageRouterclass, by default, defines 2 standard message channels - for standard output and standard error messages. Applications can publish their standard output and standard error messages using theoutWriter()anderrWriter()methods correspondingly.
TheMessageRouterclass distributes the messages to a number of message channel listeners, added by applications. Standard message channel listeners should implement theMessageRouter.StdChannelListenerinterface. TheMessageRouterclass collects all published messages. When a new message channel listener is added, it receives all collected messages from the message history.The
MessageRoutercode runs in a separate thread that should be started and terminated by applications. Applications should use thestart()andterminate()methods to start and terminate theMessageRouterthread correspondingly.
For terminology see the Enterprise Integration Patterns book.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMessageRouter.StdChannelListenerTheStdChannelListenerinterface declares methods that should be implemented by each standard message channel listener.
-
Constructor Summary
Constructors Constructor Description MessageRouter()Default constructor for theMessageRouterclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChannelListener(MessageRouter.StdChannelListener listener)Adds a given object, implementing theStdChannelListenerinterface, to the list of standard message channel listeners.intcountStdChannelListeners()java.io.PrintWritererrWriter()booleanisRunning()java.io.PrintWriteroutWriter()voidremoveChannelListener(MessageRouter.StdChannelListener listener)Removes a givenStdChannelListenerobject from the list of standard channel listeners.voidrun()Implements the main service method that runs in a separate thread.voidstart()Starts the main service thread.voidterminate()Terminates the main service thread.
-
-
-
Method Detail
-
addChannelListener
public void addChannelListener(MessageRouter.StdChannelListener listener)
Adds a given object, implementing theStdChannelListenerinterface, to the list of standard message channel listeners. Sends to the new listener all previously collected messages for this channel.- Parameters:
listener- The given new standard message channel listener.
-
countStdChannelListeners
public int countStdChannelListeners()
- Returns:
- Current number of standard channel listeners.
-
isRunning
public boolean isRunning()
- Returns:
true, if the router thread is running,falseotherwise.
-
removeChannelListener
public void removeChannelListener(MessageRouter.StdChannelListener listener)
Removes a givenStdChannelListenerobject from the list of standard channel listeners.- Parameters:
listener- TheStdChannelListenerobject to be removed from the list.
-
run
public void run()
Implements the main service method that runs in a separate thread.- Specified by:
runin interfacejava.lang.Runnable
-
errWriter
public java.io.PrintWriter errWriter()
- Returns:
- The standard error message channel writer.
-
outWriter
public java.io.PrintWriter outWriter()
- Returns:
- The standard output message channel writer.
-
start
public void start()
Starts the main service thread.
-
terminate
public void terminate()
Terminates the main service thread.
-
-