Class LiveFeedProtocol
- java.lang.Object
-
- com.sportradar.livedata.sdk.proto.common.ProtocolBase<IncomingMessage,OutgoingMessage>
-
- com.sportradar.livedata.sdk.proto.LiveFeedProtocol
-
- All Implemented Interfaces:
Protocol<IncomingMessage,OutgoingMessage>
public class LiveFeedProtocol extends ProtocolBase<IncomingMessage,OutgoingMessage>
AProtocol
implementation used to connect to the live-feed.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.joda.time.Duration
DISCONNECT_WHEN_HAVING_TO_WAIT_LONGER_THAN
When having to wait longer than that amount of time for logging-in, just disconnect.-
Fields inherited from class com.sportradar.livedata.sdk.proto.common.ProtocolBase
gateway, isStarted, listener, messageParser, sdkLogger
-
-
Constructor Summary
Constructors Constructor Description LiveFeedProtocol(Gateway gateway, MessageParser<IncomingMessage> messageParser, MessageWriter<OutgoingMessage> messageWriter, RateLimiter rateLimiter, OutgoingMessageInspector<OutgoingMessage> outgoingMessageInspector, StatusFactory statusFactory, LiveFeedSettings settings)
Initializes a new instance of theLiveFeedProtocol
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
notifyOnDisconnected()
Notifies the observer that the currentLiveFeedProtocol
has disconnected.protected void
notifyOnLoggedIn()
Notifies the observer that the currentLiveFeedProtocol
has logged in.protected void
onGatewayConnected()
Invoked by the observedGateway
instance when it establishes a connection to the server.protected void
onGatewayDisconnected()
Invoked when the internally usedGateway
drops connection to the remote host.protected void
onMessageParsed(IncomingMessage message)
Invoked when the observedMessageParser
parsed data which represented a whole message.boolean
sendMessage(OutgoingMessage message, boolean blocking)
Sends the passedOutgoingMessage
instance to the server.void
sendMessage(String data)
Sends the passed data to the server as is.void
stop()
Stops the protocol - i.e.-
Methods inherited from class com.sportradar.livedata.sdk.proto.common.ProtocolBase
connect, isStarted, notifyOnEvent, notifyOnMessageReceived, onGatewayDataReceived, onGatewayError, reconnect, setDependencyListeners, setListener, start
-
-
-
-
Constructor Detail
-
LiveFeedProtocol
public LiveFeedProtocol(Gateway gateway, MessageParser<IncomingMessage> messageParser, MessageWriter<OutgoingMessage> messageWriter, RateLimiter rateLimiter, OutgoingMessageInspector<OutgoingMessage> outgoingMessageInspector, StatusFactory statusFactory, LiveFeedSettings settings)
Initializes a new instance of theLiveFeedProtocol
class.- Parameters:
gateway
- TheGateway
implementation used to establish a connection to the live-odds server.messageParser
- TheMessageParser
implementation used to constructIncomingMessage
instances from data received from the server.messageWriter
- Theused to write messages to {@link byte[]}
.rateLimiter
- TheRateLimiter
implementation used to rate-limit send messagesoutgoingMessageInspector
- TheOutgoingMessageInspector
implementation used to inspect send messages.statusFactory
- The factory used to build requests send to the feed.settings
- TheLiveFeedSettings
instance containing the application's settings concerning the live-feed
-
-
Method Detail
-
sendMessage
public boolean sendMessage(OutgoingMessage message, boolean blocking) throws MessageException, ProtocolException
Sends the passedOutgoingMessage
instance to the server.- Parameters:
message
- The message derived fromOutgoingMessage
to be send to the server.blocking
- true if request must be blocking.- Returns:
- true if success.
- Throws:
MessageException
- An error occurred while writing the message to byte array.ProtocolException
- thrown when an un-expected situation is encountered.
-
sendMessage
public void sendMessage(String data) throws MessageException, ProtocolException
Sends the passed data to the server as is.- Parameters:
data
- data to be sent.- Throws:
MessageException
- An error occurred while writing the message to byte array.ProtocolException
- thrown when an un-expected situation is encountered.
-
stop
public void stop()
Stops the protocol - i.e. disables the communication with the server.- Specified by:
stop
in interfaceProtocol<IncomingMessage,OutgoingMessage>
- Overrides:
stop
in classProtocolBase<IncomingMessage,OutgoingMessage>
-
onGatewayConnected
protected void onGatewayConnected()
Invoked by the observedGateway
instance when it establishes a connection to the server.- Overrides:
onGatewayConnected
in classProtocolBase<IncomingMessage,OutgoingMessage>
-
onGatewayDisconnected
protected void onGatewayDisconnected()
Invoked when the internally usedGateway
drops connection to the remote host.- Overrides:
onGatewayDisconnected
in classProtocolBase<IncomingMessage,OutgoingMessage>
-
onMessageParsed
protected void onMessageParsed(IncomingMessage message)
Invoked when the observedMessageParser
parsed data which represented a whole message.- Overrides:
onMessageParsed
in classProtocolBase<IncomingMessage,OutgoingMessage>
- Parameters:
message
- Message constructed from the received data.
-
notifyOnDisconnected
protected void notifyOnDisconnected()
Notifies the observer that the currentLiveFeedProtocol
has disconnected.
-
notifyOnLoggedIn
protected void notifyOnLoggedIn()
Notifies the observer that the currentLiveFeedProtocol
has logged in.
-
-