Class WebSocketTransport
- java.lang.Object
-
- jadex.platform.service.message.websockettransport.WebSocketTransport
-
- All Implemented Interfaces:
ITransport<IWebSocketConnection>
public class WebSocketTransport extends java.lang.Object implements ITransport<IWebSocketConnection>
Transport implementing communication using web sockets.
-
-
Field Summary
Fields Modifier and Type Field Description protected WebSocketTransportAgent
handler
Connection handler.protected static int
PRIORITY
protected WebSocketServer
server
The server for incoming connections.
-
Constructor Summary
Constructors Constructor Description WebSocketTransport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeConnection(IWebSocketConnection con)
Perform close operations on a connection.IFuture<IWebSocketConnection>
createConnection(java.lang.String address, IComponentIdentifier target)
Create a connection to a given address.java.lang.String
getProtocolName()
Get the protocol name.void
init(ITransportHandler<IWebSocketConnection> handler)
Initialize the transport.IFuture<java.lang.Integer>
openPort(int port)
Open a port to accept connections.IFuture<java.lang.Integer>
sendMessage(IWebSocketConnection con, byte[] header, byte[] body)
Send bytes using the given connection.void
shutdown()
Shutdown and free all resources.
-
-
-
Field Detail
-
PRIORITY
protected static final int PRIORITY
- See Also:
- Constant Field Values
-
handler
protected WebSocketTransportAgent handler
Connection handler.
-
server
protected WebSocketServer server
The server for incoming connections.
-
-
Method Detail
-
init
public void init(ITransportHandler<IWebSocketConnection> handler)
Initialize the transport. To be called once, before any other method.- Specified by:
init
in interfaceITransport<IWebSocketConnection>
- Parameters:
handler
- The transport handler with callback methods.
-
shutdown
public void shutdown()
Shutdown and free all resources. To be called once, as last method.- Specified by:
shutdown
in interfaceITransport<IWebSocketConnection>
-
getProtocolName
public java.lang.String getProtocolName()
Get the protocol name.- Specified by:
getProtocolName
in interfaceITransport<IWebSocketConnection>
-
openPort
public IFuture<java.lang.Integer> openPort(int port)
Open a port to accept connections.- Specified by:
openPort
in interfaceITransport<IWebSocketConnection>
- Parameters:
port
- The (positive) port or 0 for any port.- Returns:
- A future holding the actual port, once the server is running.
-
createConnection
public IFuture<IWebSocketConnection> createConnection(java.lang.String address, IComponentIdentifier target)
Create a connection to a given address.- Specified by:
createConnection
in interfaceITransport<IWebSocketConnection>
- Parameters:
address
- The target platform's address.target
- The target identifier to maybe perform authentication of the connection.- Returns:
- A future containing the connection when succeeded.
-
closeConnection
public void closeConnection(IWebSocketConnection con)
Perform close operations on a connection. Potentially cleans up key attachments as well.- Specified by:
closeConnection
in interfaceITransport<IWebSocketConnection>
-
sendMessage
public IFuture<java.lang.Integer> sendMessage(IWebSocketConnection con, byte[] header, byte[] body)
Send bytes using the given connection.- Specified by:
sendMessage
in interfaceITransport<IWebSocketConnection>
- Parameters:
sc
- The connection.header
- The message header.body
- The message body.- Returns:
- A future indicating success.
-
-