Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.1.0

E18814-01


com.tangosol.io
Class AsyncBinaryStore

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.io.AsyncBinaryStore

All Implemented Interfaces:
BinaryStore

public class AsyncBinaryStore
extends Base
implements BinaryStore

An AsyncBinaryStore is a BinaryStore wrapper that performs the "O" (output) portion of its I/O asynchronously on a daemon thread. The output portion consists of store and erase processing.

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
protected  class AsyncBinaryStore.QueueDaemon
          A daemon that processes queued writes.

 

Field Summary
protected static int DEFAULT_LIMIT
          Default size limit for write-queued data.
protected static Binary DELETED
          A special token that is used to signify a queued erase operation.
protected static java.lang.Object LOCK_ALL
          Special key to indicate that all keys should be locked.
protected static long WAIT_FOREVER
          Special wait time to indicate that a lock should be blocked on until it becomes available.

 

Constructor Summary
AsyncBinaryStore(BinaryStore store)
          Construct an AsyncBinaryStore.
AsyncBinaryStore(BinaryStore store, int cbMax)
          Construct an AsyncBinaryStore.

 

Method Summary
 void close()
          Close the store.
protected  AsyncBinaryStore.QueueDaemon ensureQueueDaemon()
          Obtain the QueueDaemon, if one already exists; otherwise, create and start one.
 void erase(Binary binKey)
          Remove the specified key from the underlying store if present.
 void eraseAll()
          Remove all data from the underlying store.
protected  void finalize()
          Perform cleanup during garbage collection.
 void forceSync()
          Indicate the future write operations must be synchronous.
 BinaryStore getBinaryStore()
          Obtain the BinaryStore that this AsyncBinaryStore wraps.
protected  ConcurrentMap getPendingMap()
          Obtain the map that contains all of the pending store and erase data.
protected  AsyncBinaryStore.QueueDaemon getQueueDaemon()
           
 int getQueuedLimit()
          Determine the size, in bytes, of the data that can be queued to be written asynchronously by the QueueDaemon thread.
 int getQueuedSize()
          Determine the current number of bytes that are pending being written.
protected  AsyncBinaryStore.QueueDaemon instantiateQueueDaemon()
          Factory method: Instantiate a QueueDaemon.
 boolean isAsync()
          Determine if the AsyncBinaryStore is operating in an asynchronous manner.
 java.util.Iterator keys()
          Iterate all keys in the underlying store.
 Binary load(Binary binKey)
          Return the value associated with the specified key, or null if the key does not have an associated value in the underlying store.
protected  void setBinaryStore(BinaryStore store)
          Specify the underlying BinaryStore.
protected  void setQueueDaemon(AsyncBinaryStore.QueueDaemon daemon)
           
 void store(Binary binKey, Binary binValue)
          Store the specified value under the specific key in the underlying store.
 java.lang.String toString()
          Return a human readable description of the AsyncBinaryStore.
protected  void updateQueuedSize(int cb)
          Update the number of bytes that are pending to be written.

 

Field Detail

DELETED

protected static final Binary DELETED
A special token that is used to signify a queued erase operation.

DEFAULT_LIMIT

protected static final int DEFAULT_LIMIT
Default size limit for write-queued data.
See Also:
Constant Field Values

LOCK_ALL

protected static final java.lang.Object LOCK_ALL
Special key to indicate that all keys should be locked.

WAIT_FOREVER

protected static final long WAIT_FOREVER
Special wait time to indicate that a lock should be blocked on until it becomes available.
See Also:
Constant Field Values

Constructor Detail

AsyncBinaryStore

public AsyncBinaryStore(BinaryStore store)
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

public AsyncBinaryStore(BinaryStore store,
                        int cbMax)
Construct an AsyncBinaryStore. An AsyncBinaryStor wrap other BinaryStore objects to provide asynchronous write operations.
Parameters:
store - the BinaryStore to wrap
cbMax - the maximum number of bytes to queue before blocking

Method Detail

load

public Binary load(Binary binKey)
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:
load in interface BinaryStore
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

public void store(Binary binKey,
                  Binary binValue)
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:
store in interface BinaryStore
Parameters:
binKey - key to store the value under
binValue - value to be stored
Throws:
java.lang.UnsupportedOperationException - if this implementation or the underlying store is read-only

erase

public void erase(Binary binKey)
Remove the specified key from the underlying store if present.
Specified by:
erase in interface BinaryStore
Parameters:
binKey - key whose mapping is to be removed from the map
Throws:
java.lang.UnsupportedOperationException - if this implementation or the underlying store is read-only

eraseAll

public void eraseAll()
Remove all data from the underlying store.
Specified by:
eraseAll in interface BinaryStore
Throws:
java.lang.UnsupportedOperationException - if this implementation or the underlying store is read-only

keys

public java.util.Iterator keys()
Iterate all keys in the underlying store.
Specified by:
keys in interface BinaryStore
Returns:
a read-only iterator of the keys in the underlying store
Throws:
java.lang.UnsupportedOperationException - if the underlying store is not iterable

close

public void close()
Close the store.

getBinaryStore

public BinaryStore 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

protected void setBinaryStore(BinaryStore store)
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

protected ConcurrentMap 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 be DELETED to indicate an erase operation, otherwise it will be a Binary value.
Returns:
the ConcurrentMap that keeps track of all the pending writes

toString

public java.lang.String toString()
Return a human readable description of the AsyncBinaryStore.
Returns:
a String description of the AsyncBinaryStore

finalize

protected void finalize()
Perform cleanup during garbage collection.

getQueueDaemon

protected AsyncBinaryStore.QueueDaemon getQueueDaemon()
Returns:
the daemon that manages the write-behind queue

setQueueDaemon

protected void setQueueDaemon(AsyncBinaryStore.QueueDaemon daemon)
Parameters:
daemon - the daemon that manages the write-behind queue

ensureQueueDaemon

protected AsyncBinaryStore.QueueDaemon ensureQueueDaemon()
Obtain the QueueDaemon, if one already exists; otherwise, create and start one.
Returns:
the daemon that manages the write-behind queue

instantiateQueueDaemon

protected AsyncBinaryStore.QueueDaemon instantiateQueueDaemon()
Factory method: Instantiate a QueueDaemon.
Returns:
a new QueueDaemon, but not started

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.1.0

E18814-01


Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.