rabbit.io
Class CachingBufferHandler

java.lang.Object
  extended by rabbit.io.CachingBufferHandler
All Implemented Interfaces:
BufferHandler

public class CachingBufferHandler
extends java.lang.Object
implements BufferHandler

A ByteBuffer handler that keeps re uses returned buffers. This class uses no synchronization. This class only allocates direct buffers.

Author:
Robert Olofsson

Constructor Summary
CachingBufferHandler()
           
 
Method Summary
 java.nio.ByteBuffer getBuffer()
          Get a byte buffer of reasonable size, the buffer will have been cleared.
 java.nio.ByteBuffer growBuffer(java.nio.ByteBuffer buffer)
          Get a larger buffer with the same contents as buffer, this will also return buffer to the pool.
 boolean isLarge(java.nio.ByteBuffer buffer)
          Check if the given buffer is a large buffer
 void putBuffer(java.nio.ByteBuffer buffer)
          Return a buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingBufferHandler

public CachingBufferHandler()
Method Detail

getBuffer

public java.nio.ByteBuffer getBuffer()
Description copied from interface: BufferHandler
Get a byte buffer of reasonable size, the buffer will have been cleared.

Specified by:
getBuffer in interface BufferHandler
Returns:
a ByteBuffer

putBuffer

public void putBuffer(java.nio.ByteBuffer buffer)
Description copied from interface: BufferHandler
Return a buffer.

Specified by:
putBuffer in interface BufferHandler
Parameters:
buffer - the ByteBuffer to return to the cache

growBuffer

public java.nio.ByteBuffer growBuffer(java.nio.ByteBuffer buffer)
Description copied from interface: BufferHandler
Get a larger buffer with the same contents as buffer, this will also return buffer to the pool.

Specified by:
growBuffer in interface BufferHandler
Parameters:
buffer - an existing buffer, the contents will be copied into the new larger buffer. May be null.
Returns:
the new larger buffer

isLarge

public boolean isLarge(java.nio.ByteBuffer buffer)
Description copied from interface: BufferHandler
Check if the given buffer is a large buffer

Specified by:
isLarge in interface BufferHandler
Parameters:
buffer - the ByteBuffer to check
Returns:
true if the given buffer is large