Package com.tangosol.io.nio
Class BinaryMap.Block
java.lang.Object
com.tangosol.util.Base
com.tangosol.io.nio.BinaryMap.Block
- Enclosing class:
BinaryMap
A Block is the unit of storage within a Buffer. There are free blocks
and Entry blocks (that store key/value pairs).
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
State of a block that holds an Entry object's data.static final int
State of a block that is available for use.static final int
Minimum size of an Entry block.static final int
Minimum size of a free block.static final int
Minimum size of a block to split off a free block.static final int
Initial state, also state of an allocated block that has not been linked.static final int
Offset of the key's hash within an Entry block.static final int
Offset of the key data within an Entry block.static final int
Offset (not counting key length) of the value data within an Entry block. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
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
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
Get the size of the fill in the block.getKey()
Get the Entry key in the block, lazy loading it if necessary.int
Get the hash code for the Entry block.int
Get the length of the Entry key in the block.int
Determine the length of the block.int
Determine the offset of the next Block in the Buffer.int
Determine the offset of the next Block in the linked list.int
Determine the offset of this Block in the Buffer.int
Determine the offset of the previous Block in the Buffer.int
Determine the offset of the previous Block in the linked list.int
Determine the "free block size code" for a block of this size.int
getType()
Determine the current Block type.getValue()
Get the Entry value in the block, lazy loading it if necessary.int
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
Read a block's header data from the Buffer.void
readKey()
Read the "key" portion of an Entry block.void
Read the "value" portion of an Entry block.void
reset()
Reset the Block object so that it doesn't point into the Buffer.void
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
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
Write the block's data to the Buffer.void
writeKey()
Write the "key" portion of an Entry block, including the key hash.void
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 Details
-
NONE
public static final int NONEInitial state, also state of an allocated block that has not been linked.- See Also:
-
FREE
public static final int FREEState of a block that is available for use.- See Also:
-
ENTRY
public static final int ENTRYState of a block that holds an Entry object's data.- See Also:
-
OFFSET_HASH
public static final int OFFSET_HASHOffset of the key's hash within an Entry block.- See Also:
-
OFFSET_KEY
public static final int OFFSET_KEYOffset of the key data within an Entry block.- See Also:
-
OFFSET_VALUE
public static final int OFFSET_VALUEOffset (not counting key length) of the value data within an Entry block.- See Also:
-
MIN_SPLIT
public static final int MIN_SPLITMinimum size of a block to split off a free block.- See Also:
-
MIN_FREE
public static final int MIN_FREEMinimum size of a free block.- See Also:
-
MIN_ENTRY
public static final int MIN_ENTRYMinimum size of an Entry block.- See Also:
-
-
Constructor Details
-
Block
public Block()Construct a Block.
-
-
Method Details
-
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
Get the Entry key in the block, lazy loading it if necessary.- Returns:
- the Entry key
-
setKey
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
Get the Entry value in the block, lazy loading it if necessary.- Returns:
- the Entry value
-
setValue
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.
-