org.jboss.cache.loader
Class AsyncCacheLoader

java.lang.Object
  extended by org.jboss.cache.loader.AbstractCacheLoader
      extended by org.jboss.cache.loader.AbstractDelegatingCacheLoader
          extended by org.jboss.cache.loader.AsyncCacheLoader
All Implemented Interfaces:
CacheLoader

public class AsyncCacheLoader
extends AbstractDelegatingCacheLoader

The AsyncCacheLoader is a delegating cache loader that extends AbstractDelegatingCacheLoader overriding methods to that should not just delegate the operation to the underlying cache loader.

Read operations are done synchronously, while write (CRUD - Create, Remove, Update, Delete) operations are done asynchronously. There is no provision for exception handling at the moment for problems encountered with the underlying CacheLoader during a CRUD operation, and the exception is just logged.

When configuring the CacheLoader, use the following attribute:

<attribute name="CacheLoaderAsynchronous">true</attribute>

to define whether cache loader operations are to be asynchronous. If not specified, a cache loader operation is assumed synchronous.

The following additional parameters are available:

cache.async.batchSize
Number of modifications to commit in one transaction, default is 100. The minimum batch size is 1.
cache.async.pollWait
How long to wait before processing an incomplete batch, in milliseconds. Default is 100. Set this to 0 to not wait before processing available records.
cache.async.returnOld
If true, this loader returns the old values from put(org.jboss.cache.Fqn, java.lang.Object, java.lang.Object) and remove(org.jboss.cache.Fqn, java.lang.Object) methods. Otherwise, these methods always return null. Default is true. false improves the performance of these operations.
cache.async.queueSize
Maximum number of entries to enqueue for asynchronous processing. Lowering this size may help prevent out-of-memory conditions. It also may help to prevent less records lost in the case of JVM failure. Default is 10,000 operations.
cache.async.put
If set to false, all put(org.jboss.cache.Fqn, java.lang.Object, java.lang.Object) operations will be processed synchronously, and then only the remove(org.jboss.cache.Fqn, java.lang.Object) operations will be processed asynchronously. This mode may be useful for processing expiration of messages within a separate thread and keeping other operations synchronous for reliability.
For increased performance for many smaller transactions, use higher values for cache.async.batchSize and cache.async.pollWait. For larger sized records, use a smaller value for cache.async.queueSize.

Author:
Manik Surtani (manik.surtani@jboss.com)

Field Summary
 
Fields inherited from class org.jboss.cache.loader.AbstractCacheLoader
cache, regionManager, transactions
 
Constructor Summary
AsyncCacheLoader()
           
AsyncCacheLoader(CacheLoader cacheLoader)
           
 
Method Summary
 Map get(Fqn name)
          Returns all keys and values from the persistent store, given a Fqn
 void put(Fqn name, Map attributes)
          Puts all entries of the map into the existing map of the given node, overwriting existing keys, but not clearing the existing map before insertion.
 Object put(Fqn name, Object key, Object value)
          Puts a key and value into the attribute map of a given node.
 void put(List<Modification> modifications)
          Applies all modifications to the backend store.
 void remove(Fqn name)
          Removes the given node and all its subnodes, does nothing if the node does not exist.
 Object remove(Fqn name, Object key)
          Removes the given key and value from the attributes of the given node.
 void removeData(Fqn name)
          Removes all attributes from a given node, but doesn't delete the node itself or any subnodes.
 void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
          Sets the configuration.
 void start()
          Lifecycle method, called when the cache loader is started.
 void stop()
          Lifecycle method, called when the cache loader is stopped.
 String toString()
           
 
Methods inherited from class org.jboss.cache.loader.AbstractDelegatingCacheLoader
commit, create, destroy, exists, getCacheLoader, getChildrenNames, getConfig, loadEntireState, loadState, prepare, rollback, setCache, setCacheLoader, setRegionManager, storeEntireState, storeState
 
Methods inherited from class org.jboss.cache.loader.AbstractCacheLoader
doMarshall, doUnmarshall, getMarshaller, getNodeDataList, loadStateHelper, put, regionAwareMarshall, regionAwareUnmarshall
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AsyncCacheLoader

