public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) {
// If the message is not a ChannelBuffer, hello ClassCastException !
ChannelBuffer cb = (ChannelBuffer)e.getMessage();
// Check to see if we already removed the handler
boolean pipelineContainsCompressor = ctx.getPipeline().getContext(nameOfCompressionHandler)!=null;
if(cb.readableBytes()<sizeThreshold) {
if(pipelineContainsCompressor) {
// The payload is too small to be compressed but the pipeline contains the compression handler
// so we need to remove it.
compressionHandler = ctx.getPipeline().remove(nameOfCompressionHandler);
}