rabbit.io
Class CacheBufferHandle

java.lang.Object
  extended by rabbit.io.CacheBufferHandle
All Implemented Interfaces:
BufferHandle

public class CacheBufferHandle
extends Object
implements BufferHandle

A handle to a ByteBuffer that uses a buffer handler

Author:
Robert Olofsson

Constructor Summary
CacheBufferHandle(BufferHandler bh)
          Create a new CacheBufferHandle that uses the given BufferHandler for the caching of the ByteBuffer:s
 
Method Summary
 ByteBuffer getBuffer()
          Get a byte buffer of reasonable size, the buffer will have been cleared.
 ByteBuffer getLargeBuffer()
          Get a byte buffer of reasonable size, the buffer will have been cleared.
 boolean isEmpty()
          Check if this handle is empty, that is if no buffer exists or the buffer is empty.
 boolean isLarge(ByteBuffer buffer)
          Check if the given buffer is a large buffer
 void possiblyFlush()
          release a buffer if possible.
 void setMayBeFlushed(boolean mayBeFlushed)
          Flag that the internal ByteBuffer may not be flushed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheBufferHandle

public CacheBufferHandle(BufferHandler bh)
Create a new CacheBufferHandle that uses the given BufferHandler for the caching of the ByteBuffer:s

Parameters:
bh - the BufferHandler that is the actual cache
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: BufferHandle
Check if this handle is empty, that is if no buffer exists or the buffer is empty.

Specified by:
isEmpty in interface BufferHandle
Returns:
true if the buffer currently is empty

getBuffer

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

Specified by:
getBuffer in interface BufferHandle
Returns:
the actual ByteBuffer

getLargeBuffer

public ByteBuffer getLargeBuffer()
Description copied from interface: BufferHandle
Get a byte buffer of reasonable size, the buffer will have been cleared.

Specified by:
getLargeBuffer in interface BufferHandle
Returns:
the large buffer to use

isLarge

public boolean isLarge(ByteBuffer buffer)
Description copied from interface: BufferHandle
Check if the given buffer is a large buffer

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

possiblyFlush

public void possiblyFlush()
Description copied from interface: BufferHandle
release a buffer if possible.

Specified by:
possiblyFlush in interface BufferHandle

setMayBeFlushed

public void setMayBeFlushed(boolean mayBeFlushed)
Description copied from interface: BufferHandle
Flag that the internal ByteBuffer may not be flushed.

Specified by:
setMayBeFlushed in interface BufferHandle
Parameters:
mayBeFlushed - if true the buffer may be returned, if false the putBuffer call will throw an exception

toString

public String toString()
Overrides:
toString in class Object