Oracle® Coherence Java API Reference
v3.5.3

E15583-01

com.tangosol.io.nio
Class BinaryMap.Block

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.io.nio.BinaryMap.Block
Enclosing class:
BinaryMap

public class BinaryMap.Block
extends Base

A Block is the unit of storage within a Buffer. There are free blocks and Entry blocks (that store key/value pairs).


Field Summary
static int ENTRY
          State of a block that holds an Entry object's data.
static int FREE
          State of a block that is available for use.
static int MIN_ENTRY
          Minimum size of an Entry block.
static int MIN_FREE
          Minimum size of a free block.
static int MIN_SPLIT
          Minimum size of a block to split off a free block.
static int NONE
          Initial state, also state of an allocated block that has not been linked.
static int OFFSET_HASH
          Offset of the key's hash within an Entry block.
static int OFFSET_KEY
          Offset of the key data within an Entry block.
static int OFFSET_VALUE
          Offset (not counting key length) of the value data within an Entry block.
 
Constructor Summary
BinaryMap.Block()
          Construct a Block.
 
Method Summary
 void allocate(int cb)
          Allocate this free block (or at least a specified number of bytes of this block) as an Entry block.
 void clear()
          Zero the block.
 void clearValue()
          Zero the value portion of the block.
 void close()
          Close the Block object, flushing any pending changes, resetting its contents and recycling the object.
 void discard()
          Recycle the Block object, discarding any changes, resetting its contents and recycling the object.
protected  boolean finishUse()
          Decrement the use count for this block and check if it is now zero.
 void flush()
          Close the Block object by resetting its contents and recycling the object.
 void free()
          Free this Entry block.
 int getFillLength()
          Get the size of the fill in the block.
 Binary getKey()
          Get the Entry key in the block, lazy loading it if necessary.
 int getKeyHash()
          Get the hash code for the Entry block.
 int getKeyLength()
          Get the length of the Entry key in the block.
 int getLength()
          Determine the length of the block.
 int getNextBlockOffset()
          Determine the offset of the next Block in the Buffer.
 int getNextNodeOffset()
          Determine the offset of the next Block in the linked list.
 int getOffset()
          Determine the offset of this Block in the Buffer.
 int getPrevBlockOffset()
          Determine the offset of the previous Block in the Buffer.
 int getPrevNodeOffset()
          Determine the offset of the previous Block in the linked list.
 int getSizeCode()
          Determine the "free block size code" for a block of this size.
 int getType()
          Determine the current Block type.
 Binary getValue()
          Get the Entry value in the block, lazy loading it if necessary.
 int getValueLength()
          Get the length of the Entry value in the block.
 void init(int of)
          Configure the Block object to point to a specific offset within the Buffer.
 boolean isEntry()
          Determine if the Block is marked as an Entry.
 boolean isFree()
          Determine if the Block is marked as free.
 int length()
          Determine the length of the block.
 void link()
          Link this block (either an Entry or free block) into the appropriate data structures (either the hash bucket or the free list.)
 void merge()
          Merge a free block with any free blocks that it borders.
 void readHeader()
          Read a block's header data from the Buffer.
 void readKey()
          Read the "key" portion of an Entry block.
 void readValue()
          Read the "value" portion of an Entry block.
 void reset()
          Reset the Block object so that it doesn't point into the Buffer.
 void setKey(Binary bin)
          Update the Entry key in the block.
 void setNextBlockOffset(int ofBlock)
          Specify the offset of the next Block in the Buffer.
 void setNextNodeOffset(int ofBlock)
          Specify the offset of the next Block in the linked list.
 void setOffset(int ofBlock)
          Specify the offset of this Block in the Buffer.
 void setPrevBlockOffset(int ofBlock)
          Specify the offset of the previous Block in the Buffer.
 void setPrevNodeOffset(int ofBlock)
          Specify the offset of the previous Block in the linked list.
 void setType(int nType)
          Set the Block type.
 void setValue(Binary bin)
          Update the Entry value in the block.
 void split(int cbRetain)
          If possible, chop a free block into two free blocks, or chop the end of an Entry block to make a free block.
 void unlink()
          Unlink this block (either an Entry or free block) from the appropriate data structures (either the hash bucket or the free list.)
protected  void use()
          Increment the use count for this block.
 void writeHeader()
          Write the block's data to the Buffer.
 void writeKey()
          Write the "key" portion of an Entry block, including the key hash.
 void writeValue()
          Write the "value" portion of an Entry block.
 

Field Detail

NONE

public static final int NONE
Initial state, also state of an allocated block that has not been linked.

See Also:
Constant Field Values

FREE

public static final int FREE
State of a block that is available for use.

See Also:
Constant Field Values

ENTRY

public static final int ENTRY
State of a block that holds an Entry object's data.

See Also:
Constant Field Values

OFFSET_HASH

public static final int OFFSET_HASH
Offset of the key's hash within an Entry block.

See Also:
Constant Field Values

OFFSET_KEY

public static final int OFFSET_KEY
Offset of the key data within an Entry block.

See Also:
Constant Field Values

OFFSET_VALUE

public static final int OFFSET_VALUE
Offset (not counting key length) of the value data within an Entry block.

See Also:
Constant Field Values

MIN_SPLIT

public static final int MIN_SPLIT
Minimum size of a block to split off a free block.

See Also:
Constant Field Values

MIN_FREE

public static final int MIN_FREE
Minimum size of a free block.

See Also:
Constant Field Values

MIN_ENTRY

public static final int MIN_ENTRY
Minimum size of an Entry block.

See Also:
Constant Field Values
Constructor Detail

BinaryMap.Block

public BinaryMap.Block()
Construct a Block.

Method Detail

init

public void init(int of)
Configure the Block object to point to a specific offset within the Buffer.

