Package com.tangosol.io.nio
Class BinaryMap.Block
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.io.nio.BinaryMap.Block
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description 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
Constructors Constructor Description Block()
Construct a Block.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
-
-
-
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
-
-
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.
-
-