8.3. Region Activation/Inactivation with a CacheLoader
The activateRegion()/inactivateRegion() API can be used in conjunction with a CacheLoader as well, but only if the cache loader implementation implements interface org.jboss.cache.loader.ExtendedCacheLoader. This is a subinterface of the normal CacheLoader interface. It additionally specifies the following methods needed to support the partial state transfer that occurs when a region is activated:
/**
* Fetch a portion of the state for this cache from secondary storage
* (disk, DB) and return it as a byte buffer.
* This is for activation of a portion of new cache from a remote cache.
* The new cache would then call {@link #storeState(byte[], Fqn)}.
*
* @param subtree Fqn naming the root (i.e. highest level parent) node of
* the subtree for which state is requested.
*
* @see org.jboss.cache.TreeCache#activateRegion(String)
*/
byte[] loadState(Fqn subtree) throws Exception;
/**
* Store the given portion of the cache tree's state in secondary storage.
* Overwrite whatever is currently in secondary storage.
*
* @param state the state to store
* @param subtree Fqn naming the root (i.e. highest level parent) node of
* the subtree included in state.
*/
void storeState(byte[] state, Fqn subtree) throws Exception;
/**
* 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 TreeCache instance this cache loader is
* associated with.
*
*
* @param manager the region manager to use, or null.
*/
void setRegionManager(RegionManager manager);
JBossCache currently comes with two implementations of ExtendedCacheLoader, FileExtendedCacheLoader and JDBCExtendedCacheLoader. These classes extend FileCacheLoader and JDBCCacheLoader, respectively, implementing the extra methods in the extended interface.