Oracle® Coherence Java API Reference
v3.5

E14977-01

com.tangosol.net.cache
Class ReadWriteBackingMap.CacheStoreWrapper

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.net.cache.AbstractCacheLoader
          extended by com.tangosol.net.cache.AbstractCacheStore
              extended by com.tangosol.net.cache.ReadWriteBackingMap.CacheStoreWrapper
All Implemented Interfaces:
CacheLoader, CacheStore
Direct Known Subclasses:
VersionedBackingMap.CacheStoreWrapper
Enclosing class:
ReadWriteBackingMap

public class ReadWriteBackingMap.CacheStoreWrapper
extends AbstractCacheStore

A wrapper around the original CacheStore to allow operations to be overridden and extended.

Author:
cp 2002.06.04

Nested Class Summary
protected  class ReadWriteBackingMap.CacheStoreWrapper.EraseBundler
           
protected  class ReadWriteBackingMap.CacheStoreWrapper.LoadBundler
           
protected  class ReadWriteBackingMap.CacheStoreWrapper.StoreBundler
           
 
Constructor Summary
ReadWriteBackingMap.CacheStoreWrapper(CacheStore store)
          Construct a wrapped CacheStore.
 
Method Summary
 AbstractBundler ensureEraseBundler(int cBundleThreshold)
          Configure the bundler for the "erase" operations.
 AbstractBundler ensureLoadBundler(int cBundleThreshold)
          Configure the bundler for the "load" operations.
 AbstractBundler ensureStoreBundler(int cBundleThreshold)
          Configure the bundler for the "store" operations.
 void erase(java.lang.Object oKey)
          Remove the specified key from the underlying store if present.
 void eraseAll(java.util.Collection colKeys)
          Remove the specified keys from the underlying store if present.
protected  void eraseAllInternal(java.util.Collection colKeys)
          Same as eraseAll(java.util.Collection), but the keys is in the internal format.
protected  void eraseInternal(java.lang.Object oKey)
          Same as erase(java.lang.Object), but the key is in the internal format.
 long getAverageBatchSize()
          Determine the average number of entries stored per store() operation.
 long getAverageEraseMillis()
          Determine the average time spent per erase() operation.
 long getAverageLoadMillis()
          Determine the average time spent per load() operation.
 long getAverageStoreMillis()
          Determine the average time spent per store() operation.
 CacheStore getCacheStore()
          The wrapped CacheStore.
 AbstractBundler getEraseBundler()
          Obtain the bundler for the "erase" operations.
 long getEraseFailures()
          Determine the number of erase() failures.
 long getEraseMillis()
          Determine the cummulative time spent on erase() operations.
 long getEraseOps()
          Determine the number of erase() operations.
 AbstractBundler getLoadBundler()
          Obtain the bundler for the "load" operations.
 long getLoadFailures()
          Determine the number of load() failures.
 long getLoadMillis()
          Determine the cummulative time spent on load() operations.
 long getLoadOps()
          Determine the number of load() operations.
 AbstractBundler getStoreBundler()
          Obtain the bundler for the "store" operations.
 long getStoreFailures()
          Determine the number of store() failures.
 long getStoreMillis()
          Determine the cummulative time spent on store() operations.
 long getStoreOps()
          Determine the number of store() operations.
 boolean isEraseAllSupported()
          Determine if the wrapped CacheStore supports eraseAll() operations.
 boolean isEraseSupported()
          Determine if the wrapped CacheStore supports erase() operations.
 boolean isStoreAllSupported()
          Determine if the wrapped CacheStore supports storeAll() operations.
 boolean isStoreSupported()
          Determine if the wrapped CacheStore supports store() operations.
 java.lang.Object load(java.lang.Object oKey)
          Return the value associated with the specified key, or null if the key does not have an associated value in the underlying store.
 java.util.Map loadAll(java.util.Collection colKeys)
          Return the values associated with each the specified keys in the passed collection.
protected  java.util.Map loadAllInternal(java.util.Collection colKeys)
          Same as loadAll(java.util.Collection), but the keys are in the internal format.
protected  java.lang.Object loadInternal(java.lang.Object oKey)
          Same as load(java.lang.Object), but the key and the returned value are in the internal format.
protected  void onEraseAllFailure(java.util.Collection colKeys, java.lang.Exception e)
          Logs a CacheStore eraseAll() failure.
protected  void onEraseFailure(java.lang.Object oKeyReal, java.lang.Exception e)
          Logs a CacheStore erase() failure.
protected  void onLoadAllFailure(java.util.Collection colKeys, java.lang.Exception e)
          Logs a CacheStore loadAll() failure.
