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 Gateway
TheGateway
implementation used to establish a connection to the server.protected boolean
The value specifying whether the protocol is started - i.e.protected ProtocolListener
<I> The listener used to observe the currentProtocolBase
protected final MessageParser
<I> TheMessageParser
used to parse data received from the server.protected final SdkLogger
Sdk logging facility. -
Constructor Summary
ConstructorsConstructorDescriptionProtocolBase
(Gateway gateway, MessageParser<I> messageParser) Initializes a new instance of theProtocolBase
class. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
connect()
Instructs the internally usedGateway
to connect to the host.boolean
Gets the value indicating whether the protocol is started - i.e if the communication with server is enabled.protected void
notifyOnEvent
(FeedEventType eventType, Object data) Notifies the attached observer that an error occurred on the observed protocolprotected void
notifyOnMessageReceived
(I message) Notifies the attached observer the protocol has received message from the server.protected void
Invoked when the internally used gateway establishes a connection to the remote host.protected void
onGatewayDataReceived
(InputStream stream) Invoked by the observedGateway
instance when it receives new data from the server.protected void
Invoked when the internally usedGateway
drops connection to the remote host.protected void
Invoked by the observedGateway
when the connection to the server is closed due to some error - connection closed by the server, missed connection alive message, invalid data ...protected void
onMessageParsed
(I message) Invoked when the observedMessageParser
parsed data which represented a whole message.void
Reconnects the underlying feedprotected void
Sets the listeners on the injected dependenciesvoid
setListener
(ProtocolListener<I> listener) Sets theProtocolListener
used to observe the currentProtocol
.void
start()
Starts the protocol - i.e.void
stop()
Stops the protocol - i.e.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.sportradar.livedata.sdk.proto.common.Protocol
sendMessage, sendMessage
-
Field Details
-
gateway
TheGateway
implementation used to establish a connection to the server. -
messageParser
TheMessageParser
used 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 theProtocolBase
class.- Parameters:
gateway
- TheGateway
implementation used to establish a connection to the server.messageParser
- TheMessageParser
used to parse data received from the server.- Throws:
IllegalArgumentException
- ThesdkLogger
is a null reference orgateway
is a null reference ormessageParser
is a null reference.
-
-
Method Details
-
start
public void start()Starts the protocol - i.e. enables(starts) the communication with the server.- Specified by:
start
in interfaceProtocol<I extends IncomingMessage,
O extends OutgoingMessage>
-
reconnect
public void reconnect()Description copied from interface:Protocol
Reconnects the underlying feed- Specified by:
reconnect
in 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:
isStarted
in interfaceProtocol<I extends IncomingMessage,
O extends OutgoingMessage> - Returns:
- True if protocol is started. False otherwise.
-
setListener
Sets theProtocolListener
used to observe the currentProtocol
.- Specified by:
setListener
in interfaceProtocol<I extends IncomingMessage,
O extends OutgoingMessage> - Parameters:
listener
- theProtocolListener
used to observe the currentProtocol
or a null reference.
-
stop
public void stop()Stops the protocol - i.e. disables the communication with the server.- Specified by:
stop
in interfaceProtocol<I extends IncomingMessage,
O extends OutgoingMessage>
-
setDependencyListeners
protected void setDependencyListeners()Sets the listeners on the injected dependencies -
onGatewayDataReceived
Invoked by the observedGateway
instance when it receives new data from the server.- Parameters:
stream
- TheInputStream
containing 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 usedGateway
drops connection to the remote host. -
onGatewayError
Invoked by the observedGateway
when 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 observedMessageParser
parsed 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
- TheFeedEventType
member 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 usedGateway
to connect to the host.
-