com.sun.grizzly.memory.slab
Class SlabByteBufferWrapper

java.lang.Object
  extended by com.sun.grizzly.memory.ByteBufferWrapper
      extended by com.sun.grizzly.memory.slab.SlabByteBufferWrapper
All Implemented Interfaces:
Buffer<ByteBuffer>, Comparable<Buffer<ByteBuffer>>

public class SlabByteBufferWrapper
extends ByteBufferWrapper

The SlabByteBufferWrapper knows both the MemoryManager and the slab used to allocate it. Both are needed in the BufferWrapper.trim() and BufferWrapper.dispose() methods: trim() is used to allocate a buffer as large as the free space in a slab for reading, so that very large reads can be made efficiently. After reading the data, trim() is called in order to reduce the space needed to the actual data read. This works best in the case where a slab is used by a single reader thread, which is the expected mode of use. dispose() is used to release a buffer once the stream is done with it (directly from the Reader, most likely as part of the BufferHandler in the Writer). Here both the allocator and the slab are needed: the slab tracks whether or not all of its allocated space has been freed, and the allocator (in the pool case by delegating to the SlabPoolImpl) tracks empty, partial and full slabs for recycling memory.

Author:
Ken Cavanaugh, John Vieten

Field Summary
 
Fields inherited from class com.sun.grizzly.memory.ByteBufferWrapper
DEBUG_MODE, memoryManager, visible
 
Constructor Summary
SlabByteBufferWrapper(ByteBufferManager allocator, Slab slab, int size)
          Allocate a buffer that contains dataSize data.
 
Method Summary
 void dispose()
          Notify the allocator that the space for this BufferWrapper is no longer needed.
 String toString()
           
 void trim()
          Trim the buffer by reducing capacity to position, if possible.
 
Methods inherited from class com.sun.grizzly.memory.ByteBufferWrapper
asReadOnlyBuffer, capacity, clear, compact, compareTo, contentAsString, duplicate, equals, flip, get, get, get, get, getChar, getChar, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, hashCode, hasRemaining, isReadOnly, limit, limit, mark, order, order, position, position, prepend, put, put, put, put, put, putChar, putChar, putDouble, putDouble, putFloat, putFloat, putInt, putInt, putLong, putLong, putShort, putShort, remaining, reset, rewind, slice, underlying
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SlabByteBufferWrapper

public SlabByteBufferWrapper(ByteBufferManager allocator,
                             Slab slab,
                             int size)
Allocate a buffer that contains dataSize data.

Method Detail

trim

public void trim()
Trim the buffer by reducing capacity to position, if possible. May return without changing capacity. Also resets the position to 0, like reset().

Specified by:
trim in interface Buffer<ByteBuffer>
Overrides:
trim in class ByteBufferWrapper

dispose

public void dispose()
Notify the allocator that the space for this BufferWrapper is no longer needed. All calls to methods on a BufferWrapper will fail after a call to dispose().

Specified by:
dispose in interface Buffer<ByteBuffer>
Overrides:
dispose in class ByteBufferWrapper

toString

public String toString()
Overrides:
toString in class ByteBufferWrapper


Copyright © 2009 SUN Microsystems. All Rights Reserved.