Constructor and Description |
---|
TcpGateway(ExecutorService executor,
SocketFactory socketFactory,
InetSocketAddress endpoint,
int bufferSize)
Initializes a new instance of the
TcpGateway class. |
Modifier and Type | Method and Description |
---|---|
void |
connect()
Attempts to establish a connection to the remote site.
|
void |
disconnect(boolean dueToError)
Drops the established connection.
|
String |
getId()
Gets gateway id (hostname, port, ...)
|
long |
getLastReceivedMsgTimestamp()
Gets last timestamp in unix millis when the last msg was received
|
boolean |
isConnected()
Gets a value specifying whether the connection to the remote site is established.
|
void |
sendData(byte[] data)
Sends data through the current
Gateway . |
void |
setListener(GatewayListener listener)
Sets the
GatewayListener used to observe the current Gateway implementation. |
public TcpGateway(ExecutorService executor, SocketFactory socketFactory, InetSocketAddress endpoint, int bufferSize)
TcpGateway
class.executor
- The ExecutorService
instance used to execute tasks.socketFactory
- The SocketFactory
instance used to build the Socket
endpoint
- The InetSocketAddress
instance specifying the remote endpoint of the socket.bufferSize
- The size of the read buffer in bytesIllegalArgumentException
- The executor
is a null reference or socketFactory
is a null reference or endpoint
is a null reference or bufferSize
is smaller than zero.public void setListener(GatewayListener listener)
GatewayListener
used to observe the current Gateway
implementation.setListener
in interface Gateway
listener
- the GatewayListener
used to observe the current Gateway
implementation or a null reference if observation is not required.public void sendData(byte[] data) throws IOException
Gateway
.sendData
in interface Gateway
data
- data to send.IllegalArgumentException
- The data
is a null reference or an empty arrayIOException
public void connect() throws IOException
connect
in interface Gateway
IOException
- There was an error establishing the connection.public void disconnect(boolean dueToError)
disconnect
in interface Gateway
dueToError
- - when false user wished to close connection; when true there was a problem and we had
to close itpublic boolean isConnected()
isConnected
in interface Gateway
public long getLastReceivedMsgTimestamp()
getLastReceivedMsgTimestamp
in interface Gateway
Copyright © 2013–2023. All rights reserved.