private void handleSnappyCompression ( final ChannelHandlerContext ctx , final BinaryMemcacheRequest r ) { if ( ! ( r instanceof FullBinaryMemcacheRequest ) ) { // we only need to handle requests which send content return ; } FullBinaryMemcacheRequest request = ( FullBinaryMemcacheRequest ) r ; int uncompressedLength = request . content ( ) . readableBytes ( ) ; // don't bother compressing if below the min compression size if ( uncompressedLength < minCompressionSize || uncompressedLength == 0 ) { return ; } ByteBuf compressedContent ; try { compressedContent = tryCompress ( request . content ( ) ) ; } catch ( Exception ex ) { throw new RuntimeException ( "Could not snappy-compress value." , ex ) ; } if ( compressedContent != null ) { // compressed is smaller, so adapt and apply new content request . setDataType ( ( byte ) ( request . getDataType ( ) | DATATYPE_SNAPPY ) ) ; request . setContent ( compressedContent ) ; request . setTotalBodyLength ( request . getExtrasLength ( ) + request . getKeyLength ( ) + compressedContent . readableBytes ( ) ) ; } }
Helper method which performs snappy compression on the request path .