public class TCPTransport extends java.lang.Object implements ITransport
Modifier and Type | Class and Description |
---|---|
protected class |
TCPTransport.Cleaner
Class for cleaning output connections after
max keep alive time has been reached.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
addresses
The addresses.
|
protected boolean |
async
Should be received asynchronously? One thread for receiving is
unavoidable.
|
static java.lang.String |
ASYNCHRONOUS
Constant for asynchronous setting.
|
protected static int |
BUFFER_SIZE
2MB as message buffer
|
protected jadex.bridge.IInternalAccess |
component
The platform.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
connections
The opened connections for addresses.
|
protected static int |
DEFAULT_PORT
Default port.
|
protected java.util.logging.Logger |
logger
The logger.
|
protected static int |
MAX_CONNECTIONS
Maximum number of outgoing connections
|
protected static int |
MAX_KEEPALIVE
How long to keep output connections alive (5 min).
|
protected jadex.bridge.service.types.message.IMessageService |
msgservice
The message service .
|
protected int |
port
The port.
|
static java.lang.String |
PORT
The receiving port.
|
static java.lang.String[] |
SCHEMAS
The schema name.
|
protected java.net.ServerSocket |
serversocket
The server socket for receiving messages.
|
protected jadex.bridge.service.types.threadpool.IDaemonThreadPoolService |
threadpool
The thread pool.
|
protected java.util.Timer |
timer
The cleanup timer.
|
Constructor and Description |
---|
TCPTransport(jadex.bridge.IInternalAccess component,
int port)
Init the transport.
|
TCPTransport(jadex.bridge.IInternalAccess component,
int port,
boolean async)
Init the transport.
|
Modifier and Type | Method and Description |
---|---|
java.net.Socket |
createClientSocket(java.lang.String host,
int port)
Create a client socket.
|
protected jadex.commons.future.IFuture<TCPOutputConnection> |
createConnection(java.lang.String address)
Create a outgoing connection.
|
java.net.ServerSocket |
createServerSocket()
Create a server socket.
|
protected jadex.commons.future.IFuture<java.lang.Void> |
deliverMessages(TCPInputConnection con)
Deliver messages to local message service
for dispatching to the components.
|
protected java.lang.String |
getAddress(java.lang.String schema,
java.lang.String hostname,
int port)
Get the address of this transport.
|
java.lang.String[] |
getAddresses()
Get the adresses of this transport.
|
protected jadex.commons.future.IFuture<TCPOutputConnection> |
getConnection(java.lang.String addr,
boolean create)
Get the connection.
|
protected jadex.commons.future.IFuture<jadex.bridge.service.types.message.IMessageService> |
getMessageService() |
java.lang.String[] |
getServiceSchemas()
Returns the prefix of this transport
|
boolean |
isApplicable(java.lang.String address)
Test if a transport is applicable for the target address.
|
boolean |
isNonFunctionalSatisfied(java.util.Map<java.lang.String,java.lang.Object> nonfunc,
java.lang.String address)
Test if a transport satisfies the non-functional requirements.
|
protected void |
removeConnection(java.lang.String address)
Remove a cached connection.
|
void |
sendMessage(java.lang.String address,
ISendTask task)
Send a message to the given address.
|
jadex.commons.future.IFuture<java.lang.Void> |
shutdown()
Perform cleanup operations (if any).
|
jadex.commons.future.IFuture<java.lang.Void> |
start()
Start the transport.
|
public static final java.lang.String[] SCHEMAS
public static final java.lang.String ASYNCHRONOUS
public static final java.lang.String PORT
protected static final int MAX_KEEPALIVE
protected static final int BUFFER_SIZE
protected static final int MAX_CONNECTIONS
protected static final int DEFAULT_PORT
protected jadex.bridge.IInternalAccess component
protected java.lang.String[] addresses
protected int port
protected java.net.ServerSocket serversocket
protected java.util.Map<java.lang.String,java.lang.Object> connections
protected boolean async
protected java.util.logging.Logger logger
protected java.util.Timer timer
protected jadex.bridge.service.types.threadpool.IDaemonThreadPoolService threadpool
protected jadex.bridge.service.types.message.IMessageService msgservice
public TCPTransport(jadex.bridge.IInternalAccess component, int port)
platform
- The platform.settings
- The settings.public TCPTransport(jadex.bridge.IInternalAccess component, int port, boolean async)
platform
- The platform.settings
- The settings.public jadex.commons.future.IFuture<java.lang.Void> start()
start
in interface ITransport
public jadex.commons.future.IFuture<java.lang.Void> shutdown()
shutdown
in interface ITransport
public java.net.ServerSocket createServerSocket() throws java.lang.Exception
java.lang.Exception
public java.net.Socket createClientSocket(java.lang.String host, int port) throws java.lang.Exception
java.lang.Exception
public boolean isApplicable(java.lang.String address)
isApplicable
in interface ITransport
public boolean isNonFunctionalSatisfied(java.util.Map<java.lang.String,java.lang.Object> nonfunc, java.lang.String address)
isNonFunctionalSatisfied
in interface ITransport
nonfunc
- The non-functional requirements (name, value).address
- The transport address.public void sendMessage(java.lang.String address, ISendTask task)
sendMessage
in interface ITransport
address
- The address to send to.task
- A task representing the message to send.public java.lang.String[] getServiceSchemas()
getServiceSchemas
in interface ITransport
public java.lang.String[] getAddresses()
getAddresses
in interface ITransport
protected java.lang.String getAddress(java.lang.String schema, java.lang.String hostname, int port)
hostname
- The hostname.port
- The port.protected jadex.commons.future.IFuture<TCPOutputConnection> getConnection(java.lang.String addr, boolean create)
address
- protected jadex.commons.future.IFuture<TCPOutputConnection> createConnection(java.lang.String address)
address
- The connection address.protected void removeConnection(java.lang.String address)
address
- The address.protected jadex.commons.future.IFuture<java.lang.Void> deliverMessages(TCPInputConnection con)
con
- The connection.protected jadex.commons.future.IFuture<jadex.bridge.service.types.message.IMessageService> getMessageService()