Skip to content

Commit

Permalink
Make ReplayingDecoder.newCumulationBuffer() overridable / Make Replay…
Browse files Browse the repository at this point in the history
…ing|FrameDecoder allocate at least 256 bytes by default
  • Loading branch information
trustin committed Feb 29, 2012
1 parent c465932 commit 689c479
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,6 @@ protected ChannelBuffer newCumulationBuffer(
ChannelHandlerContext ctx, int minimumCapacity) {
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
return ChannelBuffers.dynamicBuffer(
factory.getDefaultOrder(), minimumCapacity, factory);
factory.getDefaultOrder(), Math.max(minimumCapacity, 256), factory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.SocketAddress;

import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBufferFactory;
import io.netty.buffer.ChannelBuffers;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
Expand Down Expand Up @@ -596,9 +597,19 @@ private void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
}
}

private ChannelBuffer newCumulationBuffer(
/**
* Create a new {@link ChannelBuffer} which is used for the cumulation.
* Be aware that this MUST be a dynamic buffer. Sub-classes may override
* this to provide a dynamic {@link ChannelBuffer} which has some
* pre-allocated size that better fit their need.
*
* @param ctx {@link ChannelHandlerContext} for this handler
* @return buffer the {@link ChannelBuffer} which is used for cumulation
*/
protected ChannelBuffer newCumulationBuffer(
ChannelHandlerContext ctx, int minimumCapacity) {
return new UnsafeDynamicChannelBuffer(
ctx.getChannel().getConfig().getBufferFactory(), minimumCapacity);
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
return ChannelBuffers.dynamicBuffer(
factory.getDefaultOrder(), Math.max(minimumCapacity, 256), factory);
}
}

This file was deleted.

0 comments on commit 689c479

Please sign in to comment.