protected  void onLoadFailure(java.lang.Object oKeyReal, java.lang.Exception e)
          Logs a CacheStore load() failure.
protected  void onStoreAllFailure(java.util.Map mapEntries, java.lang.Exception e)
          Logs a CacheStore storeAll() failure.
protected  void onStoreFailure(java.lang.Object oKeyReal, java.lang.Object oValueReal, java.lang.Exception e)
          Logs a CacheStore store() failure.
protected  void replaceInternal(java.lang.Object oKey, java.lang.Object oValueOld, java.lang.Object oValueNew)
          Replace the value in the internal cache with a new one iff it is currently mapped to the given value.
protected  boolean requeue(ReadWriteBackingMap.WriteQueue queue, int cThreshold, java.lang.Object oKeyReal, java.lang.Object oValueReal)
          Requeue the specified entry if the queue has not reached the max size.
 void resetStatistics()
          Reset the CacheStore statistics.
 void setEraseAllSupported(boolean fSupported)
          Set the flag that determines whether or not the wrapped CacheStore supports eraseAll() operations.
 void setEraseSupported(boolean fSupported)
          Set the flag that determines whether or not the wrapped CacheStore supports erase() operations.
 void setStoreAllSupported(boolean fSupported)
          Set the flag that determines whether or not the wrapped CacheStore supports storeAll() operations.
 void setStoreSupported(boolean fSupported)
          Set the flag that determines whether or not the wrapped CacheStore supports store() operations.
 void store(java.lang.Object oKey, java.lang.Object oValue)
          Store the specified value under the specified key in the underlying store.
 void storeAll(java.util.Map mapEntries)
          Store the specified values under the specified keys in the underlying store.
protected  void storeAllInternal(java.util.Map mapEntries)
          Same as storeAll(java.util.Map), but the entries are in the internal format.
protected  void storeInternal(java.lang.Object oKey, java.lang.Object oValue)
          Same as store(java.lang.Object, java.lang.Object), but the key and value are in the internal format.
 java.lang.String toString()
          Return a String representation of the CacheStoreWrapper object that will be used as a part of the write-behind thread name.
 

Constructor Detail

ReadWriteBackingMap.CacheStoreWrapper

public ReadWriteBackingMap.CacheStoreWrapper(CacheStore store)
Construct a wrapped CacheStore.

Parameters:
store - the CacheStore to wrap
Method Detail

ensureLoadBundler

public AbstractBundler ensureLoadBundler(int cBundleThreshold)
Configure the bundler for the "load" operations. If the bundler does not exist and bundling is enabled, it will be instantiated.

Parameters:
cBundleThreshold - the bundle size threshold; pass zero to disable "load" operation bundling
Returns:
the "load" bundler or null if bundling is disabled

ensureStoreBundler

public AbstractBundler ensureStoreBundler(int cBundleThreshold)
Configure the bundler for the "store" operations. If the bundler does not exist and bundling is enabled, it will be instantiated.

Parameters:
cBundleThreshold - the bundle size threshold; pass zero to disable "store" operation bundling
Returns:
the "store" bundler or null if bundling is disabled

ensureEraseBundler

public AbstractBundler ensureEraseBundler(int cBundleThreshold)
Configure the bundler for the "erase" operations. If the bundler does not exist and bundling is enabled, it will be instantiated.

Parameters:
cBundleThreshold - the bundle size threshold; pass zero to disable "erase" operation bundling
Returns:
the "erase" bundler or null if bundling is disabled

getLoadBundler

public AbstractBundler getLoadBundler()
Obtain the bundler for the "load" operations.

Returns:
the "load" bundler

getStoreBundler

public AbstractBundler getStoreBundler()
Obtain the bundler for the "store" operations.

Returns:
the "store" bundler

getEraseBundler

public AbstractBundler getEraseBundler()
Obtain the bundler for the "erase" operations.

Returns:
the "erase" bundler

loadInternal

protected java.lang.Object loadInternal(java.lang.Object oKey)
Same as load(java.lang.Object), but the key and the returned value are in the internal format.


loadAllInternal

protected java.util.Map loadAllInternal(java.util.Collection colKeys)
Same as loadAll(java.util.Collection), but the keys are in the internal format.


storeInternal

protected void storeInternal(java.lang.Object oKey,
                             java.lang.Object oValue)
Same as store(java.lang.Object, java.lang.Object), but the key and value are in the internal format.


storeAllInternal

protected void storeAllInternal(java.util.Map mapEntries)
Same as storeAll(java.util.Map), but the entries are in the internal format.


eraseInternal

