Holger's
Java API

com.antelmann.net
Class MessageDelegator

java.lang.Object
  extended by com.antelmann.net.MessageDelegator
All Implemented Interfaces:
Enabled, Runnable

public class MessageDelegator
extends Object
implements Runnable, Enabled

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.

Author:
Holger Antelmann
See Also:
ConnectionDispatcher, NetConnection, NetConnectionHandler

Field Summary
 
Fields inherited from interface com.antelmann.util.Enabled
FILTER
 
Constructor Summary
MessageDelegator(NetConnection con, NetConnectionHandler handler)
           
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()
           
 boolean getContinuousMode()
          if false, the run() method will exit after a single message was received
 NetConnectionHandler getHandler()
           
 Logger getLogger()
           
 int getMessageCount()
           
 int getMissedMessages()
          returns the number of messages that were missed due to a ClassNotFoundException (unknown messages)
 boolean isEnabled()
          determines whether this object is currently enabled
 void resetMessageCount()
           
 void run()
          run() listens for incoming messages and delegates to the handler.
 void setEnabled(boolean enabled)
          allows to enable/disable this instance
 void setLogger(Logger logger)
           
 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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDelegator

public MessageDelegator(NetConnection con,
                        NetConnectionHandler handler)

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()

getHandler

public NetConnectionHandler getHandler()

getLogger

public Logger getLogger()

setLogger

public void setLogger(Logger logger)

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. (To also close the connection directly hereafter, use getConnection().close().


isEnabled

public boolean isEnabled()
Description copied from interface: Enabled
determines whether this object is currently enabled

Specified by:
isEnabled in interface Enabled

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: Enabled
allows to enable/disable this instance

Specified by:
setEnabled in interface Enabled

getMessageCount

public int getMessageCount()

resetMessageCount

public void resetMessageCount()

getContinuousMode

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


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 Runnable
See Also:
Logger, LogWriter, Level

getMissedMessages

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



(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads