Infinispan Server - Core Components 5.1.4.FINAL-redhat-1

org.infinispan.server.core.transport
Class CustomReplayingDecoder<T extends Enum<T>>

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelUpstreamHandler
      extended by org.infinispan.server.core.transport.CustomReplayingDecoder<T>
All Implemented Interfaces:
org.jboss.netty.channel.ChannelHandler, org.jboss.netty.channel.ChannelUpstreamHandler

public abstract class CustomReplayingDecoder<T extends Enum<T>>
extends org.jboss.netty.channel.SimpleChannelUpstreamHandler

A fork version of ReplayingDecoder whose cumulation buffer can be cleared when the request is completed. This helps keep memory consumption low particularly when big objects are stored in Infinispan. To be more precise, the differences between the ReplayingDecoder version in Netty 3.2.4 (code here) and this one are:

This replaying decoder should be removed once Netty has been upgraded to version 4.0, when buffer pooling will avoid unlimited buffer growth.

Since:
5.1
Author:
Galder ZamarreƱo

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
org.jboss.netty.channel.ChannelHandler.Sharable
 
Constructor Summary
protected CustomReplayingDecoder(T initialState, boolean unfold, int maxCapacity)
           
 
Method Summary
protected  int actualReadableBytes()
          Returns the actual number of readable bytes in the internal cumulative buffer of this decoder.
 void channelClosed(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ChannelStateEvent e)
           
 void channelDisconnected(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ChannelStateEvent e)
           
protected  void checkpoint()
          Stores the internal cumulative buffer's reader position.
protected  void checkpoint(T state)
          Stores the internal cumulative buffer's reader position and updates the current decoder state.
protected abstract  Object decode(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.Channel channel, org.jboss.netty.buffer.ChannelBuffer buffer, T state)
          Decodes the received packets so far into a frame.
protected  Object decodeLast(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.Channel channel, org.jboss.netty.buffer.ChannelBuffer buffer, T state)
          Decodes the received data so far into a frame when the channel is disconnected.
 void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ExceptionEvent e)
           
protected  T getState()
          Returns the current state of this decoder.
protected  org.jboss.netty.buffer.ChannelBuffer internalBuffer()
          Returns the internal cumulative buffer of this decoder.
 void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.MessageEvent e)
           
protected  T setState(T newState)
          Sets the current state of this decoder.
protected  void slimDownBuffer()
          Slim down internal buffer if it exceeds the limit established on creation
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelConnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, writeComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomReplayingDecoder

protected CustomReplayingDecoder(T initialState,
                                 boolean unfold,
                                 int maxCapacity)
Method Detail

checkpoint

protected void checkpoint()
Stores the internal cumulative buffer's reader position.


checkpoint

protected void checkpoint(T state)
Stores the internal cumulative buffer's reader position and updates the current decoder state.


getState

protected T getState()
Returns the current state of this decoder.

Returns:
the current state of this decoder

setState

protected T setState(T newState)
Sets the current state of this decoder.

Returns:
the old state of this decoder

actualReadableBytes

protected int actualReadableBytes()
Returns the actual number of readable bytes in the internal cumulative buffer of this decoder. You usually do not need to rely on this value to write a decoder. Use it only when you muse use it at your own risk. This method is a shortcut to internalBuffer().readableBytes().


internalBuffer

protected org.jboss.netty.buffer.ChannelBuffer internalBuffer()
Returns the internal cumulative buffer of this decoder. You usually do not need to access the internal buffer directly to write a decoder. Use it only when you must use it at your own risk.


decode

protected abstract Object decode(org.jboss.netty.channel.ChannelHandlerContext ctx,
                                 org.jboss.netty.channel.Channel channel,
                                 org.jboss.netty.buffer.ChannelBuffer buffer,
                                 T state)
                          throws Exception
Decodes the received packets so far into a frame.

Parameters:
ctx - the context of this handler
channel - the current channel
buffer - the cumulative buffer of received packets so far. Note that the buffer might be empty, which means you should not make an assumption that the buffer contains at least one byte in your decoder implementation.
state - the current decoder state (null if unused)
Returns:
the decoded frame
Throws:
Exception

decodeLast

protected Object decodeLast(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.Channel channel,
                            org.jboss.netty.buffer.ChannelBuffer buffer,
                            T state)
                     throws Exception
Decodes the received data so far into a frame when the channel is disconnected.

Parameters:
ctx - the context of this handler
channel - the current channel
buffer - the cumulative buffer of received packets so far. Note that the buffer might be empty, which means you should not make an assumption that the buffer contains at least one byte in your decoder implementation.
state - the current decoder state (null if unused)
Returns:
the decoded frame
Throws:
Exception

slimDownBuffer

protected void slimDownBuffer()
Slim down internal buffer if it exceeds the limit established on creation


messageReceived

public void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.MessageEvent e)
                     throws Exception
Overrides:
messageReceived in class org.jboss.netty.channel.SimpleChannelUpstreamHandler
Throws:
Exception

channelDisconnected

public void channelDisconnected(org.jboss.netty.channel.ChannelHandlerContext ctx,
                                org.jboss.netty.channel.ChannelStateEvent e)
                         throws Exception
Overrides:
channelDisconnected in class org.jboss.netty.channel.SimpleChannelUpstreamHandler
Throws:
Exception

channelClosed

public void channelClosed(org.jboss.netty.channel.ChannelHandlerContext ctx,
                          org.jboss.netty.channel.ChannelStateEvent e)
                   throws Exception
Overrides:
channelClosed in class org.jboss.netty.channel.SimpleChannelUpstreamHandler
Throws:
Exception

exceptionCaught

public void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.ExceptionEvent e)
                     throws Exception
Overrides:
exceptionCaught in class org.jboss.netty.channel.SimpleChannelUpstreamHandler
Throws:
Exception

Infinispan Server - Core Components 5.1.4.FINAL-redhat-1

Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.