Package jadex.platform.service.transport
Class AbstractTransportAgent<Con>
- java.lang.Object
-
- jadex.platform.service.transport.AbstractTransportAgent<Con>
-
- All Implemented Interfaces:
IInternalService
,IService
,IMemstatService
,ITransportInfoService
,ITransportService
,ITransportHandler<Con>
- Direct Known Subclasses:
IntravmTransportAgent
,TcpTransportAgent
,WebSocketTransportAgent
public class AbstractTransportAgent<Con> extends java.lang.Object implements ITransportService, ITransportHandler<Con>, ITransportInfoService, IMemstatService, IInternalService
-
-
Field Summary
Fields Modifier and Type Field Description protected IInternalAccess
agent
The agent.protected long
cleanupinterval
Cleanup interval.protected MultiCollection<IComponentIdentifier,Tuple3<ICommand<Con>,java.lang.Long,TerminableFuture<java.lang.Integer>>>
commandswaitingforcons
Commands waiting for a connection to be established, subject to timeouts.protected IRwMap<IComponentIdentifier,Con>
establishedconnections
The established connections, multithreaded.protected IExecutionFeature
execfeat
The execution feature.protected LeaseTimeMap<Con,IComponentIdentifier>
handshakingconnections
Connections to be established, subject to timeouts.protected ITransport<Con>
impl
The transport implementation.protected java.util.Collection<SubscriptionIntermediateFuture<PlatformData>>
infosubscribers
Listeners from transport info service.protected int
maxmsgsize
Maximum size a message is allowed to have (including header).protected java.util.concurrent.atomic.AtomicLong
nextcleanup
Next cleanup interval.protected IComponentIdentifier
platformid
The local platform ID.protected int
port
The port, the transport should listen to (<0: don't listen, 0: choose random port, >0: use given port).protected IRwMap<Con,IComponentIdentifier>
restablishedconnections
The established connections, reverse lookup, multithreaded.protected ISecurityService
secser
Security service.protected ISerializationServices
serser
Serialization services.protected ITransportAddressService
tas
Transport address service.-
Fields inherited from interface jadex.bridge.service.IService
EMPTY_SERVICES
-
-
Constructor Summary
Constructors Constructor Description AbstractTransportAgent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canDecide(IComponentIdentifier remotepf)
Check if the local platform can decide which connection to establish.protected void
cleanup()
Perform housekeeping operations if necessary.protected java.util.List<PlatformData>
collectConnectionStatus()
Collects the current connection status.void
connectionClosed(Con con, java.lang.Exception e)
Called when a connection is closed.void
connectionEstablished(Con con)
Called when a server connection is established.protected void
createNewConnections(IComponentIdentifier remotepf)
Creates new connections to a remote platform.ITransport<Con>
createTransportImpl()
Get the transport implementationstatic void
deliverRemoteMessage(IInternalAccess agent, ISecurityService secser, ISerializationServices serser, IComponentIdentifier source, byte[] header, byte[] body)
Delivers a remote message to a component.protected void
establishConnection(IComponentIdentifier remotepf, Con con)
Establish a connection after handshake.IInternalAccess
getAccess()
Get the internal access.IIntermediateFuture<PlatformData>
getConnections()
Get the established connections.IFuture<java.util.Map<java.lang.String,java.lang.Object>>
getMemInfo()
Get info about stored data like connections and listeners.IFuture<MethodInfo[]>
getMethodInfos()
Get reflective info about the service methods, args, return types.java.util.Map<java.lang.String,java.lang.Object>
getPropertyMap()
Get the map of properties (considered as constant).IServiceIdentifier
getServiceId()
Get the service identifier.IFuture<java.lang.Object>
invokeMethod(java.lang.String methodname, ClassInfo[] argtypes, java.lang.Object[] args, ClassInfo rettype)
Invoke a method reflectively.IFuture<java.lang.Boolean>
isValid()
Test if the service is valid.void
messageReceived(Con con, byte[] header, byte[] body)
Deliver a received message.ITerminableFuture<java.lang.Integer>
sendMessage(IMsgHeader header, byte[] bheader, byte[] body)
Send a message.IFuture<java.lang.Void>
setComponentAccess(IInternalAccess access)
Sets the access for the component.void
setServiceIdentifier(IServiceIdentifier sid)
Set the service identifier.IFuture<java.lang.Void>
shutdown()
IFuture<java.lang.Void>
shutdownService()
Shutdown the service.IFuture<java.lang.Void>
start()
Initialized agent.IFuture<java.lang.Void>
startService()
Start the service.ISubscriptionIntermediateFuture<PlatformData>
subscribeToConnections()
Get events about established connections.
-
-
-
Field Detail
-
port
protected int port
The port, the transport should listen to (<0: don't listen, 0: choose random port, >0: use given port).
-
maxmsgsize
protected int maxmsgsize
Maximum size a message is allowed to have (including header).
-
agent
protected IInternalAccess agent
The agent.
-
impl
protected ITransport<Con> impl
The transport implementation.
-
establishedconnections
protected IRwMap<IComponentIdentifier,Con> establishedconnections
The established connections, multithreaded.
-
restablishedconnections
protected IRwMap<Con,IComponentIdentifier> restablishedconnections
The established connections, reverse lookup, multithreaded.
-
commandswaitingforcons
protected MultiCollection<IComponentIdentifier,Tuple3<ICommand<Con>,java.lang.Long,TerminableFuture<java.lang.Integer>>> commandswaitingforcons
Commands waiting for a connection to be established, subject to timeouts.
-
handshakingconnections
protected LeaseTimeMap<Con,IComponentIdentifier> handshakingconnections
Connections to be established, subject to timeouts.
-
platformid
protected IComponentIdentifier platformid
The local platform ID.
-
secser
protected ISecurityService secser
Security service.
-
tas
protected ITransportAddressService tas
Transport address service.
-
serser
protected ISerializationServices serser
Serialization services.
-
execfeat
protected IExecutionFeature execfeat
The execution feature.
-
infosubscribers
protected java.util.Collection<SubscriptionIntermediateFuture<PlatformData>> infosubscribers
Listeners from transport info service.
-
cleanupinterval
protected long cleanupinterval
Cleanup interval.
-
nextcleanup
protected java.util.concurrent.atomic.AtomicLong nextcleanup
Next cleanup interval.
-
-
Method Detail
-
start
public IFuture<java.lang.Void> start()
Initialized agent.- Returns:
- Null, when done.
-
shutdown
public IFuture<java.lang.Void> shutdown()
-
sendMessage
public ITerminableFuture<java.lang.Integer> sendMessage(IMsgHeader header, byte[] bheader, byte[] body)
Send a message.- Specified by:
sendMessage
in interfaceITransportService
- Parameters:
header
- Message header.bheader
- Message header already encoded and encrypted for sending.body
- Message body.- Returns:
- Transport priority, when sent. Failure does not need to be returned as message feature uses its own timeouts. Future is terminated by message feature, when another transport has sent the message.
-
messageReceived
public void messageReceived(Con con, byte[] header, byte[] body)
Deliver a received message.- Specified by:
messageReceived
in interfaceITransportHandler<Con>
- Parameters:
con
- The connection.header
- The message header.body
- The message body.
-
connectionEstablished
public void connectionEstablished(Con con)
Called when a server connection is established.- Specified by:
connectionEstablished
in interfaceITransportHandler<Con>
- Parameters:
con
- The connection.
-
connectionClosed
public void connectionClosed(Con con, java.lang.Exception e)
Called when a connection is closed.- Specified by:
connectionClosed
in interfaceITransportHandler<Con>
- Parameters:
con
- The connection.e
- The exception, if any.
-
getAccess
public IInternalAccess getAccess()
Get the internal access.- Specified by:
getAccess
in interfaceITransportHandler<Con>
-
createTransportImpl
public ITransport<Con> createTransportImpl()
Get the transport implementation
-
subscribeToConnections
public ISubscriptionIntermediateFuture<PlatformData> subscribeToConnections()
Get events about established connections.- Specified by:
subscribeToConnections
in interfaceITransportInfoService
- Returns:
- Events for connections specified by 1: platform id, 2: protocol name, 3: ready flag (false=connecting, true=connected, null=disconnected).
-
getConnections
public IIntermediateFuture<PlatformData> getConnections()
Get the established connections.- Specified by:
getConnections
in interfaceITransportInfoService
- Returns:
- A list of connections specified by 1: platform id, 2: protocol name, 3: ready flag (false=connecting, true=connected).
-
getMemInfo
public IFuture<java.util.Map<java.lang.String,java.lang.Object>> getMemInfo()
Get info about stored data like connections and listeners.- Specified by:
getMemInfo
in interfaceIMemstatService
-
createNewConnections
protected void createNewConnections(IComponentIdentifier remotepf)
Creates new connections to a remote platform.- Parameters:
remotepf
- The remote platform ID.
-
establishConnection
protected void establishConnection(IComponentIdentifier remotepf, Con con)
Establish a connection after handshake.- Parameters:
remotepf
- The remote platform.con
- The connection.
-
cleanup
protected void cleanup()
Perform housekeeping operations if necessary.
-
canDecide
protected boolean canDecide(IComponentIdentifier remotepf)
Check if the local platform can decide which connection to establish.- Parameters:
remotepf
- Remote platform ID.- Returns:
- True, if the local platform can decide.
-
collectConnectionStatus
protected java.util.List<PlatformData> collectConnectionStatus()
Collects the current connection status.- Returns:
- The current connection status.
-
getServiceId
public IServiceIdentifier getServiceId()
Get the service identifier.- Specified by:
getServiceId
in interfaceIService
- Returns:
- The service identifier.
-
isValid
public IFuture<java.lang.Boolean> isValid()
Test if the service is valid.
-
getPropertyMap
public java.util.Map<java.lang.String,java.lang.Object> getPropertyMap()
Get the map of properties (considered as constant).- Specified by:
getPropertyMap
in interfaceIService
- Returns:
- The service property map (if any).
-
startService
public IFuture<java.lang.Void> startService()
Start the service.- Specified by:
startService
in interfaceIInternalService
- Returns:
- A future that is done when the service has completed starting.
-
shutdownService
public IFuture<java.lang.Void> shutdownService()
Shutdown the service.- Specified by:
shutdownService
in interfaceIInternalService
- Returns:
- A future that is done when the service has completed its shutdown.
-
setComponentAccess
public IFuture<java.lang.Void> setComponentAccess(IInternalAccess access)
Sets the access for the component.- Specified by:
setComponentAccess
in interfaceIInternalService
- Parameters:
access
- Component access.
-
setServiceIdentifier
public void setServiceIdentifier(IServiceIdentifier sid)
Set the service identifier.- Specified by:
setServiceIdentifier
in interfaceIInternalService
-
invokeMethod
public IFuture<java.lang.Object> invokeMethod(java.lang.String methodname, ClassInfo[] argtypes, java.lang.Object[] args, ClassInfo rettype)
Invoke a method reflectively.- Specified by:
invokeMethod
in interfaceIService
- Parameters:
methodname
- The method name.argtypes
- The argument types (can be null if method exists only once).args
- The arguments.rettype
- The future return type if it is a specific future.- Returns:
- The result.
-
getMethodInfos
public IFuture<MethodInfo[]> getMethodInfos()
Get reflective info about the service methods, args, return types.- Specified by:
getMethodInfos
in interfaceIService
- Returns:
- The method infos.
-
deliverRemoteMessage
public static final void deliverRemoteMessage(IInternalAccess agent, ISecurityService secser, ISerializationServices serser, IComponentIdentifier source, byte[] header, byte[] body)
Delivers a remote message to a component.- Parameters:
agent
- Agent performing the delivery.secser
- The security service.cms
- The component management service.serser
- The serialization services.source
- Source ID of the message.header
- The header of the message.body
- The body of the message.
-
-