Class AbstractMemcacheObjectEncoder<M extends MemcacheMessage>

java.lang.Object
All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Direct Known Subclasses:
AbstractBinaryMemcacheEncoder

@UnstableApi public abstract class AbstractMemcacheObjectEncoder<M extends MemcacheMessage> extends MessageToMessageEncoder<java.lang.Object>
A general purpose AbstractMemcacheObjectEncoder that encodes MemcacheMessages.

Note that this class is designed to be extended, especially because both the binary and ascii protocol require different treatment of their messages. Since the content chunk writing is the same for both, the encoder abstracts this right away.

  • Field Details

    • expectingMoreContent

      private boolean expectingMoreContent
  • Constructor Details

    • AbstractMemcacheObjectEncoder

      public AbstractMemcacheObjectEncoder()
  • Method Details

    • encode

      protected void encode(ChannelHandlerContext ctx, java.lang.Object msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
      Description copied from class: MessageToMessageEncoder
      Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.
      Specified by:
      encode in class MessageToMessageEncoder<java.lang.Object>
      Parameters:
      ctx - the ChannelHandlerContext which this MessageToMessageEncoder belongs to
      msg - the message to encode to an other one
      out - the List into which the encoded msg should be added needs to do some kind of aggregation
      Throws:
      java.lang.Exception - is thrown if an error occurs
    • acceptOutboundMessage

      public boolean acceptOutboundMessage(java.lang.Object msg) throws java.lang.Exception
      Description copied from class: MessageToMessageEncoder
      Returns true if the given message should be handled. If false it will be passed to the next ChannelOutboundHandler in the ChannelPipeline.
      Overrides:
      acceptOutboundMessage in class MessageToMessageEncoder<java.lang.Object>
      Throws:
      java.lang.Exception
    • encodeMessage

      protected abstract ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg)
      Take the given MemcacheMessage and encode it into a writable ByteBuf.
      Parameters:
      ctx - the channel handler context.
      msg - the message to encode.
      Returns:
      the ByteBuf representation of the message.
    • contentLength

      private static int contentLength(java.lang.Object msg)
      Determine the content length of the given object.
      Parameters:
      msg - the object to determine the length of.
      Returns:
      the determined content length.
    • encodeAndRetain

      private static java.lang.Object encodeAndRetain(java.lang.Object msg)
      Encode the content, depending on the object type.
      Parameters:
      msg - the object to encode.
      Returns:
      the encoded object.