CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

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(Object oKey)
          Remove the specified key from the underlying store if present.
 void eraseAll(Collection colKeys)
          Remove the specified keys from the underlying store if present.
protected  void eraseAllInternal(Collection colKeys)
          Same as eraseAll(java.util.Collection), but the keys is in the internal format.
protected  void eraseInternal(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.
 Object load(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.
 Map loadAll(Collection colKeys)
          Return the values associated with each the specified keys in the passed collection.
protected  Map loadAllInternal(Collection colKeys)
          Same as loadAll(java.util.Collection), but the keys are in the internal format.
protected  Object loadInternal(Object oKey)
          Same as load(java.lang.Object), but the key and the returned value are in the internal format.
protected  void onEraseAllFailure(Collection colKeys, Exception e)
          Logs a CacheStore eraseAll() failure.
protected  void onEraseFailure(Object oKeyReal, Exception e)
          Logs a CacheStore erase() failure.
protected  void onLoadAllFailure(Collection colKeys, Exception e)
          Logs a CacheStore loadAll() failure.
protected  void onLoadFailure(Object oKeyReal, Exception e)
          Logs a CacheStore load() failure.
protected  void onStoreAllFailure(Map mapEntries, Exception e)
          Logs a CacheStore storeAll() failure.
protected  void onStoreFailure(Object oKeyReal, Object oValueReal, Exception e)
          Logs a CacheStore store() failure.
protected  void replaceInternal(Object oKey, Object oValueOld, Object oValueNew)
          Replace the value in the internal cache with a new one iff it is currently mapped to the given value.
 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(Object oKey, Object oValue)
          Store the specified value under the specified key in the underlying store.
 void storeAll(Map mapEntries)
          Store the specified values under the specified keys in the underlying store.
protected  void storeAllInternal(Map mapEntries)
          Same as storeAll(java.util.Map), but the entries are in the internal format.
protected  void storeInternal(Object oKey, Object oValue)
          Same as store(java.lang.Object, java.lang.Object), but the key and value are in the internal format.
 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 Object loadInternal(Object oKey)
Same as load(java.lang.Object), but the key and the returned value are in the internal format.


loadAllInternal

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


storeInternal

protected void storeInternal(Object oKey,
                             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(Map mapEntries)
Same as storeAll(java.util.Map), but the entries are in the internal format.


eraseInternal

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


eraseAllInternal

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


replaceInternal

protected void replaceInternal(Object oKey,
                               Object oValueOld,
                               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 Object load(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 Map loadAll(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(Object oKey,
                  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(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(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(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(Object oKeyReal,
                             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(Collection colKeys,
                                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(Object oKeyReal,
                              Object oValueReal,
                              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(Map mapEntries,
                                 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

onEraseFailure

protected void onEraseFailure(Object oKeyReal,
                              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(Collection colKeys,
                                 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 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

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation