Package host.anzo.simon
Class Dispatcher
java.lang.Object
host.anzo.simon.Dispatcher
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionDispatcher(String serverString, ClassLoader classLoader, ExecutorService threadPool) Creates a packet dispatcher which delegates the packet-reading toProcessMessageRunnable's which run in the giventhreadPool -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddClosedListener(ClosedListener listener, String remoteObjectName) Method used by the Lookup-Classes to register a closed listener with a given remote object nameprotected voidcloseRawChannel(org.apache.mina.core.session.IoSession session, int channelToken) Triggers a close of a raw channelvoidevent(org.apache.mina.core.session.IoSession session, org.apache.mina.filter.FilterEvent event) voidexceptionCaught(org.apache.mina.core.session.IoSession session, Throwable throwable) protected List<ClosedListener>getClosedListenerList(String remoteObjectName) Returns a list of ClosedListeners which listen for closed event for given remote object nameprotected LookupTablefor internal use onlyprotected intMethod used by the PingWatchdog for getting the current ping/keepalive timeoutprotected PingWatchdogReturns the PingWatchdog that checks the session connectivityprotected RawChannelDataListenergetRawChannelDataListener(int channelToken) TODO document meReturns the identifier string which determines to which server this dispatcher is connected tovoidinputClosed(org.apache.mina.core.session.IoSession is) protected booleaninvokeEquals(org.apache.mina.core.session.IoSession session, String remoteObjectName, Object objectToCompareWith) Forwards an "equals()" call to the remote side to be handled thereprotected intinvokeHashCode(org.apache.mina.core.session.IoSession session, String remoteObjectName) Invokes the hashCode() method on the remote objectprotected MsgInterfaceLookupReturninvokeInterfaceLookup(org.apache.mina.core.session.IoSession session, String canonicalInterfaceName) Sends a remote object lookup to the serverprotected ObjectinvokeMethod(org.apache.mina.core.session.IoSession session, String remoteObjectName, Method method, Object[] args) protected MsgNameLookupReturninvokeNameLookup(org.apache.mina.core.session.IoSession session, String remoteObjectName) Sends a remote object lookup to the serverprotected StringinvokeToString(org.apache.mina.core.session.IoSession session, String remoteObjectName) Sends a "toString()" request to the remote host.protected booleanisRawChannelDataListenerRegistered(int channelToken) TODO document meprotected booleanReturns whether the dispatcher is still in run() or notprotected booleanReturns whether this is an server dispatcher or notvoidmessageReceived(org.apache.mina.core.session.IoSession session, Object message) voidmessageSent(org.apache.mina.core.session.IoSession session, Object msg) protected RawChannelopenRawChannel(org.apache.mina.core.session.IoSession session, int channelToken) Opens the a raw channel on the given session with the specified tokenprotected intprepareRawChannel(RawChannelDataListener listener) TODO document mevoidputResultToQueue(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".protected booleanremoveClosedListener(ClosedListener listener, String remoteObjectName) Method used by the lookup-Classes to remove a single closed listener from a remote objectprotected List<ClosedListener>removeClosedListenerList(String remoteObjectName) Method used by the Loopup-Classes to remove a list of closed listener for a given remote objectvoidsendPong(org.apache.mina.core.session.IoSession session) voidsessionClosed(org.apache.mina.core.session.IoSession session) voidsessionCreated(org.apache.mina.core.session.IoSession session) voidsessionIdle(org.apache.mina.core.session.IoSession session, org.apache.mina.core.session.IdleStatus idleStatus) voidsessionOpened(org.apache.mina.core.session.IoSession session) protected voidsetPingTimeOut(int pingTimeOut) Method used by the Registry while setting the keep alive timeoutvoidshutdown()Initiates a shutdown at the dispatcher and all related thingsprotected voidunprepareRawChannel(int channelToken) TODO document meprotected voidwriteRawData(org.apache.mina.core.session.IoSession session, int channelToken, ByteBuffer byteBuffer) TODO document me
-
Constructor Details
-
Dispatcher
Creates a packet dispatcher which delegates the packet-reading toProcessMessageRunnable's which run in the giventhreadPool- Parameters:
serverString- an identifier string to determine to which server this dispatcher is connected to. this must be set tonullif this dispatcher is a server dispatcher.threadPool- the pool where theProcessMessageRunnable'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
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
Method used by the Lookup-Classes to register a closed listener with a given remote object name- Parameters:
listener- the listener to addremoteObjectName- the obejct that we listen for closed situations
-
removeClosedListener
Method used by the lookup-Classes to remove a single closed listener from a remote object- Parameters:
listener- the listener to removeremoteObjectName- 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 comesremoteObjectName- the remote object to lookup- Returns:
- the name lookup return message
- Throws:
LookupFailedException- if lookup failsSimonRemoteException- 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 comescanonicalInterfaceName- the canonical name of the interface- Returns:
- the interface lookup return message
- Throws:
LookupFailedException- if lookup failsSimonRemoteException
-
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 comesremoteObjectName- 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 comesremoteObjectName- 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 sentremoteObjectName- the name of the remote object that has to be comparedobjectToCompareWith- 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 sessionsequenceId- the sequence id that is waiting for the resulto- the result itself
-
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
Returns the identifier string which determines to which server this dispatcher is connected to- Returns:
- the identifier string. this is
nullif 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:
exceptionCaughtin interfaceorg.apache.mina.core.service.IoHandler- Throws:
Exception
-
messageReceived
public void messageReceived(org.apache.mina.core.session.IoSession session, Object message) throws Exception - Specified by:
messageReceivedin interfaceorg.apache.mina.core.service.IoHandler- Throws:
Exception
-
messageSent
public void messageSent(org.apache.mina.core.session.IoSession session, Object msg) throws Exception - Specified by:
messageSentin interfaceorg.apache.mina.core.service.IoHandler- Throws:
Exception
-
sessionClosed
- Specified by:
sessionClosedin interfaceorg.apache.mina.core.service.IoHandler- Throws:
Exception
-
sessionCreated
- Specified by:
sessionCreatedin interfaceorg.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:
sessionIdlein interfaceorg.apache.mina.core.service.IoHandler- Throws:
Exception
-
sendPong
- Throws:
SessionException
-
sessionOpened
- Specified by:
sessionOpenedin interfaceorg.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
TODO document me- Throws:
SimonException
-
isRawChannelDataListenerRegistered
protected boolean isRawChannelDataListenerRegistered(int channelToken) TODO document me -
getRawChannelDataListener
TODO document me -
unprepareRawChannel
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:
SimonRemoteExceptionRawChannelException
-
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 IoSessionchannelToken- the related channel token- Throws:
SimonRemoteExceptionRawChannelException
-
getPingWatchdog
Returns the PingWatchdog that checks the session connectivity- Returns:
- the current instance of PingWatchdog
-
getClosedListenerList
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
- Specified by:
inputClosedin interfaceorg.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:
eventin interfaceorg.apache.mina.core.service.IoHandler- Throws:
Exception
-