Class TcpGateway
java.lang.Object
com.sportradar.livedata.sdk.common.networking.TcpGateway
- All Implemented Interfaces:
Gateway
A
Gateway implementation which uses TCP protocol stack to communicate.- Author:
- uros.bregar
-
Constructor Summary
ConstructorsConstructorDescriptionTcpGateway(ExecutorService executor, SocketFactory socketFactory, InetSocketAddress endpoint, int bufferSize) Initializes a new instance of theTcpGatewayclass. -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Attempts to establish a connection to the remote site.voiddisconnect(boolean dueToError) Drops the established connection.getId()Gets gateway id (hostname, port, ...)longGets last timestamp in unix millis when the last msg was receivedbooleanGets a value specifying whether the connection to the remote site is established.voidsendData(byte[] data) Sends data through the currentGateway.voidsetListener(GatewayListener listener) Sets theGatewayListenerused to observe the currentGatewayimplementation.
-
Constructor Details
-
TcpGateway
public TcpGateway(ExecutorService executor, SocketFactory socketFactory, InetSocketAddress endpoint, int bufferSize) Initializes a new instance of theTcpGatewayclass.- Parameters:
executor- TheExecutorServiceinstance used to execute tasks.socketFactory- TheSocketFactoryinstance used to build theSocketendpoint- TheInetSocketAddressinstance specifying the remote endpoint of the socket.bufferSize- The size of the read buffer in bytes- Throws:
IllegalArgumentException- Theexecutoris a null reference orsocketFactoryis a null reference orendpointis a null reference orbufferSizeis smaller than zero.
-
-
Method Details
-
setListener
Sets theGatewayListenerused to observe the currentGatewayimplementation.- Specified by:
setListenerin interfaceGateway- Parameters:
listener- theGatewayListenerused to observe the currentGatewayimplementation or a null reference if observation is not required.
-
sendData
Sends data through the currentGateway.- Specified by:
sendDatain interfaceGateway- Parameters:
data- data to send.- Throws:
IllegalArgumentException- Thedatais a null reference or an empty arrayIOException- connection problem
-
connect
Attempts to establish a connection to the remote site.- Specified by:
connectin interfaceGateway- Throws:
IOException- There was an error establishing the connection.
-
disconnect
public void disconnect(boolean dueToError) Drops the established connection.- Specified by:
disconnectin 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:
isConnectedin 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:
getLastReceivedMsgTimestampin interfaceGateway- Returns:
- timestamp when the last msg was received
-
getId
Description copied from interface:GatewayGets gateway id (hostname, port, ...)
-