public AsyncCacheLoader()

AsyncCacheLoader

public AsyncCacheLoader(CacheLoader cacheLoader)
Method Detail

setConfig

public void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
Description copied from interface: CacheLoader
Sets the configuration. This is called before CacheLoader.create() and CacheLoader.start().

Specified by:
setConfig in interface CacheLoader
Overrides:
setConfig in class AbstractDelegatingCacheLoader
Parameters:
base - May be an instance of the CacheLoaderConfig.IndividualCacheLoaderConfig base class, in which case the cache loader should use the CacheLoaderConfig.IndividualCacheLoaderConfig.getProperties() method to find configuration information. Alternatively, may be a type-specific subclass of CacheLoaderConfig.IndividualCacheLoaderConfig, if there is one.

get

public Map get(Fqn name)
        throws Exception
Description copied from interface: CacheLoader
Returns all keys and values from the persistent store, given a Fqn

Specified by:
get in interface CacheLoader
Overrides:
get in class AbstractDelegatingCacheLoader
Parameters:
name - the Fqn to search for.
Returns:
Map keys and values for the given node. Returns null if the node is not found. If the node is found but has no attributes, this method returns an empty Map.
Throws:
Exception

put

public Object put(Fqn name,
                  Object key,
                  Object value)
           throws Exception
Description copied from interface: CacheLoader
Puts a key and value into the attribute map of a given node. If the node does not exist, all parent nodes from the root down are created automatically. Returns the old value.

Specified by:
put in interface CacheLoader
Overrides:
put in class AbstractDelegatingCacheLoader
Throws:
Exception

put

public void put(Fqn name,
                Map attributes)
         throws Exception
Description copied from interface: CacheLoader
Puts all entries of the map into the existing map of the given node, overwriting existing keys, but not clearing the existing map before insertion. This is the same behavior as Map.putAll(java.util.Map). If the node does not exist, all parent nodes from the root down are created automatically

Specified by:
put in interface CacheLoader
Overrides:
put in class AbstractDelegatingCacheLoader
Parameters:
name - The fully qualified name of the node
attributes - A Map of attributes. Can be null
Throws:
Exception

put

public void put(List<Modification> modifications)
         throws Exception
Description copied from interface: CacheLoader
Applies all modifications to the backend store. Changes may be applied in a single operation.

Specified by:
put in interface CacheLoader
Overrides:
put in class AbstractDelegatingCacheLoader
Parameters:
modifications - A List of modifications
Throws:
Exception

remove

public Object remove(Fqn name,
                     Object key)
              throws Exception
Description copied from interface: CacheLoader
Removes the given key and value from the attributes of the given node. Does nothing if the node doesn't exist Returns the removed value.

Specified by:
remove in interface CacheLoader
Overrides:
remove in class AbstractDelegatingCacheLoader
Throws:
Exception

remove

public void remove(Fqn name)
            throws Exception
Description copied from interface: CacheLoader
Removes the given node and all its subnodes, does nothing if the node does not exist.

Specified by:
remove in interface CacheLoader
Overrides:
remove in class AbstractDelegatingCacheLoader
Parameters:
name - the Fqn of the node
Throws:
Exception

removeData

public void removeData(Fqn name)
                throws Exception
Description copied from interface: CacheLoader
Removes all attributes from a given node, but doesn't delete the node itself or any subnodes.

Specified by:
removeData in interface CacheLoader
Overrides:
removeData in class AbstractDelegatingCacheLoader
Parameters:
name - the Fqn of the node
Throws:
Exception

start

public void start()
           throws Exception
Description copied from interface: CacheLoader
Lifecycle method, called when the cache loader is started.

Specified by:
start in interface CacheLoader
Overrides:
start in class AbstractDelegatingCacheLoader
Throws:
Exception

stop

public void stop()
Description copied from interface: CacheLoader
Lifecycle method, called when the cache loader is stopped.

Specified by:
stop in interface CacheLoader
Overrides:
stop in class AbstractDelegatingCacheLoader

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.