Package io.netty.handler.codec.memcache
Class AbstractMemcacheObjectAggregator<H extends MemcacheMessage>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageDecoder<I>
-
- io.netty.handler.codec.MessageAggregator<MemcacheObject,H,MemcacheContent,FullMemcacheMessage>
-
- io.netty.handler.codec.memcache.AbstractMemcacheObjectAggregator<H>
-
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
- Direct Known Subclasses:
BinaryMemcacheObjectAggregator
@UnstableApi public abstract class AbstractMemcacheObjectAggregator<H extends MemcacheMessage> extends MessageAggregator<MemcacheObject,H,MemcacheContent,FullMemcacheMessage>
AChannelHandler
that aggregates anMemcacheMessage
and its followingMemcacheContent
s into a singleMemcacheMessage
with no followingMemcacheContent
s. It is useful when you don't want to take care of memcache messages where the content comes along in chunks. Insert this handler after a AbstractMemcacheObjectDecoder in theChannelPipeline
. For example, here for the binary protocol:ChannelPipeline
p = ...; ... p.addLast("decoder", newBinaryMemcacheRequestDecoder
()); p.addLast("aggregator", newBinaryMemcacheObjectAggregator
(1048576) ); ... p.addLast("encoder", newBinaryMemcacheResponseEncoder
()); p.addLast("handler", new YourMemcacheRequestHandler());
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMemcacheObjectAggregator(int maxContentLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
closeAfterContinueResponse(java.lang.Object msg)
Determine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
is written.protected boolean
ignoreContentAfterContinueResponse(java.lang.Object msg)
Determine if all objects for the current request/response should be ignored or not.protected boolean
isAggregated(MemcacheObject msg)
Returnstrue
if and only if the specified message is already aggregated.protected boolean
isContentLengthInvalid(H start, int maxContentLength)
Determine if the messagestart
's content length is known, and if it greater thanmaxContentLength
.protected boolean
isContentMessage(MemcacheObject msg)
Returnstrue
if and only if the specified message is a content message.protected boolean
isLastContentMessage(MemcacheContent msg)
Returnstrue
if and only if the specified message is the last content message.protected java.lang.Object
newContinueResponse(H start, int maxContentLength, ChannelPipeline pipeline)
Returns the 'continue response' for the specified start message if necessary.-
Methods inherited from class io.netty.handler.codec.MessageAggregator
acceptInboundMessage, aggregate, beginAggregation, channelInactive, channelReadComplete, ctx, decode, finishAggregation, handleOversizedMessage, handlerAdded, handlerRemoved, isHandlingOversizedMessage, isStartMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponents
-
Methods inherited from class io.netty.handler.codec.MessageToMessageDecoder
channelRead
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
-
-
-
Method Detail
-
isContentMessage
protected boolean isContentMessage(MemcacheObject msg) throws java.lang.Exception
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is a content message. Typically, this method is implemented as a singlereturn
statement withinstanceof
:return msg instanceof MyContentMessage;
- Specified by:
isContentMessage
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Throws:
java.lang.Exception
-
isLastContentMessage
protected boolean isLastContentMessage(MemcacheContent msg) throws java.lang.Exception
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is the last content message. Typically, this method is implemented as a singlereturn
statement withinstanceof
:return msg instanceof MyLastContentMessage;
or withinstanceof
and boolean field check:return msg instanceof MyContentMessage && msg.isLastFragment();
- Specified by:
isLastContentMessage
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Throws:
java.lang.Exception
-
isAggregated
protected boolean isAggregated(MemcacheObject msg) throws java.lang.Exception
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is already aggregated. If this method returnstrue
, this handler will simply forward the message to the next handler as-is.- Specified by:
isAggregated
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Throws:
java.lang.Exception
-
isContentLengthInvalid
protected boolean isContentLengthInvalid(H start, int maxContentLength)
Description copied from class:MessageAggregator
Determine if the messagestart
's content length is known, and if it greater thanmaxContentLength
.- Specified by:
isContentLengthInvalid
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Parameters:
start
- The message which may indicate the content length.maxContentLength
- The maximum allowed content length.- Returns:
true
if the messagestart
's content length is known, and if it greater thanmaxContentLength
.false
otherwise.
-
newContinueResponse
protected java.lang.Object newContinueResponse(H start, int maxContentLength, ChannelPipeline pipeline)
Description copied from class:MessageAggregator
Returns the 'continue response' for the specified start message if necessary. For example, this method is useful to handle an HTTP 100-continue header.- Specified by:
newContinueResponse
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Returns:
- the 'continue response', or
null
if there's no message to send
-
closeAfterContinueResponse
protected boolean closeAfterContinueResponse(java.lang.Object msg) throws java.lang.Exception
Description copied from class:MessageAggregator
Determine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
is written.- Specified by:
closeAfterContinueResponse
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Parameters:
msg
- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
.- Returns:
true
if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
is written.false
otherwise.- Throws:
java.lang.Exception
-
ignoreContentAfterContinueResponse
protected boolean ignoreContentAfterContinueResponse(java.lang.Object msg) throws java.lang.Exception
Description copied from class:MessageAggregator
Determine if all objects for the current request/response should be ignored or not. Messages will stop being ignored the next timeMessageAggregator.isContentMessage(Object)
returnstrue
.- Specified by:
ignoreContentAfterContinueResponse
in classMessageAggregator<MemcacheObject,H extends MemcacheMessage,MemcacheContent,FullMemcacheMessage>
- Parameters:
msg
- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
.- Returns:
true
if all objects for the current request/response should be ignored or not.false
otherwise.- Throws:
java.lang.Exception
-
-