Package convex.net
Class MessageReceiver
java.lang.Object
convex.net.MessageReceiver
Class responsible for buffered accumulation of data received over a connection.
ByteBuffers received must be passed in via @receiveFromChannel
Passes any successfully received objects to a specified Consumer, using the same thread on which the
MessageReceiver was called.
"There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery"
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Get the number of messages received in total by this Receiverint
Handles receipt of bytes from a channel.void
Sets an optional additional message receiver hook (for debugging / observability purposes)
-
Field Details
-
RECEIVE_BUFFER_SIZE
public static final int RECEIVE_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
MessageReceiver
-
-
Method Details
-
getReceiceAction
-
getReceivedCount
public long getReceivedCount()Get the number of messages received in total by this Receiver- Returns:
- Count of messages received
-
receiveFromChannel
Handles receipt of bytes from a channel. Should be called with a ReadableByteChannel containing bytes received. May be called multiple times during receipt of a single message, i.e. can handle partial message receipt. Will consume enough bytes from channel to handle exactly one message. Bytes will be left unconsumed on the channel if more are available. This hopefully creates sufficient backpressure on clients sending a lot of messages.- Parameters:
chan
- Byte channel- Returns:
- The number of bytes read from the channel, or -1 if EOS
- Throws:
IOException
- If IO error occursBadFormatException
- If a bad encoding is received
-
setHook
Sets an optional additional message receiver hook (for debugging / observability purposes)- Parameters:
hook
- Hook to call when a message is received
-