Package jade.imtp.leap.nio
Class NIOBEDispatcher
- java.lang.Object
-
- jade.imtp.leap.nio.NIOBEDispatcher
-
- All Implemented Interfaces:
BEConnectionManager,Dispatcher,JICPMediator,NIOMediator
- Direct Known Subclasses:
SMSBEDispatcher
public class NIOBEDispatcher extends Object implements NIOMediator, BEConnectionManager, Dispatcher
This class implements the BIFEDispatcher related BackEnd dispatcher managable by an asynchronous JICPMediatorManager- Author:
- Giovanni Caire - Telecom Italia LAB S.p.A.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classNIOBEDispatcher.InputManagerInner class InputManager.protected classNIOBEDispatcher.OutputManagerInner class OutputManager This class manages the reception of commands and keep-alive packets from the FrontEnd.
-
Field Summary
Fields Modifier and Type Field Description protected NIOBEDispatcher.InputManagerinpManagerprotected NIOBEDispatcher.OutputManageroutManager
-
Constructor Summary
Constructors Constructor Description NIOBEDispatcher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]dispatch(byte[] payload, boolean flush, int oldSessionId)FrontEndgetFrontEnd(BackEnd be, Properties props)Return a stub of the remote FrontEnd that is connected to the local BackEnd.StringgetID()Retrieve the ID of this mediator.PropertiesgetProperties()Retrieve the startup Properties for this NIOBEDispatcher.voidhandleConnectionError(Connection c, Exception e)Notify this NIOMediator that an error occurred on one of the Connections it was using.protected voidhandleDropDown(Connection c, JICPPacket pkt, InetAddress addr, int port)Handle a connection DROP_DOWN request from the FE.booleanhandleIncomingConnection(Connection c, JICPPacket pkt, InetAddress addr, int port)Passes to this JICPMediator the connection opened by the mediated entity.JICPPackethandleJICPPacket(Connection c, JICPPacket pkt, InetAddress addr, int port)Overloaded version of the handleJICPPacket() method including theConnectionthe incoming JICPPacket was received from.JICPPackethandleJICPPacket(JICPPacket p, InetAddress addr, int port)Passes to this mediator a JICPPacket received by the JICPMediatorManager this mediator is attached to.voidinit(JICPMediatorManager mgr, String id, Properties props)Initialize this JICPMediatorbooleanisConnected()voidkill()Kill the above container.protected voidrequestRefresh()Request the FE to refresh the connection.voidshutdown()Make this NIOBEDispatcher terminate.protected BackEndSkelstartBackEndContainer(Properties props)voidtick(long currentTime)This is periodically called by the JICPMediatorManager and is used by this NIOMediator to evaluate the elapsed time without the need of a dedicated thread or timer.
-
-
-
Field Detail
-
inpManager
protected NIOBEDispatcher.InputManager inpManager
-
outManager
protected NIOBEDispatcher.OutputManager outManager
-
-
Method Detail
-
getID
public String getID()
Retrieve the ID of this mediator. Returns null if this mediator is not active- Specified by:
getIDin interfaceJICPMediator
-
getProperties
public Properties getProperties()
Retrieve the startup Properties for this NIOBEDispatcher.- Specified by:
getPropertiesin interfaceNIOMediator
-
init
public void init(JICPMediatorManager mgr, String id, Properties props) throws ICPException
Initialize this JICPMediator- Specified by:
initin interfaceJICPMediator- Throws:
ICPException
-
startBackEndContainer
protected final BackEndSkel startBackEndContainer(Properties props) throws ICPException
- Throws:
ICPException
-
kill
public void kill()
Kill the above container. This may be called by the JICPMediatorManager or when a peer termination notification is received.- Specified by:
killin interfaceJICPMediator
-
handleIncomingConnection
public boolean handleIncomingConnection(Connection c, JICPPacket pkt, InetAddress addr, int port)
Passes to this JICPMediator the connection opened by the mediated entity. This is called by the JICPMediatorManager this Mediator is attached to as soon as the mediated entity (re)connects.- Specified by:
handleIncomingConnectionin interfaceJICPMediator- Parameters:
c- the connection to the mediated entitypkt- the packet that was sent by the mediated entity when opening this connectionaddr- the address of the mediated entityport- the local port used by the mediated entity- Returns:
- an indication to the JICPMediatorManager to keep the connection open.
-
handleConnectionError
public void handleConnectionError(Connection c, Exception e)
Notify this NIOMediator that an error occurred on one of the Connections it was using. This information is important since, unlike normal mediators, a NIOMediator typically does not read packets from connections on its own (the JICPMediatorManager does that in general).- Specified by:
handleConnectionErrorin interfaceNIOMediator
-
handleJICPPacket
public JICPPacket handleJICPPacket(JICPPacket p, InetAddress addr, int port) throws ICPException
Passes to this mediator a JICPPacket received by the JICPMediatorManager this mediator is attached to. In a NIOMediator this should never be called.- Specified by:
handleJICPPacketin interfaceJICPMediator- Parameters:
p- the JICPPacketaddr- the address of the mediated entityport- the local port used by the mediated entity- Throws:
ICPException
-
handleJICPPacket
public JICPPacket handleJICPPacket(Connection c, JICPPacket pkt, InetAddress addr, int port) throws ICPException
Overloaded version of the handleJICPPacket() method including theConnectionthe incoming JICPPacket was received from. This information is important since, unlike normal mediators, a NIOMediator may not read packets from connections on its own (the JICPMediatorManager does that in general).- Specified by:
handleJICPPacketin interfaceNIOMediator- Throws:
ICPException
-
tick
public final void tick(long currentTime)
This is periodically called by the JICPMediatorManager and is used by this NIOMediator to evaluate the elapsed time without the need of a dedicated thread or timer.- Specified by:
tickin interfaceJICPMediator
-
getFrontEnd
public FrontEnd getFrontEnd(BackEnd be, Properties props) throws IMTPException
Return a stub of the remote FrontEnd that is connected to the local BackEnd.- Specified by:
getFrontEndin interfaceBEConnectionManager- Parameters:
be- The local BackEndprops- Additional (implementation dependent) connection configuration properties.- Returns:
- A stub of the remote FrontEnd.
- Throws:
IMTPException
-
shutdown
public void shutdown()
Make this NIOBEDispatcher terminate.- Specified by:
shutdownin interfaceBEConnectionManager
-
dispatch
public byte[] dispatch(byte[] payload, boolean flush, int oldSessionId) throws ICPException- Specified by:
dispatchin interfaceDispatcher- Throws:
ICPException
-
handleDropDown
protected void handleDropDown(Connection c, JICPPacket pkt, InetAddress addr, int port)
Handle a connection DROP_DOWN request from the FE.
-
requestRefresh
protected void requestRefresh()
Request the FE to refresh the connection.
-
isConnected
public boolean isConnected()
-
-