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.Runnable
TheMessageRouter
class facilitates intra-process message routing. It provides application classes with convenient access to the message channels via thePrintWriter
class. TheMessageRouter
class, 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.
TheMessageRouter
class distributes the messages to a number of message channel listeners, added by applications. Standard message channel listeners should implement theMessageRouter.StdChannelListener
interface. TheMessageRouter
class collects all published messages. When a new message channel listener is added, it receives all collected messages from the message history.The
MessageRouter
code runs in a separate thread that should be started and terminated by applications. Applications should use thestart()
andterminate()
methods to start and terminate theMessageRouter
thread correspondingly.
For terminology see the Enterprise Integration Patterns book.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MessageRouter.StdChannelListener
TheStdChannelListener
interface declares methods that should be implemented by each standard message channel listener.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuffer
_errBuffer
private int
_errOffset
private java.io.StringWriter
_errStream
private java.io.PrintWriter
_errWriter
private java.lang.StringBuffer
_outBuffer
private int
_outOffset
private java.io.StringWriter
_outStream
private java.io.PrintWriter
_outWriter
private java.util.List<java.lang.String>
_stdHistory
private java.util.List<MessageRouter.StdChannelListener>
_stdListeners
private boolean
_terminated
private java.lang.Thread
_thread
private static java.lang.String
ERR_MSG_ID
private static java.lang.String
OUT_MSG_ID
private static long
WAITING_TIME
-
Constructor Summary
Constructors Constructor Description MessageRouter()
Default constructor for theMessageRouter
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChannelListener(MessageRouter.StdChannelListener listener)
Adds a given object, implementing theStdChannelListener
interface, to the list of standard message channel listeners.int
countStdChannelListeners()
java.io.PrintWriter
errWriter()
boolean
isRunning()
java.io.PrintWriter
outWriter()
void
removeChannelListener(MessageRouter.StdChannelListener listener)
Removes a givenStdChannelListener
object from the list of standard channel listeners.void
run()
Implements the main service method that runs in a separate thread.void
start()
Starts the main service thread.void
terminate()
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 theStdChannelListener
interface, 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,false
otherwise.
-
removeChannelListener
public void removeChannelListener(MessageRouter.StdChannelListener listener)
Removes a givenStdChannelListener
object from the list of standard channel listeners.- Parameters:
listener
- TheStdChannelListener
object to be removed from the list.
-
run
public void run()
Implements the main service method that runs in a separate thread.- Specified by:
run
in 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.
-
-