protected void eraseInternal(java.lang.Object oKey)
Same as erase(java.lang.Object), but the key is in the internal format.


eraseAllInternal

protected void eraseAllInternal(java.util.Collection colKeys)
Same as eraseAll(java.util.Collection), but the keys is in the internal format.


replaceInternal

protected void replaceInternal(java.lang.Object oKey,
                               java.lang.Object oValueOld,
                               java.lang.Object oValueNew)
Replace the value in the internal cache with a new one iff it is currently mapped to the given value.

This would be a trivial call if the internal cache implemented the java.util.concurrent.ConcurrentMap interface (JDK 1.5).


load

public java.lang.Object load(java.lang.Object oKey)
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 CacheLoader
Specified by:
load in class AbstractCacheLoader
Parameters:
oKey - 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

loadAll

public java.util.Map loadAll(java.util.Collection colKeys)
Return the values associated with each the specified keys in the passed collection. If a key does not have an associated value in the underlying store, then the return map will not have an entry for that key.

Specified by:
loadAll in interface CacheLoader
Overrides:
loadAll in class AbstractCacheLoader
Parameters:
colKeys - a collection of keys to load
Returns:
a Map of keys to associated values for the specified keys

store

public void store(java.lang.Object oKey,
                  java.lang.Object oValue)
Store the specified value under the specified 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 CacheStore
Overrides:
store in class AbstractCacheStore
Parameters:
oKey - key to store the value under
oValue - value to be stored

storeAll

public void storeAll(java.util.Map mapEntries)
Store the specified values under the specified keys in the underlying store. This method is intended to support both key/value creation and value update for the specified keys.

The implementation of this method calls AbstractCacheStore.store(java.lang.Object, java.lang.Object) for each entry in the supplied Map. Once stored successfully, an entry is removed from the Map (if possible).

Note: For many types of persistent stores, a single store operation is as expensive as a bulk store operation; therefore, subclasses should override this method if possible.

Specified by:
storeAll in interface CacheStore
Overrides:
storeAll in class AbstractCacheStore
Parameters:
mapEntries - a Map of any number of keys and values to store

erase

public void erase(java.lang.Object oKey)
Remove the specified key from the underlying store if present.

Specified by:
erase in interface CacheStore
Overrides:
erase in class AbstractCacheStore
Parameters:
oKey - key whose mapping is being removed from the cache

eraseAll

public void eraseAll(java.util.Collection colKeys)
Remove the specified keys from the underlying store if present.

The implementation of this method calls AbstractCacheStore.erase(java.lang.Object) for each key in the supplied Collection. Once erased successfully, a key is removed from the Collection (if possible).

Note: For many types of persistent stores, a single erase operation is as expensive as a bulk erase operation; therefore, subclasses should override this method if possible.

Specified by:
eraseAll in interface CacheStore
Overrides:
eraseAll in class AbstractCacheStore
Parameters:
colKeys - keys whose mappings are being removed from the cache

getLoadOps

public long getLoadOps()
Determine the number of load() operations.

Returns:
the number of load() operations

getLoadFailures

public long getLoadFailures()
Determine the number of load() failures.

Returns:
the number of load() failures

getLoadMillis

public long getLoadMillis()
Determine the cummulative time spent on load() operations.

Returns:
the cummulative time spent on load() operations

getStoreOps

public long getStoreOps()
Determine the number of store() operations.

Returns:
the number of store() operations

getStoreFailures

public long getStoreFailures()
Determine the number of store() failures.

Returns:
the number of store() failures

getStoreMillis

public long getStoreMillis()
Determine the cummulative time spent on store() operations.

Returns:
the cummulative time spent on store() operations

getEraseOps

public long getEraseOps()
Determine the number of erase() operations.

Returns:
the number of erase() operations

getEraseFailures

public long getEraseFailures()
Determine the number of erase() failures.

Returns:
the number of erase() failures

getEraseMillis

public long getEraseMillis()
Determine the cummulative time spent on erase() operations.

Returns:
the cummulative time spent on erase() operations

getAverageBatchSize

public long getAverageBatchSize()
Determine the average number of entries stored per store() operation.

Returns:
the average number of entries stored per store() operation

getAverageLoadMillis

public long getAverageLoadMillis()
Determine the average time spent per load() operation.

Returns:
the average time spent per load() operation

getAverageStoreMillis

public long getAverageStoreMillis()
Determine the average time spent per store() operation.

Returns:
the average time spent per store() operation

getAverageEraseMillis

public long getAverageEraseMillis()
Determine the average time spent per erase() operation.

Returns:
the average time spent per erase() operation

resetStatistics

