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 intENTRYState of a block that holds an Entry object's data.static intFREEState of a block that is available for use.static intMIN_ENTRYMinimum size of an Entry block.static intMIN_FREEMinimum size of a free block.static intMIN_SPLITMinimum size of a block to split off a free block.static intNONEInitial state, also state of an allocated block that has not been linked.static intOFFSET_HASHOffset of the key's hash within an Entry block.static intOFFSET_KEYOffset of the key data within an Entry block.static intOFFSET_VALUEOffset (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 voidallocate(int cb)Allocate this free block (or at least a specified number of bytes of this block) as an Entry block.voidclear()Zero the block.voidclearValue()Zero the value portion of the block.voidclose()Close the Block object, flushing any pending changes, resetting its contents and recycling the object.voiddiscard()Recycle the Block object, discarding any changes, resetting its contents and recycling the object.protected booleanfinishUse()Decrement the use count for this block and check if it is now zero.voidflush()Close the Block object by resetting its contents and recycling the object.voidfree()Free this Entry block.intgetFillLength()Get the size of the fill in the block.BinarygetKey()Get the Entry key in the block, lazy loading it if necessary.intgetKeyHash()Get the hash code for the Entry block.intgetKeyLength()Get the length of the Entry key in the block.intgetLength()Determine the length of the block.intgetNextBlockOffset()Determine the offset of the next Block in the Buffer.intgetNextNodeOffset()Determine the offset of the next Block in the linked list.intgetOffset()Determine the offset of this Block in the Buffer.intgetPrevBlockOffset()Determine the offset of the previous Block in the Buffer.intgetPrevNodeOffset()Determine the offset of the previous Block in the linked list.intgetSizeCode()Determine the "free block size code" for a block of this size.intgetType()Determine the current Block type.BinarygetValue()Get the Entry value in the block, lazy loading it if necessary.intgetValueLength()Get the length of the Entry value in the block.voidinit(int of)Configure the Block object to point to a specific offset within the Buffer.booleanisEntry()Determine if the Block is marked as an Entry.booleanisFree()Determine if the Block is marked as free.intlength()Determine the length of the block.voidlink()Link this block (either an Entry or free block) into the appropriate data structures (either the hash bucket or the free list.)voidmerge()Merge a free block with any free blocks that it borders.voidreadHeader()Read a block's header data from the Buffer.voidreadKey()Read the "key" portion of an Entry block.voidreadValue()Read the "value" portion of an Entry block.voidreset()Reset the Block object so that it doesn't point into the Buffer.voidsetKey(Binary bin)Update the Entry key in the block.voidsetNextBlockOffset(int ofBlock)Specify the offset of the next Block in the Buffer.voidsetNextNodeOffset(int ofBlock)Specify the offset of the next Block in the linked list.voidsetOffset(int ofBlock)Specify the offset of this Block in the Buffer.voidsetPrevBlockOffset(int ofBlock)Specify the offset of the previous Block in the Buffer.voidsetPrevNodeOffset(int ofBlock)Specify the offset of the previous Block in the linked list.voidsetType(int nType)Set the Block type.voidsetValue(Binary bin)Update the Entry value in the block.voidsplit(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.voidunlink()Unlink this block (either an Entry or free block) from the appropriate data structures (either the hash bucket or the free list.)protected voiduse()Increment the use count for this block.voidwriteHeader()Write the block's data to the Buffer.voidwriteKey()Write the "key" portion of an Entry block, including the key hash.voidwriteValue()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.
-
-