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 allProtocol
implementations
-
-
Field Summary
Fields Modifier and Type Field Description protected Gateway
gateway
TheGateway
implementation used to establish a connection to the server.protected boolean
isStarted
The value specifying whether the protocol is started - i.e.protected ProtocolListener<I>
listener
The listener used to observe the currentProtocolBase
protected MessageParser<I>
messageParser
TheMessageParser
used to parse data received from the server.protected SdkLogger
sdkLogger
Sdk logging facility.
-
Constructor Summary
Constructors Constructor Description ProtocolBase(Gateway gateway, MessageParser<I> messageParser)
Initializes a new instance of theProtocolBase
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
connect()
Instructs the internally usedGateway
to connect to the host.boolean
isStarted()
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
onGatewayConnected()
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
onGatewayDisconnected()
Invoked when the internally usedGateway
drops connection to the remote host.protected void
onGatewayError(Exception ex)
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
reconnect()
Reconnects the underlying feedprotected void
setDependencyListeners()
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 Detail
-
gateway
protected final Gateway gateway
TheGateway
implementation used to establish a connection to the server.
-
messageParser
protected final MessageParser<I extends IncomingMessage> messageParser
TheMessageParser
used to parse data received from the server.
-
sdkLogger
protected final SdkLogger sdkLogger
Sdk logging facility.
-
isStarted
protected volatile boolean isStarted
The value specifying whether the protocol is started - i.e. is communication with the server enabled.
-
listener
protected volatile ProtocolListener<I extends IncomingMessage> listener
The listener used to observe the currentProtocolBase
-
-
Constructor Detail
-
ProtocolBase
public ProtocolBase(Gateway gateway, MessageParser<I> messageParser)
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 Detail
-
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
public void setListener(ProtocolListener<I> listener)
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
protected void onGatewayDataReceived(InputStream stream)
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
protected void onGatewayError(Exception ex)
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
protected void onMessageParsed(I message)
Invoked when the observedMessageParser
parsed data which represented a whole message.- Parameters:
message
- Message constructed from the received data.
-
notifyOnEvent
protected void notifyOnEvent(FeedEventType eventType, Object data)
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
protected void notifyOnMessageReceived(I message)
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.
-
-