org.jboss.cache.loader
Class AbstractCacheLoader

java.lang.Object
  extended by org.jboss.cache.loader.AbstractCacheLoader
All Implemented Interfaces:
CacheLoader
Direct Known Subclasses:
AbstractDelegatingCacheLoader, AdjListJDBCCacheLoader, BdbjeCacheLoader, ChainingCacheLoader, ClusteredCacheLoader, DelegatingCacheLoader, FileCacheLoader, JdbmCacheLoader

public abstract class AbstractCacheLoader
extends java.lang.Object
implements CacheLoader

A convenience abstract implementation of a CacheLoader. Specific methods to note are methods like storeState(org.jboss.cache.Fqn,java.io.ObjectInputStream), loadState(org.jboss.cache.Fqn,java.io.ObjectOutputStream), storeEntireState(java.io.ObjectInputStream) and loadEntireState(java.io.ObjectOutputStream) which have convenience implementations here.

Also useful to note is the implementation of put(java.util.List), used during the prepare phase of a transaction.

Since:
2.0.0
Author:
Manik Surtani (manik@jboss.org), Galder Zamarreno

Field Summary
protected  CacheSPI cache
           
protected  RegionManager regionManager
           
 
Constructor Summary
AbstractCacheLoader()
           
 
Method Summary
protected  Marshaller getMarshaller()
           
protected  void getNodeDataList(Fqn fqn, java.util.List<NodeData> list)
           
 void loadEntireState(java.io.ObjectOutputStream os)
          Fetches the entire state for this cache from secondary storage (disk, database) and writes it to a provided ObjectOutputStream.
 void loadState(Fqn subtree, java.io.ObjectOutputStream os)
          Fetches a portion of the state for this cache from secondary storage (disk, database) and writes it to a provided ObjectOutputStream.
protected  void loadStateHelper(Fqn fqn, java.io.ObjectOutputStream out)
          Do a preorder traversal: visit the node first, then the node's children
 void put(Fqn fqn, java.util.Map<java.lang.Object,java.lang.Object> attributes, boolean erase)
           
 void put(java.util.List<Modification> modifications)
          Applies all modifications to the backend store.
 void setCache(CacheSPI c)
          Sets the CacheSPI that is maintaining this CacheLoader.
 void setRegionManager(RegionManager regionManager)
          Sets the RegionManager this object should use to manage marshalling/unmarshalling of different regions using different classloaders.
 void storeEntireState(java.io.ObjectInputStream is)
          Stores the entire state for this cache by reading it from a provided ObjectInputStream.
 void storeState(Fqn subtree, java.io.ObjectInputStream in)
          Stores the given portion of the cache tree's state in secondary storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.cache.loader.CacheLoader
commit, create, destroy, exists, get, getChildrenNames, getConfig, prepare, put, put, remove, remove, removeData, rollback, setConfig, start, stop
 

Field Detail

cache

protected CacheSPI cache

regionManager

protected RegionManager regionManager
Constructor Detail

AbstractCacheLoader

public AbstractCacheLoader()
Method Detail

put

public void put(Fqn fqn,
                java.util.Map<java.lang.Object,java.lang.Object> attributes,
                boolean erase)
         throws java.lang.Exception
Throws:
java.lang.Exception

storeEntireState

public void storeEntireState(java.io.ObjectInputStream is)
                      throws java.lang.Exception
Description copied from interface: CacheLoader
Stores the entire state for this cache by reading it from a provided ObjectInputStream. The state was provided to this cache by calling CacheLoader.loadEntireState(ObjectOutputStream)} on some other cache instance. State currently in storage gets overwritten.

Implementations of this method should not catch any exception or close the given ObjectInputStream parameter. In order to ensure cacheloader interoperability contents of the cache are read from the ObjectInputStream as a sequence of NodeData objects.

Default implementation is provided by AbstractCacheLoader and ensures cacheloader interoperability. Implementors are encouraged to consider extending AbstractCacheLoader prior to implementing completely custom cacheloader.

Specified by:
storeEntireState in interface CacheLoader
Parameters:
is - ObjectInputStream to read state
Throws:
java.lang.Exception
See Also:
storeEntireState(ObjectInputStream), NodeData

storeState

public void storeState(Fqn subtree,
                       java.io.ObjectInputStream in)
                throws java.lang.Exception
Description copied from interface: CacheLoader
Stores the given portion of the cache tree's state in secondary storage. Overwrite whatever is currently in secondary storage. If the transferred state has Fqns equal to or children of parameter subtree, then no special behavior is required. Otherwise, ensure that the state is integrated under the given subtree. Typically in the latter case subtree would be the Fqn of the buddy backup region for a buddy group; e.g.