Parameters:
of - the offset of the Block within the Buffer

use

protected void use()
Increment the use count for this block.


finishUse

protected boolean finishUse()
Decrement the use count for this block and check if it is now zero.


reset

public void reset()
Reset the Block object so that it doesn't point into the Buffer. Block objects can be re-used to reduce allocations by calling the close() method.


flush

public void flush()
Close the Block object by resetting its contents and recycling the object.


close

public void close()
Close the Block object, flushing any pending changes, resetting its contents and recycling the object.


discard

public void discard()
Recycle the Block object, discarding any changes, resetting its contents and recycling the object.


clear

public void clear()
Zero the block.


clearValue

public void clearValue()
Zero the value portion of the block.


getType

public int getType()
Determine the current Block type.

Returns:
one of {NONE, FREE, ENTRY}

setType

public void setType(int nType)
Set the Block type.

Parameters:
nType - the new Block type

isFree

public boolean isFree()
Determine if the Block is marked as free.

Returns:
true if and only if the type is FREE

isEntry

public boolean isEntry()
Determine if the Block is marked as an Entry.

Returns:
true if and only if the type is ENTRY

getOffset

public int getOffset()
Determine the offset of this Block in the Buffer.

Returns:
the offset of this Block in the Buffer, or NIL if this Block has not been initialized

setOffset

public void setOffset(int ofBlock)
Specify the offset of this Block in the Buffer.

Parameters:
ofBlock - the offset of this Block

getLength

public int getLength()
Determine the length of the block.

Returns:
the length, in bytes, of this block

length

public int length()
Determine the length of the block.

Returns:
the length, in bytes, of this block

getSizeCode

public int getSizeCode()
Determine the "free block size code" for a block of this size.

Returns:
the size code for this block

getNextBlockOffset

public int getNextBlockOffset()
Determine the offset of the next Block in the Buffer.

Returns:
the offset of the next Block in the Buffer, or NIL if this Block is the last in the Buffer

setNextBlockOffset

public void setNextBlockOffset(int ofBlock)
Specify the offset of the next Block in the Buffer.

Parameters:
ofBlock - the offset of the next contiguous Block

getPrevBlockOffset

public int getPrevBlockOffset()
Determine the offset of the previous Block in the Buffer.

Returns:
the offset of the previous Block in the Buffer, or NIL if this Block is the first in the Buffer

setPrevBlockOffset

public void setPrevBlockOffset(int ofBlock)
Specify the offset of the previous Block in the Buffer.

Parameters:
ofBlock - the offset of the previous contiguous Block

getNextNodeOffset

public int getNextNodeOffset()
Determine the offset of the next Block in the linked list.

Returns:
the offset of the next Block in the linked list, or NIL if this Block is the last in the linked list

setNextNodeOffset

public void setNextNodeOffset(int ofBlock)
Specify the offset of the next Block in the linked list.

Parameters:
ofBlock - the offset of the next Block in the linked list of Blocks

getPrevNodeOffset

public int getPrevNodeOffset()
Determine the offset of the previous Block in the linked list.

Returns:
the offset of the previous Block in the linked list, or NIL if this Block is the first in the linked list of Blocks

setPrevNodeOffset

public void setPrevNodeOffset(int ofBlock)
Specify the offset of the previous Block in the linked list.

Parameters:
ofBlock - the offset of the previous Block in the linked list of blocks

getKeyHash

public int getKeyHash()
Get the hash code for the Entry block.

Returns:
the hash code for the Entry block

getKeyLength

public int getKeyLength()
Get the length of the Entry key in the block.

Returns:
the length, in bytes, of the key

getKey

public Binary getKey()
Get the Entry key in the block, lazy loading it if necessary.

Returns:
the Entry key

setKey

public void setKey(Binary bin)
Update the Entry key in the block. The write is deferred.

Parameters:
bin - the Entry key

getValueLength

public int getValueLength()
Get the length of the Entry value in the block.

Returns:
the length, in bytes, of the value

getValue

public Binary getValue()
Get the Entry value in the block, lazy loading it if necessary.

Returns:
the Entry value

setValue

public void setValue(Binary bin)
Update the Entry value in the block. The write is deferred.

Parameters:
bin - the Entry value

getFillLength

public int getFillLength()
Get the size of the fill in the block.

Returns:
the length, in bytes, of the fill

readHeader

public void readHeader()
Read a block's header data from the Buffer. Also reads key hash, key length and value length.


writeHeader

public void writeHeader()
Write the block's data to the Buffer.


readKey

public void readKey()
Read the "key" portion of an Entry block.


writeKey

public void writeKey()
Write the "key" portion of an Entry block, including the key hash.


readValue

public void readValue()
Read the "value" portion of an Entry block. Note that if the length of the key is modified, the value must be read first or it will be unreadable.


writeValue

public void writeValue()
Write the "value" portion of an Entry block.


link

public void link()
Link this block (either an Entry or free block) into the appropriate data structures (either the hash bucket or the free list.)


unlink

public void unlink()
Unlink this block (either an Entry or free block) from the appropriate data structures (either the hash bucket or the free list.)


split

public void split(int cbRetain)
If possible, chop a free block into two free blocks, or chop the end of an Entry block to make a free block.

Parameters:
cbRetain - the number of bytes to allocate to the first of the two free blocks

merge

public void merge()
Merge a free block with any free blocks that it borders.


allocate

public void allocate(int cb)
Allocate this free block (or at least a specified number of bytes of this block) as an Entry block. Note that the block is an Entry in an unlinked state at the termination of this method.

Parameters:
cb - the minimum number of bytes required for the Entry block

free

public void free()
Free this Entry block. Note that this has the effect of closing the block.


Oracle® Coherence Java API Reference
v3.5.3

E15583-01

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