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:
Lifecycle, 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.
cache.async.threadPoolSize
The size of the async processor thread pool. Defaults to 1. This property is new in JBoss Cache 3.0.
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
buddyFqnTransformer, cache, regionManager, transactions
 
Constructor Summary
AsyncCacheLoader()
           
AsyncCacheLoader(CacheLoader cacheLoader)
           
 
Method Summary
 void commit(Object tx)
          TODO this is the same as the AbstractCacheLoader.
 Map get(Fqn name)
          Returns all keys and values from the persistent store, given a Fqn
 void prepare(Object tx, List<Modification> modifications, boolean one_phase)
          TODO this is the same as the AbstractCacheLoader.
 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 rollback(Object tx)
          TODO this is the same as the AbstractCacheLoader.
 void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
          Sets the configuration.
 void start()
           
 void stop()
           
 String toString()
           
 
Methods inherited from class org.jboss.cache.loader.AbstractDelegatingCacheLoader
create, destroy, exists, getCacheLoader, getChildrenNames, getConfig, loadEntireState, loadState, setCache, setCacheLoader, setRegionManager, storeEntireState, storeState
 
Methods inherited from class org.jboss.cache.loader.AbstractCacheLoader
doMarshall, doUnmarshall, getMarshaller, getNodeDataList, loadStateHelper, move, put, regionAwareMarshall, regionAwareUnmarshall, storeStateHelper
 
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 Lifecycle.create() and Lifecycle.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 PluggableConfigurationComponent.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

prepare

public void prepare(Object tx,
                    List<Modification> modifications,
                    boolean one_phase)
             throws Exception
TODO this is the same as the AbstractCacheLoader.

Specified by:
prepare in interface CacheLoader
Overrides:
prepare in class AbstractDelegatingCacheLoader
Parameters:
tx - The transaction, indended to be used by implementations as an identifier of the transaction (and not necessarily a JTA Transaction object)
modifications - A List containing Modifications, for the given transaction
one_phase - Persist immediately and (for example) commit the local JDBC transaction as well. When true, we won't get a CacheLoader.commit(Object) or CacheLoader.rollback(Object) method call later
Throws:
Exception

commit

public void commit(Object tx)
            throws Exception
TODO this is the same as the AbstractCacheLoader.

Specified by:
commit in interface CacheLoader
Overrides:
commit in class AbstractDelegatingCacheLoader
Parameters:
tx - transaction to commit
Throws:
Exception

rollback

public void rollback(Object tx)
TODO this is the same as the AbstractCacheLoader.

Specified by:
rollback in interface CacheLoader
Overrides:
rollback in class AbstractDelegatingCacheLoader
Parameters:
tx - transaction to roll back

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

Note since 3.0, as an optimization, this method will require a definitive attribute map and not just a subset. This will allow cache loader implementations to overwrite rather than merge, if that is deemed more efficient. This will not break backward compatibility since performing a merge will not cause any loss of data even though it is an unnecessary step.

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
Specified by:
start in interface Lifecycle
Overrides:
start in class AbstractDelegatingCacheLoader
Throws:
Exception

stop

public void stop()
Specified by:
stop in interface Lifecycle
Overrides:
stop in class AbstractDelegatingCacheLoader

toString

public String toString()
Overrides:
toString in class Object


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