|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jboss.cache.loader.AbstractCacheLoader
org.jboss.cache.loader.AbstractDelegatingCacheLoader
org.jboss.cache.loader.SingletonStoreCacheLoader
public class SingletonStoreCacheLoader
SingletonStoreCacheLoader is a delegating cache loader used for situations when only one node should interact with the underlying store. The coordinator of the cluster will be responsible for the underlying CacheLoader. SingletonStoreCacheLoader is a simply facade to a real CacheLoader implementation. It always delegates reads to the real CacheLoader.
Writes are forwarded only if this SingletonStoreCacheLoader is currently the cordinator. This avoid having all CacheLoaders in a cluster writing the same data to the same underlying store. Although not incorrect (e.g. a DB will just discard additional INSERTs for the same key, and throw an exception), this will avoid a lot of redundant work.
| Nested Class Summary | |
|---|---|
static class |
SingletonStoreCacheLoader.PushStateException
Exception representing any issues that arise from pushing the in-memory state to the cache loader. |
class |
SingletonStoreCacheLoader.SingletonStoreListener
Cache listener that reacts to cluster topology changes to find out whether a new coordinator is elected. |
| Field Summary |
|---|
| Fields inherited from class org.jboss.cache.loader.AbstractCacheLoader |
|---|
buddyFqnTransformer, cache, regionManager, transactions |
| Constructor Summary | |
|---|---|
|
SingletonStoreCacheLoader()
Empty constructor so that it can instantiated using reflection. |
protected |
SingletonStoreCacheLoader(SingletonStoreDefaultConfig config)
Protected constructor which should only be used from unit tests. |
| Method Summary | |
|---|---|
protected void |
activeStatusChanged(boolean newActiveState)
Method called when the node either becomes the coordinator or stops being the coordinator. |
protected void |
awaitForPushToFinish(Future future,
int timeout,
TimeUnit unit)
Method that waits for the in-memory to cache loader state to finish. |
void |
commit(Object tx)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
create()
Lifecycle method, called when the cache loader is created. |
protected Callable<?> |
createPushStateTask()
Factory method for the creation of a Callable task in charge of pushing in-memory state to cache loader. |
protected Future<?> |
getPushStateFuture()
Returns the Future instance of a running in-memory to cache loader push task. |
protected SingletonStoreDefaultConfig |
getSingletonStoreDefaultConfig()
Returns SingletonStoreCacheLoader's configuration instance. |
void |
prepare(Object tx,
List<Modification> modifications,
boolean one_phase)
Calls the underlying cache loader's operation if the current node is the coordinator. |
protected void |
pushState(NodeSPI node)
Pushes the state of a specific node by reading the node's data from the cache and putting in the cache store via the cache loader. |
void |
put(Fqn name,
Map attributes)
Calls the underlying cache loader's operation if the current node is the coordinator. |
Object |
put(Fqn name,
Object key,
Object value)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
put(List<Modification> modifications)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
remove(Fqn fqn)
Calls the underlying cache loader's operation if the current node is the coordinator. |
Object |
remove(Fqn fqn,
Object key)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
removeData(Fqn fqn)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
rollback(Object tx)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig config)
Sets the config for SingletonStoreCacheLoader and for the delegating cache loader. |
void |
storeEntireState(ObjectInputStream is)
Calls the underlying cache loader's operation if the current node is the coordinator. |
void |
storeState(Fqn subtree,
ObjectInputStream is)
Calls the underlying cache loader's operation if the current node is the coordinator. |
String |
toString()
Calls the underlying cache loader's operation if the current node is the coordinator. |
| Methods inherited from class org.jboss.cache.loader.AbstractDelegatingCacheLoader |
|---|
destroy, exists, get, getCacheLoader, getConfig, getChildrenNames, loadEntireState, loadState, setCache, setCacheLoader, setRegionManager, start, stop |
| 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 |
|---|
public SingletonStoreCacheLoader()
protected SingletonStoreCacheLoader(SingletonStoreDefaultConfig config)
config - configuration instance for SingletonStoreCacheLoader| Method Detail |
|---|
public void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig config)
setConfig in interface CacheLoadersetConfig in class AbstractDelegatingCacheLoaderconfig - 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.
public void create()
throws Exception
CacheLoader
create in interface CacheLoadercreate in class AbstractDelegatingCacheLoaderExceptionprotected SingletonStoreDefaultConfig getSingletonStoreDefaultConfig()
protected Future<?> getPushStateFuture()
protected void activeStatusChanged(boolean newActiveState)
throws SingletonStoreCacheLoader.PushStateException
newActiveState - true if the node just became the coordinator, false if the nodes stopped being the coordinator.
SingletonStoreCacheLoader.PushStateExceptionprotected Callable<?> createPushStateTask()
protected void pushState(NodeSPI node)
throws Exception
node - instance of NodeSPI to push to the cache loader
Exception - if there's any issues reading the data from the cache or pushing the node's data to the cache
loader.
protected void awaitForPushToFinish(Future future,
int timeout,
TimeUnit unit)
future - instance of Future representing the on going push tasktimeout - time to wait for the push task to finishunit - instance of TimeUnit representing the unit of timeout
public Object put(Fqn name,
Object key,
Object value)
throws Exception
put in interface CacheLoaderput in class AbstractDelegatingCacheLoaderException
public void put(Fqn name,
Map attributes)
throws Exception
put in interface CacheLoaderput in class AbstractDelegatingCacheLoadername - The fully qualified name of the nodeattributes - A Map of attributes. Can be null
Exception
public void put(List<Modification> modifications)
throws Exception
put in interface CacheLoaderput in class AbstractDelegatingCacheLoadermodifications - A ListException
public Object remove(Fqn fqn,
Object key)
throws Exception
remove in interface CacheLoaderremove in class AbstractDelegatingCacheLoaderException
public void remove(Fqn fqn)
throws Exception
remove in interface CacheLoaderremove in class AbstractDelegatingCacheLoaderfqn - the Fqn of the node
Exception
public void removeData(Fqn fqn)
throws Exception
removeData in interface CacheLoaderremoveData in class AbstractDelegatingCacheLoaderfqn - the Fqn of the node
Exception
public void prepare(Object tx,
List<Modification> modifications,
boolean one_phase)
throws Exception
prepare in interface CacheLoaderprepare in class AbstractDelegatingCacheLoadertx - 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 transactionone_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
Exception
public void commit(Object tx)
throws Exception
commit in interface CacheLoadercommit in class AbstractDelegatingCacheLoadertx - transaction to commit
Exceptionpublic void rollback(Object tx)
rollback in interface CacheLoaderrollback in class AbstractDelegatingCacheLoadertx - transaction to roll back
public void storeEntireState(ObjectInputStream is)
throws Exception
storeEntireState in interface CacheLoaderstoreEntireState in class AbstractDelegatingCacheLoaderis - ObjectInputStream to read state
ExceptionAbstractCacheLoader.storeEntireState(ObjectInputStream),
NodeData
public void storeState(Fqn subtree,
ObjectInputStream is)
throws Exception
storeState in interface CacheLoaderstoreState in class AbstractDelegatingCacheLoadersubtree - 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.is - ObjectInputStream to read state
ExceptionAbstractCacheLoader.storeState(Fqn,ObjectInputStream),
NodeDatapublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||