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.
-
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.
-
-
-
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.
-
-