Class TcpGateway
- java.lang.Object
-
- com.sportradar.livedata.sdk.common.networking.TcpGateway
-
-
Constructor Summary
Constructors Constructor Description TcpGateway(ExecutorService executor, SocketFactory socketFactory, InetSocketAddress endpoint, int bufferSize)
Initializes a new instance of theTcpGateway
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 receivedboolean
isConnected()
Gets a value specifying whether the connection to the remote site is established.void
sendData(byte[] data)
Sends data through the currentGateway
.void
setListener(GatewayListener listener)
Sets theGatewayListener
used to observe the currentGateway
implementation.
-
-
-
Constructor Detail
-
TcpGateway
public TcpGateway(ExecutorService executor, SocketFactory socketFactory, InetSocketAddress endpoint, int bufferSize)
Initializes a new instance of theTcpGateway
class.- Parameters:
executor
- TheExecutorService
instance used to execute tasks.socketFactory
- TheSocketFactory
instance used to build theSocket
endpoint
- TheInetSocketAddress
instance specifying the remote endpoint of the socket.bufferSize
- The size of the read buffer in bytes- Throws:
IllegalArgumentException
- Theexecutor
is a null reference orsocketFactory
is a null reference orendpoint
is a null reference orbufferSize
is smaller than zero.
-
-
Method Detail
-
setListener
public void setListener(GatewayListener listener)
Sets theGatewayListener
used to observe the currentGateway
implementation.- Specified by:
setListener
in interfaceGateway
- Parameters:
listener
- theGatewayListener
used to observe the currentGateway
implementation or a null reference if observation is not required.
-
sendData
public void sendData(byte[] data) throws IOException
Sends data through the currentGateway
.- Specified by:
sendData
in interfaceGateway
- Parameters:
data
- data to send.- Throws:
IllegalArgumentException
- Thedata
is a null reference or an empty arrayIOException
- connection problem
-
connect
public void connect() throws IOException
Attempts to establish a connection to the remote site.- Specified by:
connect
in interfaceGateway
- Throws:
IOException
- There was an error establishing the connection.
-
disconnect
public void disconnect(boolean dueToError)
Drops the established connection.- Specified by:
disconnect
in interfaceGateway
- Parameters:
dueToError
- - when false user wished to close connection; when true there was a problem and we had to close it
-
isConnected
public boolean isConnected()
Gets a value specifying whether the connection to the remote site is established.- Specified by:
isConnected
in interfaceGateway
- Returns:
- Value specifying whether the connection to the remote site is established.
-
getLastReceivedMsgTimestamp
public long getLastReceivedMsgTimestamp()
Gets last timestamp in unix millis when the last msg was received- Specified by:
getLastReceivedMsgTimestamp
in interfaceGateway
- Returns:
- timestamp when the last msg was received
-
-