Oracle® Coherence Java API Reference
v3.5.3

E15583-01

com.tangosol.io.nio
Class AbstractBufferManager

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.io.nio.AbstractBufferManager
All Implemented Interfaces:
ByteBufferManager
Direct Known Subclasses:
DirectBufferManager, MappedBufferManager

public abstract class AbstractBufferManager
extends Base
implements ByteBufferManager

Provides a basic implementation of ByteBufferManager.

Since:
Coherence 2.2
Author:
cp 2002.09.19

Constructor Summary
protected AbstractBufferManager(int cbInitial, int cbMaximum)
          Construct a AbstractBufferManager that supports a buffer of a certain initial and maximum size.
 
Method Summary
protected abstract  void allocateBuffer()
          Allocate a new buffer, copying old data if there is any.
protected  void calibrate()
          Determine the grow and shrink thresholds based on the current capacity.
 java.nio.ByteBuffer getBuffer()
          Get the current ByteBuffer reference.
 int getCapacity()
          Get the capacity of the current ByteBuffer.
 int getGrowthThreshold()
          Determine the level (what number of bytes used) above which the current ByteBuffer will need to be "resized" upwards.
 int getMaxCapacity()
          Determine the maximum size that the managed buffer can reach.
protected  int getMaxIncrement()
           
 int getMinCapacity()
          Determine the minimum size that the managed buffer can reach.
 int getShrinkageThreshold()
          Determine the level (what number of bytes used) below which the current ByteBuffer will need to be "resized" downwards.
 void grow(int cbRequired)
          Request that the buffer be grown based on the number of bytes currently required.
protected  void setBuffer(java.nio.ByteBuffer buffer)
          Set the current ByteBuffer reference.
protected  void setCapacity(int cb)
          Set the capacity of the current ByteBuffer.
protected  void setGrowthThreshold(int cb)
          Specify the level (what number of bytes used) above which the current ByteBuffer will need to be "resized" upwards.
protected  void setMaxCapacity(int cb)
          Specify the maximum size that the managed buffer can reach.
protected  void setMinCapacity(int cb)
          Specify the minimum size that the managed buffer can reach.
protected  void setShrinkageThreshold(int cb)
          Specify the level (what number of bytes used) below which the current ByteBuffer will need to be "resized" downwards.
 void shrink(int cbRequired)
          Request that the buffer be shrunk based on the number of bytes currently required.
 

Constructor Detail

AbstractBufferManager

protected AbstractBufferManager(int cbInitial,
                                int cbMaximum)
Construct a AbstractBufferManager that supports a buffer of a certain initial and maximum size.

Parameters:
cbInitial - the initial size
cbMaximum - the maximum size
Method Detail

getBuffer

public java.nio.ByteBuffer getBuffer()
Get the current ByteBuffer reference.

Specified by:
getBuffer in interface ByteBufferManager
Returns:
the current ByteBuffer

setBuffer

protected void setBuffer(java.nio.ByteBuffer buffer)
Set the current ByteBuffer reference.

Parameters:
buffer - the current ByteBuffer

getCapacity

public int getCapacity()
Get the capacity of the current ByteBuffer. This is the same as getBuffer().capacity().

Specified by:
getCapacity in interface ByteBufferManager
Returns:
the capacity of the current ByteBuffer

setCapacity

protected void setCapacity(int cb)
Set the capacity of the current ByteBuffer. This does not actually allocate a new buffer.

Parameters:
cb - the capacity of the managed ByteBuffer

getGrowthThreshold

public int getGrowthThreshold()
Determine the level (what number of bytes used) above which the current ByteBuffer will need to be "resized" upwards. Returns Integer.MAX_VALUE if the buffer cannot be resized upwards.

Specified by:
getGrowthThreshold in interface ByteBufferManager
Returns:
the number of bytes that, when the number of used bytes exceeds it, the ByteBuffer will need to grow

setGrowthThreshold

protected void setGrowthThreshold(int cb)
Specify the level (what number of bytes used) above which the current ByteBuffer will need to be "resized" upwards.

Parameters:
cb - the number of bytes that, when the number of used bytes exceeds it, the ByteBuffer will need to grow

getShrinkageThreshold

public int getShrinkageThreshold()
Determine the level (what number of bytes used) below which the current ByteBuffer will need to be "resized" downwards. Returns 0 if the buffer cannot be resized downwards.

Specified by:
getShrinkageThreshold in interface ByteBufferManager
Returns:
the number of bytes that, when the number of used bytes drops below it, the ByteBuffer will need to shrink

setShrinkageThreshold

protected void setShrinkageThreshold(int cb)
Specify the level (what number of bytes used) below which the current ByteBuffer will need to be "resized" downwards. Specify 0 if the buffer cannot be resized downwards.

Parameters:
cb - the number of bytes that, when the number of used bytes drops below it, the ByteBuffer will need to shrink

getMinCapacity

public int getMinCapacity()
Determine the minimum size that the managed buffer can reach. If the buffer is already at its minimum, then this method will return the same value as getCapacity.

Specified by:
getMinCapacity in interface ByteBufferManager
Returns:
minimum size for the managed buffer

setMinCapacity

protected void setMinCapacity(int cb)
Specify the minimum size that the managed buffer can reach.

Parameters:
cb - minimum size for the managed buffer

getMaxCapacity

public int getMaxCapacity()
Determine the maximum size that the managed buffer can reach. If the buffer is already at its maximum, then this method will return the same value as getCapacity.

Specified by:
getMaxCapacity in interface ByteBufferManager
Returns:
maximum size for the managed buffer

setMaxCapacity

protected void setMaxCapacity(int cb)
Specify the maximum size that the managed buffer can reach.

Parameters:
cb - maximum size for the managed buffer

getMaxIncrement

protected int getMaxIncrement()
Returns:
maximum size to grow in one step

grow

public void grow(int cbRequired)
Request that the buffer be grown based on the number of bytes currently required.

Specified by:
grow in interface ByteBufferManager
Parameters:
cbRequired - the number of bytes that are needed by the requesting operation

shrink

public void shrink(int cbRequired)
Request that the buffer be shrunk based on the number of bytes currently required.

Specified by:
shrink in interface ByteBufferManager
Parameters:
cbRequired - the number of contiguous bytes in the buffer, starting from offset 0, that are actually in use

calibrate

protected void calibrate()
Determine the grow and shrink thresholds based on the current capacity.


allocateBuffer

protected abstract void allocateBuffer()
Allocate a new buffer, copying old data if there is any.


Oracle® Coherence Java API Reference
v3.5.3

E15583-01

Copyright © 2000, 2010, Oracle. All rights reserved.