public interface MessageReader<H extends MessageHeader,M extends Message>
| Modifier and Type | Method and Description |
|---|---|
default byte |
getMessageSequence()
Get last message sequence number, as it was stored by
readHeader(). |
default H |
probeHeader()
Read the next message header from server, possibly blocking indefinitely until the message is received,
and cache it so that the next
readHeader() return the same header. |
default M |
probeMessage(Optional<M> reuse,
H header)
Read message from server into to the given
Message instance or into the new one if not present
and cache it so that the next readMessage(Optional, MessageHeader) return the same message. |
default void |
pushMessageListener(MessageListener<M> l)
Queue a
MessageListener to receive messages delivered asynchronously. |
H |
readHeader()
Read the next message header from server, possibly blocking indefinitely until the message is received.
|
M |
readMessage(Optional<M> reuse,
H header)
Read message from server into to the given
Message instance or into the new one if not present. |
default M |
readMessage(Optional<M> reuse,
int expectedType)
Read message from server into to the given
Message instance or into the new one if not present. |
default void |
resetMessageSequence()
Set stored message sequence number to 0.
|
default void |
skipPacket()
Skips the next packet, or the current one if previously probed, by reading and discarding it.
|
default void |
start()
Start reading messages reader from the provided channel.
|
default void |
stopAfterNextMessage()
Signal to the reader that it should stop reading messages after reading the next message.
|
default MessageReader<H,M> |
undecorate()
Return the previous MessageReader instance from the decorators chain or the current MessageReader
if it is the first entry in a chain.
|
default MessageReader<H,M> |
undecorateAll()
Return a MessageReader instance free of decorators.
|
H readHeader() throws IOException
MessageHeader of the next messageIOException - if an error occursdefault H probeHeader() throws IOException
readHeader() return the same header.MessageHeader of the next messageIOException - if an error occursM readMessage(Optional<M> reuse, H header) throws IOException
Message instance or into the new one if not present.
For asynchronous channel it synchronously reads the next message in the stream, blocking until the message is read fully.
Could throw CJCommunicationsException wrapping an IOException during read or parsereuse - Message object to reuse. May be ignored by implementation.header - MessageHeader instanceMessage instanceIOException - if an error occursdefault M probeMessage(Optional<M> reuse, H header) throws IOException
Message instance or into the new one if not present
and cache it so that the next readMessage(Optional, MessageHeader) return the same message.
For asynchronous channel it synchronously reads the next message in the stream, blocking until the message is read fully.
Could throw CJCommunicationsException wrapping an IOException during read or parsereuse - Message object to reuse. May be ignored by implementation.header - MessageHeader instanceMessage instanceIOException - if an error occursdefault M readMessage(Optional<M> reuse, int expectedType) throws IOException
Message instance or into the new one if not present.
For asynchronous channel it synchronously reads the next message in the stream, blocking until the message is read fully.
Could throw WrongArgumentException if the expected message type is not the next message (exception will be thrown in *caller* context).reuse - Message object to reuse. May be ignored by implementation.expectedType - Expected type of message.Message instanceIOException - if an error occursdefault void skipPacket()
throws IOException
IOException - if an error occursdefault void pushMessageListener(MessageListener<M> l)
MessageListener to receive messages delivered asynchronously.l - MessageListenerdefault byte getMessageSequence()
readHeader().default void resetMessageSequence()
default MessageReader<H,M> undecorateAll()
MessageReaderdefault MessageReader<H,M> undecorate()
MessageReaderdefault void start()
default void stopAfterNextMessage()