Class ProtocolBase<I extends IncomingMessage,O extends OutgoingMessage>
java.lang.Object
com.sportradar.livedata.sdk.proto.common.ProtocolBase<I,O>
- All Implemented Interfaces:
Protocol<I,O>
- Direct Known Subclasses:
LiveFeedProtocol
public abstract class ProtocolBase<I extends IncomingMessage,O extends OutgoingMessage>
extends Object
implements Protocol<I,O>
Base class for all
Protocol implementations-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final GatewayTheGatewayimplementation used to establish a connection to the server.protected booleanThe value specifying whether the protocol is started - i.e.protected ProtocolListener<I> The listener used to observe the currentProtocolBaseprotected final MessageParser<I> TheMessageParserused to parse data received from the server.protected final SdkLoggerSdk logging facility. -
Constructor Summary
ConstructorsConstructorDescriptionProtocolBase(Gateway gateway, MessageParser<I> messageParser) Initializes a new instance of theProtocolBaseclass. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconnect()Instructs the internally usedGatewayto connect to the host.booleanGets the value indicating whether the protocol is started - i.e if the communication with server is enabled.protected voidnotifyOnEvent(FeedEventType eventType, Object data) Notifies the attached observer that an error occurred on the observed protocolprotected voidnotifyOnMessageReceived(I message) Notifies the attached observer the protocol has received message from the server.protected voidInvoked when the internally used gateway establishes a connection to the remote host.protected voidonGatewayDataReceived(InputStream stream) Invoked by the observedGatewayinstance when it receives new data from the server.protected voidInvoked when the internally usedGatewaydrops connection to the remote host.protected voidInvoked by the observedGatewaywhen the connection to the server is closed due to some error - connection closed by the server, missed connection alive message, invalid data ...protected voidonMessageParsed(I message) Invoked when the observedMessageParserparsed data which represented a whole message.voidReconnects the underlying feedprotected voidSets the listeners on the injected dependenciesvoidsetListener(ProtocolListener<I> listener) Sets theProtocolListenerused to observe the currentProtocol.voidstart()Starts the protocol - i.e.voidstop()Stops the protocol - i.e.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sportradar.livedata.sdk.proto.common.Protocol
sendMessage, sendMessage
-
Field Details
-
gateway
TheGatewayimplementation used to establish a connection to the server. -
messageParser
TheMessageParserused to parse data received from the server. -
sdkLogger
Sdk logging facility. -
isStarted
protected volatile boolean isStartedThe value specifying whether the protocol is started - i.e. is communication with the server enabled. -
listener
The listener used to observe the currentProtocolBase
-
-
Constructor Details
-
ProtocolBase
Initializes a new instance of theProtocolBaseclass.- Parameters:
gateway- TheGatewayimplementation used to establish a connection to the server.messageParser- TheMessageParserused to parse data received from the server.- Throws:
IllegalArgumentException- ThesdkLoggeris a null reference orgatewayis a null reference ormessageParseris a null reference.
-
-
Method Details
-
start
public void start()Starts the protocol - i.e. enables(starts) the communication with the server.- Specified by:
startin interfaceProtocol<I extends IncomingMessage,O extends OutgoingMessage>
-
reconnect
public void reconnect()Description copied from interface:ProtocolReconnects the underlying feed- Specified by:
reconnectin interfaceProtocol<I extends IncomingMessage,O extends OutgoingMessage>
-
isStarted
public boolean isStarted()Gets the value indicating whether the protocol is started - i.e if the communication with server is enabled.- Specified by:
isStartedin interfaceProtocol<I extends IncomingMessage,O extends OutgoingMessage> - Returns:
- True if protocol is started. False otherwise.
-
setListener
Sets theProtocolListenerused to observe the currentProtocol.- Specified by:
setListenerin interfaceProtocol<I extends IncomingMessage,O extends OutgoingMessage> - Parameters:
listener- theProtocolListenerused to observe the currentProtocolor a null reference.
-
stop
public void stop()Stops the protocol - i.e. disables the communication with the server.- Specified by:
stopin interfaceProtocol<I extends IncomingMessage,O extends OutgoingMessage>
-
setDependencyListeners
protected void setDependencyListeners()Sets the listeners on the injected dependencies -
onGatewayDataReceived
Invoked by the observedGatewayinstance when it receives new data from the server.- Parameters:
stream- TheInputStreamcontaining the received data.
-
onGatewayConnected
protected void onGatewayConnected()Invoked when the internally used gateway establishes a connection to the remote host. -
onGatewayDisconnected
protected void onGatewayDisconnected()Invoked when the internally usedGatewaydrops connection to the remote host. -
onGatewayError
Invoked by the observedGatewaywhen the connection to the server is closed due to some error - connection closed by the server, missed connection alive message, invalid data ...- Parameters:
ex- The exception which occurred on the observed gateway.
-
onMessageParsed
Invoked when the observedMessageParserparsed data which represented a whole message.- Parameters:
message- Message constructed from the received data.
-
notifyOnEvent
Notifies the attached observer that an error occurred on the observed protocol- Parameters:
eventType- TheFeedEventTypemember specifying the type of the occurred error.data- Opaque additional data
-
notifyOnMessageReceived
Notifies the attached observer the protocol has received message from the server.- Parameters:
message- the message received from the server.
-
connect
protected void connect()Instructs the internally usedGatewayto connect to the host.
-