If the the transferred state had Fqns starting with "/a" and subtree was "/_BUDDY_BACKUP_/192.168.1.2:5555" then the state should be stored in the local persistent store under "/_BUDDY_BACKUP_/192.168.1.2:5555/a"

Implementations of this method should not catch any exception or close the given ObjectInputStream parameter. In order to ensure cacheloader interoperability contents of the cache are read from the ObjectInputStream as a sequence of NodeData objects.

Default implementation is provided by AbstractCacheLoader and ensures cacheloader interoperability. Implementors are encouraged to consider extending AbstractCacheLoader prior to implementing completely custom cacheloader.

Specified by:
storeState in interface CacheLoader
Parameters:
subtree - Fqn naming the root (i.e. highest level parent) node of the subtree included in state. If the Fqns of the data included in state are not already children of subtree, then their Fqns should be altered to make them children of subtree before they are persisted.
in - ObjectInputStream to read state
Throws:
java.lang.Exception
See Also:
storeState(Fqn,ObjectInputStream), NodeData

loadEntireState

public void loadEntireState(java.io.ObjectOutputStream os)
                     throws java.lang.Exception
Description copied from interface: CacheLoader
Fetches the entire state for this cache from secondary storage (disk, database) and writes it to a provided ObjectOutputStream. State written to the provided ObjectOutputStream parameter is used for initialization of a new CacheImpl instance. When the state gets transferred to the new cache instance its cacheloader calls CacheLoader.storeEntireState(ObjectInputStream)

Implementations of this method should not catch any exception or close the given ObjectOutputStream parameter. In order to ensure cacheloader interoperability contents of the cache are written to the ObjectOutputStream as a sequence of NodeData objects.

Default implementation is provided by AbstractCacheLoader and ensures cacheloader interoperability. Implementors are encouraged to consider extending AbstractCacheLoader prior to implementing completely custom cacheloader.

Specified by:
loadEntireState in interface CacheLoader
Parameters:
os - ObjectOutputStream to write state
Throws:
java.lang.Exception
See Also:
loadEntireState(ObjectOutputStream), NodeData

loadState

public void loadState(Fqn subtree,
                      java.io.ObjectOutputStream os)
               throws java.lang.Exception
Description copied from interface: CacheLoader
Fetches a portion of the state for this cache from secondary storage (disk, database) and writes it to a provided ObjectOutputStream. State written to the provided ObjectOutputStream parameter is used for activation of a portion of a new CacheImpl instance. When the state gets transferred to the new cache instance its cacheloader calls CacheLoader.storeState(Fqn,ObjectInputStream).

Implementations of this method should not catch any exception or close the given ObjectOutputStream parameter. In order to ensure cacheloader interoperability contents of the cache are written to the ObjectOutputStream as a sequence of NodeData objects.

Default implementation is provided by AbstractCacheLoader and ensures cacheloader interoperability. Implementors are encouraged to consider extending AbstractCacheLoader prior to implementing completely custom cacheloader.

Specified by:
loadState in interface CacheLoader
Parameters:
subtree - Fqn naming the root (i.e. highest level parent) node of the subtree for which state is requested.
os - ObjectOutputStream to write state
Throws:
java.lang.Exception
See Also:
loadState(Fqn,ObjectOutputStream), Region.activate(), NodeData

setCache

public void setCache(CacheSPI c)
Description copied from interface: CacheLoader
Sets the CacheSPI that is maintaining this CacheLoader. This method allows this CacheLoader to set a reference to the CacheSPI. This method is called be called after the CacheLoader instance has been constructed.

Specified by:
setCache in interface CacheLoader
Parameters:
c - The cache on which this loader works

setRegionManager

public void setRegionManager(RegionManager regionManager)
Description copied from interface: CacheLoader
Sets the RegionManager this object should use to manage marshalling/unmarshalling of different regions using different classloaders.

NOTE: This method is only intended to be used by the CacheSPI instance this cache loader is associated with.

Specified by:
setRegionManager in interface CacheLoader
Parameters:
regionManager - the region manager to use, or null.

loadStateHelper

protected void loadStateHelper(Fqn fqn,
                               java.io.ObjectOutputStream out)
                        throws java.lang.Exception
Do a preorder traversal: visit the node first, then the node's children

Parameters:
fqn - Start node
out -
Throws:
java.lang.Exception

getNodeDataList

protected void getNodeDataList(Fqn fqn,
                               java.util.List<NodeData> list)
                        throws java.lang.Exception
Throws:
java.lang.Exception

put

public void put(java.util.List<Modification> modifications)
         throws java.lang.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
Parameters:
modifications - A List of modifications
Throws:
java.lang.Exception

getMarshaller

protected Marshaller getMarshaller()