de.root1.simon
Class Dispatcher

java.lang.Object
  extended by de.root1.simon.Dispatcher
All Implemented Interfaces:
org.apache.mina.core.service.IoHandler

public class Dispatcher
extends java.lang.Object
implements org.apache.mina.core.service.IoHandler

This class is the "brain" of SIMON on server side, as well as on client side. It handles all the I/O and delegates the required tasks

Author:
ACHR

Constructor Summary
Dispatcher(java.lang.String serverString, java.util.concurrent.ExecutorService threadPool)
          Creates a packet dispatcher which delegates the packet-reading to ProcessMessageRunnable's which run in the given threadPool
 
Method Summary
protected  void addClosedListener(ClosedListener listener, java.lang.String remoteObjectName)
          Method used by the Lookup-Classes to register a closed listener with a given remote object name
protected  void closeRawChannel(org.apache.mina.core.session.IoSession session, int channelToken)
          Triggers a close of a raw channel
 void exceptionCaught(org.apache.mina.core.session.IoSession session, java.lang.Throwable throwable)
           
protected  java.util.List<ClosedListener> getClosedListenerList(java.lang.String remoteObjectName)
          Returns a list of ClosedListeners which listen for closed event for given remote object name
protected  LookupTable getLookupTable()
          for internal use only
protected  int getPingTimeout()
          Method used by the PingWatchdog for getting the current ping/keepalive timeout
protected  PingWatchdog getPingWatchdog()
          Returns the PingWatchdog that checks the session connectivity
protected  RawChannelDataListener getRawChannelDataListener(int channelToken)
          TODO document me
 java.lang.String getServerString()
          Returns the identifier string which determines to which server this dispatcher is connected to
protected  boolean invokeEquals(org.apache.mina.core.session.IoSession session, java.lang.String remoteObjectName, java.lang.Object objectToCompareWith)
          Forwards an "equals()" call to the remote side to be handled there
protected  int invokeHashCode(org.apache.mina.core.session.IoSession session, java.lang.String remoteObjectName)
          Invokes the hashCode() method on the remote object
protected  MsgInterfaceLookupReturn invokeInterfaceLookup(org.apache.mina.core.session.IoSession session, java.lang.String canonicalInterfaceName)
          Sends a remote object lookup to the server
protected  java.lang.Object invokeMethod(org.apache.mina.core.session.IoSession session, java.lang.String remoteObjectName, java.lang.reflect.Method method, java.lang.Object[] args)
           
protected  MsgNameLookupReturn invokeNameLookup(org.apache.mina.core.session.IoSession session, java.lang.String remoteObjectName)
          Sends a remote object lookup to the server
protected  java.lang.String invokeToString(org.apache.mina.core.session.IoSession session, java.lang.String remoteObjectName)
          Sends a "toString()" request to the remote host.
protected  boolean isRawChannelDataListenerRegistered(int channelToken)
          TODO document me
protected  boolean isRunning()
          Returns whether the dispatcher is still in run() or not
protected  boolean isServerDispatcher()
          Returns whether this is an server dispatcher or not
 void messageReceived(org.apache.mina.core.session.IoSession session, java.lang.Object message)
           
 void messageSent(org.apache.mina.core.session.IoSession session, java.lang.Object msg)
           
protected  RawChannel openRawChannel(org.apache.mina.core.session.IoSession session, int channelToken)
          Opens the a raw channel on the given session with the specified token
protected  int prepareRawChannel(RawChannelDataListener listener)
          TODO document me
 void putResultToQueue(org.apache.mina.core.session.IoSession session, int sequenceId, java.lang.Object o)
          This method is called from worker-threads which processed an invocation and have data ready that has to be returned to the "caller".
protected  boolean removeClosedListener(ClosedListener listener, java.lang.String remoteObjectName)
          Method used by the lookup-Classes to remove a single closed listener from a remote object
protected  java.util.List<ClosedListener> removeClosedListenerList(java.lang.String remoteObjectName)
          Method used by the Loopup-Classes to remove a list of closed listener for a given remote object
 void sendPong(org.apache.mina.core.session.IoSession session)
           
 void sessionClosed(org.apache.mina.core.session.IoSession session)
           
 void sessionCreated(org.apache.mina.core.session.IoSession session)
           
 void sessionIdle(org.apache.mina.core.session.IoSession session, org.apache.mina.core.session.IdleStatus idleStatus)
           
 void sessionOpened(org.apache.mina.core.session.IoSession session)
           
