java.lang.Object
convex.net.MessageReceiver
Class responsible for buffered accumulation of data received over a single connection.
Data received must be passed in via @receiveFromChannel
Passes any successfully received Messages 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
ConstructorsConstructorDescriptionMessageReceiver
(Consumer<Message> receiveAction, Predicate<Message> returnHandler) -
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
-
INITIAL_RECEIVE_BUFFER_SIZE
public static final int INITIAL_RECEIVE_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
MessageReceiver
-
-
Method Details
-
getReceivedCount
public long getReceivedCount()Get the number of messages received in total by this Receiver- Returns:
- Count of messages received
-
receiveFromChannel
public int receiveFromChannel(ReadableByteChannel chan) throws BadFormatException, convex.net.impl.HandlerException, IOException 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 receivedconvex.net.impl.HandlerException
- If the message handler throws an unexpected Exception
-
setHook
Sets an optional additional message receiver hook (for debugging / observability purposes)- Parameters:
hook
- Hook to call when a message is received
-