Class AsyncBinaryStore
- All Implemented Interfaces:
BinaryStore
Since the "O" portion is passed along to the wrapped BinaryStore on a separate thread, only read operations are blocking, thus the BinaryStore operations on a whole appear much faster. As such, it is somewhat analogous to a write-behind cache.
If an operation fails on the daemon thread, all further operations will occur synchronously, so that exceptions will propagate successfully up. It is assumed that once one exception occurs, the underlying BinaryStore is in a state that will cause more exceptions to occur. Even when an exception occurs on the daemon thread, that write-behind data will not be "lost" because it will still be available in the internal data structures that keeps track of pending writes.
- Since:
- Coherence 2.5
- Author:
- cp 2004.06.18
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA daemon that processes queued writes.Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriterNested classes/interfaces inherited from interface com.tangosol.io.BinaryStore
BinaryStore.KeySetAware, BinaryStore.SizeAware -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intDefault size limit for write-queued data.protected static final BinaryA special token that is used to signify a queued erase operation.protected static final ObjectSpecial key to indicate that all keys should be locked.protected static final longSpecial wait time to indicate that a lock should be blocked on until it becomes available. -
Constructor Summary
ConstructorsConstructorDescriptionAsyncBinaryStore(BinaryStore store) Construct an AsyncBinaryStore.AsyncBinaryStore(BinaryStore store, int cbMax) Construct an AsyncBinaryStore. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the store.protected AsyncBinaryStore.QueueDaemonObtain the QueueDaemon, if one already exists; otherwise, create and start one.voidRemove the specified key from the underlying store if present.voideraseAll()Remove all data from the underlying store.protected voidfinalize()Perform cleanup during garbage collection.voidIndicate the future write operations must be synchronous.Obtain the BinaryStore that this AsyncBinaryStore wraps.protected ConcurrentMapObtain the map that contains all of the pending store and erase data.protected AsyncBinaryStore.QueueDaemonintDetermine the size, in bytes, of the data that can be queued to be written asynchronously by the QueueDaemon thread.intDetermine the current number of bytes that are pending being written.protected AsyncBinaryStore.QueueDaemonFactory method: Instantiate a QueueDaemon.protected voidinternalClose(Consumer<? super BinaryStore> onClose) Close the store.booleanisAsync()Determine if the AsyncBinaryStore is operating in an asynchronous manner.keys()Iterate all keys in the underlying store.Return the value associated with the specified key, or null if the key does not have an associated value in the underlying store.protected voidsetBinaryStore(BinaryStore store) Specify the underlying BinaryStore.protected voidvoidStore the specified value under the specific key in the underlying store.toString()Return a human readable description of the AsyncBinaryStore.protected voidupdateQueuedSize(int cb) Update the number of bytes that are pending to be written.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
-
DELETED
A special token that is used to signify a queued erase operation. -
DEFAULT_LIMIT
protected static final int DEFAULT_LIMITDefault size limit for write-queued data.- See Also:
-
LOCK_ALL
Special key to indicate that all keys should be locked. -
WAIT_FOREVER
protected static final long WAIT_FOREVERSpecial wait time to indicate that a lock should be blocked on until it becomes available.- See Also:
-
-
Constructor Details
-
AsyncBinaryStore
Construct an AsyncBinaryStore. An AsyncBinaryStor wrap other BinaryStore objects to provide asynchronous write operations.The new AsyncBinaryStore will queue a maximum of 4194304 bytes (4 MB) before blocking.
- Parameters:
store- the BinaryStore to wrap
-
AsyncBinaryStore
Construct an AsyncBinaryStore. An AsyncBinaryStor wrap other BinaryStore objects to provide asynchronous write operations.- Parameters:
store- the BinaryStore to wrapcbMax- the maximum number of bytes to queue before blocking
-
-
Method Details
-
load
Return the value associated with the specified key, or null if the key does not have an associated value in the underlying store.- Specified by:
loadin interfaceBinaryStore- Parameters:
binKey- key whose associated value is to be returned- Returns:
- the value associated with the specified key, or null if no value is available for that key
-
store
Store the specified value under the specific key in the underlying store. This method is intended to support both key/value creation and value update for a specific key.- Specified by:
storein interfaceBinaryStore- Parameters:
binKey- key to store the value underbinValue- value to be stored- Throws:
UnsupportedOperationException- if this implementation or the underlying store is read-only
-
erase
Remove the specified key from the underlying store if present.- Specified by:
erasein interfaceBinaryStore- Parameters:
binKey- key whose mapping is to be removed from the map- Throws:
UnsupportedOperationException- if this implementation or the underlying store is read-only
-
eraseAll
public void eraseAll()Remove all data from the underlying store.- Specified by:
eraseAllin interfaceBinaryStore- Throws:
UnsupportedOperationException- if this implementation or the underlying store is read-only
-
keys
Iterate all keys in the underlying store.- Specified by:
keysin interfaceBinaryStore- Returns:
- a read-only iterator of the keys in the underlying store
- Throws:
UnsupportedOperationException- if the underlying store is not iterable
-
close
public void close()Close the store. -
internalClose
Close the store. The wrapped store is closed either with the optionalonCloseconsumer or by directly callingcloseon wrapped store whenonCloseconsumer is null.- Parameters:
onClose- optional close consumer to close wrappedBinaryStore
-
getBinaryStore
Obtain the BinaryStore that this AsyncBinaryStore wraps. The wrapped BinaryStore is also referred to as the "underlying" BinaryStore. All I/O operations are delegated to the underlying BinaryStore; some write operations are performed asynchronously on the QueueDaemon thread.- Returns:
- the underlying BinaryStore
-
setBinaryStore
Specify the underlying BinaryStore. When the AsyncBinaryStore is closed, it should clear out its reference to the underlying BinaryStore to indicate that it no longer is open.- Parameters:
store- the underlying BinaryStore
-
getQueuedLimit
public int getQueuedLimit()Determine the size, in bytes, of the data that can be queued to be written asynchronously by the QueueDaemon thread. Once the limit is exceeded, operations will be forced to be synchronous to avoid running out of memory or getting too far behind on the I/O operations.- Returns:
- the number of bytes allowed to be queued to be written
-
getQueuedSize
public int getQueuedSize()Determine the current number of bytes that are pending being written.- Returns:
- the number of bytes currently queued to be written
-
updateQueuedSize
protected void updateQueuedSize(int cb) Update the number of bytes that are pending to be written.- Parameters:
cb- the number of bytes that the queue length changed by
-
isAsync
public boolean isAsync()Determine if the AsyncBinaryStore is operating in an asynchronous manner.- Returns:
- true if the AsyncBinaryStore is still operating in an async mode
-
forceSync
public void forceSync()Indicate the future write operations must be synchronous. -
getPendingMap
Obtain the map that contains all of the pending store and erase data. The key of the map is a Binary key to pass to the underlying store. The corresponding value will beDELETEDto indicate an erase operation, otherwise it will be a Binary value.- Returns:
- the ConcurrentMap that keeps track of all the pending writes
-
toString
Return a human readable description of the AsyncBinaryStore. -
finalize
protected void finalize()Perform cleanup during garbage collection. -
getQueueDaemon
- Returns:
- the daemon that manages the write-behind queue
-
setQueueDaemon
- Parameters:
daemon- the daemon that manages the write-behind queue
-
ensureQueueDaemon
Obtain the QueueDaemon, if one already exists; otherwise, create and start one.- Returns:
- the daemon that manages the write-behind queue
-
instantiateQueueDaemon
Factory method: Instantiate a QueueDaemon.- Returns:
- a new QueueDaemon, but not started
-