protected  void setPingTimeOut(int pingTimeOut)
          Method used by the Registry while setting the keep alive timeout
 void shutdown()
          Initiates a shutdown at the dispatcher and all related things
protected  void unprepareRawChannel(int channelToken)
          TODO document me
protected  void writeRawData(org.apache.mina.core.session.IoSession session, int channelToken, java.nio.ByteBuffer byteBuffer)
          TODO document me
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher(java.lang.String serverString,
                  java.util.concurrent.ExecutorService threadPool)
Creates a packet dispatcher which delegates the packet-reading to ProcessMessageRunnable's which run in the given threadPool

Parameters:
serverString - an identifier string to determine to which server this dispatcher is connected to. this must be set to null if this dispatcher is a server dispatcher.
threadPool - the pool where the ProcessMessageRunnable's run in
Method Detail

getPingTimeout

protected int getPingTimeout()
Method used by the PingWatchdog for getting the current ping/keepalive timeout

Returns:
the pingTimeOut

setPingTimeOut

protected void setPingTimeOut(int pingTimeOut)
Method used by the Registry while setting the keep alive timeout

Parameters:
pingTimeOut - the pingTimeOut to set

removeClosedListenerList

protected java.util.List<ClosedListener> removeClosedListenerList(java.lang.String remoteObjectName)
Method used by the Loopup-Classes to remove a list of closed listener for a given remote object

Parameters:
remoteObjectName - the remote object that correlates to the closed listenert
Returns:
the list of removed closed listeners

addClosedListener

protected void addClosedListener(ClosedListener listener,
                                 java.lang.String remoteObjectName)
Method used by the Lookup-Classes to register a closed listener with a given remote object name

Parameters:
listener - the listener to add
remoteObjectName - the obejct that we listen for closed situations

removeClosedListener

protected boolean removeClosedListener(ClosedListener listener,
                                       java.lang.String remoteObjectName)
Method used by the lookup-Classes to remove a single closed listener from a remote object

Parameters:
listener - the listener to remove
remoteObjectName - the related remote object

invokeNameLookup

protected MsgNameLookupReturn invokeNameLookup(org.apache.mina.core.session.IoSession session,
                                               java.lang.String remoteObjectName)
                                        throws LookupFailedException,
                                               SimonRemoteException
Sends a remote object lookup to the server

Parameters:
session - the related session over which the invoke request comes
remoteObjectName - the remote object to lookup
Returns:
the name lookup return message
Throws:
SimonRemoteException
LookupFailedException

invokeInterfaceLookup

protected MsgInterfaceLookupReturn invokeInterfaceLookup(org.apache.mina.core.session.IoSession session,
                                                         java.lang.String canonicalInterfaceName)
                                                  throws LookupFailedException,
                                                         SimonRemoteException
Sends a remote object lookup to the server

Parameters:
session - the related session over which the invoke request comes
canonicalInterfaceName - the canonical name of the interface
Returns:
the interface lookup return message
Throws:
SimonRemoteException
LookupFailedException

invokeMethod

protected java.lang.Object invokeMethod(org.apache.mina.core.session.IoSession session,
                                        java.lang.String remoteObjectName,
                                        java.lang.reflect.Method method,
                                        java.lang.Object[] args)
                                 throws SimonRemoteException
Throws:
SimonRemoteException

invokeToString

protected java.lang.String invokeToString(org.apache.mina.core.session.IoSession session,
                                          java.lang.String remoteObjectName)
                                   throws SimonRemoteException
Sends a "toString()" request to the remote host.

Parameters:
session - the related session over which the invoke request comes
remoteObjectName - the remote object
Returns:
the result of the remote "toString()" call
Throws:
SimonRemoteException

invokeHashCode

protected int invokeHashCode(org.apache.mina.core.session.IoSession session,
                             java.lang.String remoteObjectName)
                      throws SimonRemoteException
Invokes the hashCode() method on the remote object

Parameters:
session - the related session over which the invoke request comes
remoteObjectName - the remote object
Returns:
the result of the remote "hashCode()" call
Throws:
SimonRemoteException

invokeEquals

protected boolean invokeEquals(org.apache.mina.core.session.IoSession session,
                               java.lang.String remoteObjectName,
                               java.lang.Object objectToCompareWith)
                        throws SimonRemoteException
Forwards an "equals()" call to the remote side to be handled there

Parameters:
session - the session to which the invocation is sent
remoteObjectName - the name of the remote object that has to be compared
objectToCompareWith - the object to which the remote object is compared with
Returns:
the result of the comparison
Throws:
SimonRemoteException