public void resetStatistics()
Reset the CacheStore statistics.


getCacheStore

public CacheStore getCacheStore()
The wrapped CacheStore.

Returns:
the underlying CacheStore that this CacheStore wraps

isStoreSupported

public boolean isStoreSupported()
Determine if the wrapped CacheStore supports store() operations.

Returns:
true if the wrapped CacheStore supports store() operations

setStoreSupported

public void setStoreSupported(boolean fSupported)
Set the flag that determines whether or not the wrapped CacheStore supports store() operations.

Parameters:
fSupported - the new value of the flag

isStoreAllSupported

public boolean isStoreAllSupported()
Determine if the wrapped CacheStore supports storeAll() operations.

Returns:
true if the wrapped CacheStore supports storeAll() operations

setStoreAllSupported

public void setStoreAllSupported(boolean fSupported)
Set the flag that determines whether or not the wrapped CacheStore supports storeAll() operations.

Parameters:
fSupported - the new value of the flag

isEraseSupported

public boolean isEraseSupported()
Determine if the wrapped CacheStore supports erase() operations.

Returns:
true if the wrapped CacheStore supports erase() operations

setEraseSupported

public void setEraseSupported(boolean fSupported)
Set the flag that determines whether or not the wrapped CacheStore supports erase() operations.

Parameters:
fSupported - the new value of the flag

isEraseAllSupported

public boolean isEraseAllSupported()
Determine if the wrapped CacheStore supports eraseAll() operations.

Returns:
true if the wrapped CacheStore supports eraseAll() operations

setEraseAllSupported

public void setEraseAllSupported(boolean fSupported)
Set the flag that determines whether or not the wrapped CacheStore supports eraseAll() operations.

Parameters:
fSupported - the new value of the flag

onLoadFailure

protected void onLoadFailure(java.lang.Object oKeyReal,
                             java.lang.Exception e)
Logs a CacheStore load() failure. This method is intended to be overwritten if a particular CacheStore can fail and the backing map must take action based on it.

Parameters:
oKeyReal - the key
e - the exception

onLoadAllFailure

protected void onLoadAllFailure(java.util.Collection colKeys,
                                java.lang.Exception e)
Logs a CacheStore loadAll() failure. This method is intended to be overwritten if a particular CacheStore can fail and the backing map must take action based on it.

Parameters:
colKeys - colKeys a collection of keys in external form to load
e - the exception

onStoreFailure

protected void onStoreFailure(java.lang.Object oKeyReal,
                              java.lang.Object oValueReal,
                              java.lang.Exception e)
Logs a CacheStore store() failure. This method is intended to be overwritten if a particular CacheStore can fail and the backing map must take action based on it.

Parameters:
oKeyReal - the key
oValueReal - the value
e - the exception

onStoreAllFailure

protected void onStoreAllFailure(java.util.Map mapEntries,
                                 java.lang.Exception e)
Logs a CacheStore storeAll() failure. This method is intended to be overwritten if a particular CacheStore can fail and the backing map must take action based on it.

Parameters:
mapEntries - a Map of entries in external form
e - the exception

requeue

protected boolean requeue(ReadWriteBackingMap.WriteQueue queue,
                          int cThreshold,
                          java.lang.Object oKeyReal,
                          java.lang.Object oValueReal)
Requeue the specified entry if the queue has not reached the max size.

Note: Subclasses could override this method and perform some type of the "last recovery attempt" operation if the super.requeue(...) call returns false.

Parameters:
queue - the queue
cThreshold - the queue size threshold
oKeyReal - entry's key
oValueReal - entry's value
Returns:
true if the entry was requeued or was already queued; false if the queue threshold has been reached

onEraseFailure

protected void onEraseFailure(java.lang.Object oKeyReal,
                              java.lang.Exception e)
Logs a CacheStore erase() failure. This method is intended to be overwritten if a particular CacheStore can fail and the backing map must take action based on it.

Parameters:
oKeyReal - the key
e - the exception

onEraseAllFailure

protected void onEraseAllFailure(java.util.Collection colKeys,
                                 java.lang.Exception e)
Logs a CacheStore eraseAll() failure. This method is intended to be overwritten if a particular CacheStore can fail and the backing map must take action based on it.

Parameters:
colKeys - keys whose mappings are being removed from the cache
e - the exception

toString

public java.lang.String toString()
Return a String representation of the CacheStoreWrapper object that will be used as a part of the write-behind thread name.

Returns:
a String representation of the CacheStoreWrapper object

Oracle® Coherence Java API Reference
v3.5

E14977-01

Copyright © 2000, 2009, Oracle. All rights reserved.