Class Dispatcher

java.lang.Object
host.anzo.simon.Dispatcher
All Implemented Interfaces:
org.apache.mina.core.service.IoHandler

public class Dispatcher extends 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

  • Constructor Details

    • Dispatcher

      public Dispatcher(String serverString, ClassLoader classLoader, 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 Details

    • 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 List<ClosedListener> removeClosedListenerList(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, 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, 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
      Returns:
      true if listener has been removed
    • invokeNameLookup

      protected MsgNameLookupReturn invokeNameLookup(org.apache.mina.core.session.IoSession session, 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:
      LookupFailedException - if lookup fails
      SimonRemoteException - if something else goes wrong
    • invokeInterfaceLookup

      protected MsgInterfaceLookupReturn invokeInterfaceLookup(org.apache.mina.core.session.IoSession session, 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:
      LookupFailedException - if lookup fails
      SimonRemoteException
    • invokeMethod

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

      protected String invokeToString(org.apache.mina.core.session.IoSession session, 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, 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 - if something goes wrong
    • invokeEquals

      protected boolean invokeEquals(org.apache.mina.core.session.IoSession session, String remoteObjectName, 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 - if something goes wrong
    • putResultToQueue

      public void putResultToQueue(org.apache.mina.core.session.IoSession session, int sequenceId, 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:
      session - the underlying session
      sequenceId - the sequence id that is waiting for the result
      o - the result itself
    • getLookupTable

      protected LookupTable getLookupTable()
      for internal use only
      Returns:
      the associated lookup table
    • shutdown

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

      public 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, Throwable throwable) throws Exception
      Specified by:
      exceptionCaught in interface org.apache.mina.core.service.IoHandler
      Throws:
      Exception
    • messageReceived

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

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

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

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

      public void sessionIdle(org.apache.mina.core.session.IoSession session, org.apache.mina.core.session.IdleStatus idleStatus) throws Exception
      Specified by:
      sessionIdle in interface org.apache.mina.core.service.IoHandler
      Throws:
      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 Exception
      Specified by:
      sessionOpened in interface org.apache.mina.core.service.IoHandler
      Throws:
      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) throws RawChannelException
      TODO document me
      Parameters:
      channelToken -
      Throws:
      RawChannelException
    • writeRawData

      protected void writeRawData(org.apache.mina.core.session.IoSession session, int channelToken, ByteBuffer byteBuffer) throws SimonRemoteException, RawChannelException
      TODO document me
      Parameters:
      session -
      channelToken -
      byteBuffer -
      Throws:
      SimonRemoteException
      RawChannelException
    • closeRawChannel

      protected void closeRawChannel(org.apache.mina.core.session.IoSession session, int channelToken) throws SimonRemoteException, RawChannelException
      Triggers a close of a raw channel
      Parameters:
      session - the related IoSession
      channelToken - the related channel token
      Throws:
      SimonRemoteException
      RawChannelException
    • getPingWatchdog

      protected PingWatchdog getPingWatchdog()
      Returns the PingWatchdog that checks the session connectivity
      Returns:
      the current instance of PingWatchdog
    • getClosedListenerList

      protected List<ClosedListener> getClosedListenerList(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
    • inputClosed

      public void inputClosed(org.apache.mina.core.session.IoSession is) throws Exception
      Specified by:
      inputClosed in interface org.apache.mina.core.service.IoHandler
      Throws:
      Exception
    • event

      public void event(org.apache.mina.core.session.IoSession session, org.apache.mina.filter.FilterEvent event) throws Exception
      Specified by:
      event in interface org.apache.mina.core.service.IoHandler
      Throws:
      Exception