putResultToQueue

public void putResultToQueue(org.apache.mina.core.session.IoSession session,
                             int sequenceId,
                             java.lang.Object o)
This method is called from worker-threads which processed an invocation and have data ready that has to be returned to the "caller". after adding the result to the map (means: replacing the monitor with the result), the waiting request-method is waked.

Parameters:
sequenceId - the sequence id that is waiting for the result
o - the result itself

getLookupTable

protected LookupTable getLookupTable()
for internal use only


shutdown

public void shutdown()
Initiates a shutdown at the dispatcher and all related things


getServerString

public java.lang.String getServerString()
Returns the identifier string which determines to which server this dispatcher is connected to

Returns:
the identifier string. this is null if this dispatcher is a server dispatcher

isServerDispatcher

protected boolean isServerDispatcher()
Returns whether this is an server dispatcher or not

Returns:
true if server dispatcher, false if not

isRunning

protected boolean isRunning()
Returns whether the dispatcher is still in run() or not

Returns:
boolean

exceptionCaught

public void exceptionCaught(org.apache.mina.core.session.IoSession session,
                            java.lang.Throwable throwable)
                     throws java.lang.Exception
Specified by:
exceptionCaught in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

messageReceived

public void messageReceived(org.apache.mina.core.session.IoSession session,
                            java.lang.Object message)
                     throws java.lang.Exception
Specified by:
messageReceived in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

messageSent

public void messageSent(org.apache.mina.core.session.IoSession session,
                        java.lang.Object msg)
                 throws java.lang.Exception
Specified by:
messageSent in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

sessionClosed

public void sessionClosed(org.apache.mina.core.session.IoSession session)
                   throws java.lang.Exception
Specified by:
sessionClosed in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

sessionCreated

public void sessionCreated(org.apache.mina.core.session.IoSession session)
                    throws java.lang.Exception
Specified by:
sessionCreated in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

sessionIdle

public void sessionIdle(org.apache.mina.core.session.IoSession session,
                        org.apache.mina.core.session.IdleStatus idleStatus)
                 throws java.lang.Exception
Specified by:
sessionIdle in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

sendPong

public void sendPong(org.apache.mina.core.session.IoSession session)
              throws SessionException
Throws:
SessionException

sessionOpened

public void sessionOpened(org.apache.mina.core.session.IoSession session)
                   throws java.lang.Exception
Specified by:
sessionOpened in interface org.apache.mina.core.service.IoHandler
Throws:
java.lang.Exception

openRawChannel

protected RawChannel openRawChannel(org.apache.mina.core.session.IoSession session,
                                    int channelToken)
                             throws SimonRemoteException
Opens the a raw channel on the given session with the specified token

Returns:
the opened RawChannel
Throws:
SimonRemoteException - if a problem occured while opening the raw channel

prepareRawChannel

protected int prepareRawChannel(RawChannelDataListener listener)
                         throws SimonException
TODO document me

Throws:
SimonException

isRawChannelDataListenerRegistered

protected boolean isRawChannelDataListenerRegistered(int channelToken)
TODO document me


getRawChannelDataListener

protected RawChannelDataListener getRawChannelDataListener(int channelToken)
TODO document me


unprepareRawChannel

protected void unprepareRawChannel(int channelToken)
TODO document me

Parameters:
channelToken -

writeRawData

protected void writeRawData(org.apache.mina.core.session.IoSession session,
                            int channelToken,
                            java.nio.ByteBuffer byteBuffer)
                     throws SimonRemoteException
TODO document me

Parameters:
session -
channelToken -
byteBuffer -
Throws:
SimonRemoteException

closeRawChannel

protected void closeRawChannel(org.apache.mina.core.session.IoSession session,
                               int channelToken)
                        throws SimonRemoteException
Triggers a close of a raw channel

Parameters:
session - the related IoSession
channelToken - the related channel token
Throws:
SimonRemoteException

getPingWatchdog

protected PingWatchdog getPingWatchdog()
Returns the PingWatchdog that checks the session connectivity

Returns:
the current instance of PingWatchdog

getClosedListenerList

protected java.util.List<ClosedListener> getClosedListenerList(java.lang.String remoteObjectName)
Returns a list of ClosedListeners which listen for closed event for given remote object name

Parameters:
remoteObjectName - the remote objects name
Returns:
the list with listeners


Copyright © 2011. All Rights Reserved.