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.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuffer_errBufferprivate int_errOffsetprivate java.io.StringWriter_errStreamprivate java.io.PrintWriter_errWriterprivate java.lang.StringBuffer_outBufferprivate int_outOffsetprivate java.io.StringWriter_outStreamprivate java.io.PrintWriter_outWriterprivate java.util.List<java.lang.String>_stdHistoryprivate java.util.List<MessageRouter.StdChannelListener>_stdListenersprivate boolean_terminatedprivate java.lang.Thread_threadprivate static java.lang.StringERR_MSG_IDprivate static java.lang.StringOUT_MSG_IDprivate static longWAITING_TIME
-
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.
-
-
-
Field Detail
-
OUT_MSG_ID
private static final java.lang.String OUT_MSG_ID
- See Also:
- Constant Field Values
-
ERR_MSG_ID
private static final java.lang.String ERR_MSG_ID
- See Also:
- Constant Field Values
-
WAITING_TIME
private static final long WAITING_TIME
- See Also:
- Constant Field Values
-
_errStream
private java.io.StringWriter _errStream
-
_errBuffer
private java.lang.StringBuffer _errBuffer
-
_errWriter
private java.io.PrintWriter _errWriter
-
_errOffset
private int _errOffset
-
_outStream
private java.io.StringWriter _outStream
-
_outBuffer
private java.lang.StringBuffer _outBuffer
-
_outWriter
private java.io.PrintWriter _outWriter
-
_outOffset
private int _outOffset
-
_terminated
private boolean _terminated
-
_thread
private java.lang.Thread _thread
-
_stdHistory
private java.util.List<java.lang.String> _stdHistory
-
_stdListeners
private java.util.List<MessageRouter.StdChannelListener> _stdListeners
-
-
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.
-
-