Class MessageParserBase<T extends MessageBase>
- java.lang.Object
-
- com.sportradar.livedata.sdk.proto.common.MessageParserBase<T>
-
- All Implemented Interfaces:
MessageParser<T>
- Direct Known Subclasses:
JaxbMessageParser
public abstract class MessageParserBase<T extends MessageBase> extends Object implements MessageParser<T>
Represents a base class for message parsers.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MessageParserBase(MessageTokenizer tokenizer)
Initializes a new instance of theMessageParserBase
class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes any data potentially left in the parser's buffer.protected void
notifyMessageReady(T message)
Notifies the attached observer that message was successfully parsed.protected abstract void
onDataReady(InputStream stream)
When overridden in derived class, it processes the received data.void
processData(InputStream stream)
Processes passed data.void
setListener(MessageParserListener<T> listener)
Sets theMessageParserListener
instance used to observe the currentMessageParserBase
-
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.MessageParser
getEncoding
-
-
-
-
Constructor Detail
-
MessageParserBase
protected MessageParserBase(MessageTokenizer tokenizer)
Initializes a new instance of theMessageParserBase
class.- Parameters:
tokenizer
- AMessageTokenizer
implementation used to tokenize received data, or a null reference.
-
-
Method Detail
-
onDataReady
protected abstract void onDataReady(InputStream stream) throws SdkException
When overridden in derived class, it processes the received data.- Parameters:
stream
- AInputStream
implementation containing the received data.- Throws:
SdkException
- thrown when an un-expected situation is encountered.
-
notifyMessageReady
protected void notifyMessageReady(T message)
Notifies the attached observer that message was successfully parsed.- Parameters:
message
- the parsed message
-
processData
public final void processData(InputStream stream) throws SdkException
Processes passed data. If passed data and any previously stored data represent a whole message theMessageParserListener.onMessageReady(T)
method is invoked- Specified by:
processData
in interfaceMessageParser<T extends MessageBase>
- Parameters:
stream
- AInputStream
instance containing message data.- Throws:
IllegalArgumentException
- thestream
is a null reference.ProtocolException
- the data could not be processed either because the buffer is full, an un-expected character was encountered or there was an error while un-marshalling the messageProtocolException
- the data could not be processed either because the buffer is full, an un-expected character was encountered or there was an error while un-marshalling the messageSdkException
-
clear
public void clear()
Removes any data potentially left in the parser's buffer.- Specified by:
clear
in interfaceMessageParser<T extends MessageBase>
-
setListener
public void setListener(MessageParserListener<T> listener)
Sets theMessageParserListener
instance used to observe the currentMessageParserBase
- Specified by:
setListener
in interfaceMessageParser<T extends MessageBase>
- Parameters:
listener
- TheMessageParserListener
instance used to observe the currentMessageParserBase
or a null reference.
-
-