public class CQLMessageHandler<M extends Message> extends AbstractMessageHandler
AbstractMessageHandler for processing CQL messages which comprise a Message wrapped
in an Envelope. This class is parameterized by a Message subtype, expected to be either
Message.Request or Message.Response. Most commonly, an instance for handling Message.Request
is created for each inbound CQL client connection.
# Small vs large messages
Small messages are deserialized in place, and then handed off to a consumer for processing.
Large messages accumulate frames until all bytes for the envelope are received, then concatenate and deserialize the
frames on the event loop thread and pass them on to the same consumer.
# Flow control (backpressure)
The size of an incoming message is explicit in the Envelope.Header.
By default, every connection has 1MiB of exlusive permits available before needing to access the per-endpoint
and global reserves. By default, those reserves are sized proportionally to the heap - 2.5% of heap per-endpoint
and a 10% for the global reserve.
Permits are held while CQL messages are processed and released after the response has been encoded into the
buffers of the response frame.
A connection level option (THROW_ON_OVERLOAD) allows clients to choose the backpressure strategy when a connection
has exceeded the maximum number of allowed permits. The choices are to either pause reads from the incoming socket
and allow TCP backpressure to do the work, or to throw an explict exception and rely on the client to back off.AbstractMessageHandler.OnHandlerClosed, AbstractMessageHandler.WaitQueue| Modifier and Type | Field and Description |
|---|---|
static int |
LARGE_MESSAGE_THRESHOLD |
channel, corruptFramesRecovered, corruptFramesUnrecovered, decoder, endpointReserveCapacity, endpointWaitQueue, globalReserveCapacity, globalWaitQueue, largeMessage, largeThreshold, onClosed, queueCapacity, receivedBytes, receivedCount, throttledCount, throttledNanos| Modifier and Type | Method and Description |
|---|---|
protected void |
fatalExceptionCaught(java.lang.Throwable cause) |
protected java.lang.String |
id() |
boolean |
process(FrameDecoder.Frame frame)
Frame processor that the frames should be handed off to.
|
protected void |
processCorruptFrame(FrameDecoder.CorruptFrame frame) |
protected boolean |
processFirstFrameOfLargeMessage(FrameDecoder.IntactFrame frame,
ResourceLimits.Limit endpointReserve,
ResourceLimits.Limit globalReserve) |
protected boolean |
processOneContainedMessage(ShareableBytes bytes,
ResourceLimits.Limit endpointReserve,
ResourceLimits.Limit globalReserve) |
protected boolean |
processRequest(Envelope request) |
acquireCapacity, acquireCapacity, channelInactive, channelRead, handlerAdded, processSubsequentFrameOfLargeMessage, releaseCapacity, releaseProcessedCapacitychannelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerRemoved, isSharablepublic static final int LARGE_MESSAGE_THRESHOLD
public boolean process(FrameDecoder.Frame frame) throws java.io.IOException
FrameDecoder.FrameProcessorprocess in interface FrameDecoder.FrameProcessorprocess in class AbstractMessageHandlerjava.io.IOExceptionprotected boolean processOneContainedMessage(ShareableBytes bytes, ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve)
processOneContainedMessage in class AbstractMessageHandlerprotected boolean processRequest(Envelope request)
protected boolean processFirstFrameOfLargeMessage(FrameDecoder.IntactFrame frame, ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve) throws java.io.IOException
processFirstFrameOfLargeMessage in class AbstractMessageHandlerjava.io.IOExceptionprotected java.lang.String id()
id in class AbstractMessageHandlerprotected void processCorruptFrame(FrameDecoder.CorruptFrame frame)
processCorruptFrame in class AbstractMessageHandlerprotected void fatalExceptionCaught(java.lang.Throwable cause)
fatalExceptionCaught in class AbstractMessageHandlerCopyright © 2009-2022 The Apache Software Foundation