public class SingletonStore extends AbstractDelegatingStore
Modifier and Type | Class and Description |
---|---|
static class |
SingletonStore.PushStateException
Exception representing any issues that arise from pushing the in-memory state to the cache loader.
|
class |
SingletonStore.SingletonStoreListener
Cache listener that reacts to cluster topology changes to find out whether a new coordinator is elected.
|
Constructor and Description |
---|
SingletonStore(CacheStore delegate,
Cache<Object,Object> cache,
SingletonStoreConfig config) |
Modifier and Type | Method and Description |
---|---|
protected void |
activeStatusChanged(boolean newActiveState)
Method called when the cache either becomes the coordinator or stops being the coordinator.
|
protected void |
awaitForPushToFinish(Future<?> future,
long timeout,
TimeUnit unit)
Method that waits for the in-memory to cache loader state to finish.
|
void |
clear()
Clears all entries in the store
|
void |
commit(GlobalTransaction tx)
Commits a transaction that has been previously prepared.
|
protected Callable<?> |
createPushStateTask()
Factory method for the creation of a Callable task in charge of pushing in-memory state to cache loader.
|
void |
fromStream(ObjectInput inputStream)
Writes contents of the stream to the store.
|
void |
prepare(List<? extends Modification> list,
GlobalTransaction tx,
boolean isOnePhase)
Issues a prepare call with a set of modifications to be applied to the cache store
|
void |
purgeExpired()
Purges expired entries from the store.
|
protected void |
pushState(Cache<Object,Object> cache)
Pushes the state of a specific cache by reading the cache's data and putting in the cache store.
|
boolean |
remove(Object key)
Removes an entry in the store.
|
void |
rollback(GlobalTransaction tx)
Rolls back a transaction that has been previously prepared
This method may be invoked on a transaction for which there is no prior
CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean) . |
void |
start() |
void |
stop() |
void |
store(InternalCacheEntry ed)
Stores an entry
|
String |
toString() |
containsKey, getCacheStoreConfig, getConfigurationClass, getDelegate, init, load, load, loadAll, loadAllKeys, removeAll, setDelegate, toStream, undelegateCacheLoader
public SingletonStore(CacheStore delegate, Cache<Object,Object> cache, SingletonStoreConfig config)
public void store(InternalCacheEntry ed) throws CacheLoaderException
CacheStore
store
in interface CacheStore
store
in class AbstractDelegatingStore
ed
- entry to storeCacheLoaderException
- in the event of problems writing to the storepublic void fromStream(ObjectInput inputStream) throws CacheLoaderException
CacheStore
CacheStore.toStream(java.io.ObjectOutput)
. While not a
requirement, it is recommended that implementations make use of the StreamingMarshaller
when dealing with the stream to make use of efficient marshalling.
It is imperative that implementations do not close the stream after finishing with it.
It is also recommended that implementations use their own start and end markers on the stream since
other processes may write additional data to the stream after the cache store has written to it. As such, either
markers or some other mechanism to prevent the store from reading too much information should be employed when
writing to the stream in CacheStore.fromStream(java.io.ObjectInput)
to prevent data corruption.
It can be assumed that the stream passed in already performs buffering such that the cache store implementation
doesn't have to.
fromStream
in interface CacheStore
fromStream
in class AbstractDelegatingStore
inputStream
- stream to read fromCacheLoaderException
- in the event of problems writing to the storepublic void clear() throws CacheLoaderException
CacheStore
clear
in interface CacheStore
clear
in class AbstractDelegatingStore
CacheLoaderException
- in the event of problems writing to the storepublic boolean remove(Object key) throws CacheLoaderException
CacheStore
remove
in interface CacheStore
remove
in class AbstractDelegatingStore
key
- key to removeCacheLoaderException
- in the event of problems writing to the storepublic void purgeExpired() throws CacheLoaderException
CacheStore
purgeExpired
in interface CacheStore
purgeExpired
in class AbstractDelegatingStore
CacheLoaderException
- in the event of problems writing to the storepublic void commit(GlobalTransaction tx) throws CacheLoaderException
CacheStore
CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean)
. The implementation would
need to deal with this case accordingly. Typically, this would be a no-op, after ensuring any resources attached
to the transaction are cleared up.
Also note that this method may be invoked on a thread which is different from the CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean)
invocation. As such, ThreadLocal
s should not be relied upon to maintain transaction context.
commit
in interface CacheStore
commit
in class AbstractDelegatingStore
tx
- tx to commitCacheLoaderException
- in the event of problems writing to the storepublic void rollback(GlobalTransaction tx)
CacheStore
CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean)
. The implementation would
need to deal with this case accordingly. Typically, this would be a no-op, after ensuring any resources attached
to the transaction are cleared up.
Also note that this method may be invoked on a thread which is different from the CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean)
invocation. As such, ThreadLocal
s should not be relied upon to maintain transaction context.
rollback
in interface CacheStore
rollback
in class AbstractDelegatingStore
tx
- tx to roll backpublic void prepare(List<? extends Modification> list, GlobalTransaction tx, boolean isOnePhase) throws CacheLoaderException
CacheStore
prepare
in interface CacheStore
prepare
in class AbstractDelegatingStore
list
- modifications to be appliedtx
- transaction identifierisOnePhase
- if true, there will not be a commit or rollback phase and changes should be flushed
immediatelyCacheLoaderException
- in the event of problems writing to the storepublic void start() throws CacheLoaderException
start
in interface CacheLoader
start
in class AbstractDelegatingStore
CacheLoaderException
public void stop() throws CacheLoaderException
stop
in interface CacheLoader
stop
in class AbstractDelegatingStore
CacheLoaderException
protected Callable<?> createPushStateTask()
protected void pushState(Cache<Object,Object> cache) throws Exception
Exception
- if there's any issues reading the data from the cache or pushing data to the cache store.protected void awaitForPushToFinish(Future<?> future, long 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 timeoutprotected void activeStatusChanged(boolean newActiveState) throws SingletonStore.PushStateException
newActiveState
- true if the cache just became the coordinator, false if the cache stopped being the
coordinator.SingletonStore.PushStateException
Copyright © 2014 JBoss, a division of Red Hat. All Rights Reserved.