org.jscience.net
Class MessageDelegator

java.lang.Object
  extended by java.lang.Thread
      extended by org.jscience.net.MessageDelegator
All Implemented Interfaces:
java.lang.Runnable

public class MessageDelegator
extends java.lang.Thread

MessageDelegator listens for incoming messages on the given connection and delegates the message to the handler - once its run() method is called. The MessageDelegator will listen continuously until stopListening() is called or an IOException is caught. The MessageDelegator can be used as a Runnable for the createHandlerThread() in ConnectionDispatcher.

See Also:
ConnectionDispatcher#createHandlerThread(NetConnectioncon), NetConnection, NetConnectionHandler

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MessageDelegator(NetConnection con, NetConnectionHandler handler)
          Creates a new MessageDelegator object.
MessageDelegator(NetConnection con, NetConnectionHandler handler, Logger logger)
          if logger is not null, it will be used to log established and closed connections
 
Method Summary
 NetConnection getConnection()
          DOCUMENT ME!
 boolean getContinuousMode()
          if false, the run() method will exit after a single message was received
 NetConnectionHandler getHandler()
          DOCUMENT ME!
 Logger getLogger()
          DOCUMENT ME!
 int getMessageCount()
          DOCUMENT ME!
 int getMissedMessages()
          returns the number of messages that were missed due to a ClassNotFoundException (unknown messages)
 void resetMessageCount()
          DOCUMENT ME!
 void run()
          run() listens for incoming messages and delegates to the handler.
 void setLogger(Logger logger)
          DOCUMENT ME!
 void stopListening()
          disables the listener and causes run() to exit after either the next message is read or an IOException is thrown; it does not close the connection
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageDelegator

public MessageDelegator(NetConnection con,
                        NetConnectionHandler handler)
Creates a new MessageDelegator object.

Parameters:
con - DOCUMENT ME!
handler - DOCUMENT ME!

MessageDelegator

public MessageDelegator(NetConnection con,
                        NetConnectionHandler handler,
                        Logger logger)
if logger is not null, it will be used to log established and closed connections

Method Detail

getConnection

public NetConnection getConnection()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getHandler

public NetConnectionHandler getHandler()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getLogger

public Logger getLogger()
DOCUMENT ME!

Returns:
DOCUMENT ME!

setLogger

public void setLogger(Logger logger)
DOCUMENT ME!

Parameters:
logger - DOCUMENT ME!

stopListening

public void stopListening()
disables the listener and causes run() to exit after either the next message is read or an IOException is thrown; it does not close the connection


getMessageCount

public int getMessageCount()
DOCUMENT ME!

Returns:
DOCUMENT ME!

resetMessageCount

public void resetMessageCount()
DOCUMENT ME!


getContinuousMode

public boolean getContinuousMode()
if false, the run() method will exit after a single message was received

Returns:
DOCUMENT ME!

run

public void run()
run() listens for incoming messages and delegates to the handler. If a Logger is present, it will log the following entries:

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
Logger, LogWriter, Level

getMissedMessages

public int getMissedMessages()
returns the number of messages that were missed due to a ClassNotFoundException (unknown messages)

Returns:
DOCUMENT ME!