L - the type of the locking key returned by
getLockFromKey(Object)public abstract class LockSupportCacheStore<L> extends AbstractCacheStore
AbstractCacheStore adding lock support for consistently accessing stored data.
In-memory locking is needed by aggregation operations(e.g. loadAll, toStream, fromStream) to make sure that
manipulated data won't be corrupted by concurrent access to Store. It also assures atomic data access for each stored
entry.
Locking is based on a StripedLock. You can tune the concurrency level of the striped lock (see the Javadocs
of StripedLock for details on what this is) by using the LockSupportCacheStoreConfig.setLockConcurrencyLevel(int)
setter.
multiThreadedPurge, purgerServicecache, marshaller| Constructor and Description |
|---|
LockSupportCacheStore() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acquireGlobalLock(boolean exclusive)
Based on the supplied param, acquires a global read(false) or write (true) lock.
|
void |
clear()
Clears all entries in the store
|
protected abstract void |
clearLockSafe() |
protected void |
downgradeLock(L key)
Downgrade a write lock to a read lock
|
void |
fromStream(ObjectInput objectInput)
Writes contents of the stream to the store.
|
protected abstract void |
fromStreamLockSafe(ObjectInput ois) |
protected abstract L |
getLockFromKey(Object key) |
int |
getTotalLockCount() |
protected boolean |
immediateLockForWriting(L key)
Same as
lockForWriting(Object), but with 0 timeout. |
void |
init(CacheLoaderConfig config,
Cache<?,?> cache,
StreamingMarshaller m)
Used to initialize a cache loader.
|
Set<InternalCacheEntry> |
load(int maxEntries)
Loads up to a specific number of entries.
|
InternalCacheEntry |
load(Object key)
Loads an entry mapped to by a given key.
|
Set<InternalCacheEntry> |
loadAll()
Loads all entries in the loader.
|
Set<Object> |
loadAllKeys(Set<Object> keysToExclude)
Loads a set of all keys, excluding a filter set.
|
protected abstract Set<Object> |
loadAllKeysLockSafe(Set<Object> keysToExclude) |
protected abstract Set<InternalCacheEntry> |
loadAllLockSafe() |
protected abstract Set<InternalCacheEntry> |
loadLockSafe(int maxEntries) |
protected abstract InternalCacheEntry |
loadLockSafe(Object key,
L lockingKey) |
protected void |
lockForReading(L key)
Acquires read lock on the given key.
|
protected void |
lockForWriting(L key)
Acquires write lock on the given key.
|
protected void |
releaseGlobalLock(boolean exclusive)
Based on the supplied param, releases a global read(false) or write (true) lock.
|
boolean |
remove(Object key)
Removes an entry in the store.
|
protected abstract boolean |
removeLockSafe(Object key,
L lockingKey) |
void |
start() |
void |
store(InternalCacheEntry ed)
Stores an entry
|
protected abstract void |
storeLockSafe(InternalCacheEntry ed,
L lockingKey) |
void |
toStream(ObjectOutput objectOutput)
Loads the entire state into a stream, using whichever format is most efficient for the cache loader
implementation.
|
protected abstract void |
toStreamLockSafe(ObjectOutput oos) |
protected void |
unlock(L key)
Release the locks (either read or write).
|
protected void |
upgradeLock(L key)
Upgrades a read lock to a write lock.
|
applyModifications, commit, getCacheStoreConfig, getConcurrencyLevel, getMarshaller, prepare, purgeExpired, purgeInternal, removeAll, rollback, safeClose, safeClose, stop, supportsMultiThreadedPurgecontainsKeyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcontainsKey, getConfigurationClasspublic void init(CacheLoaderConfig config, Cache<?,?> cache, StreamingMarshaller m) throws CacheLoaderException
CacheLoaderCacheLoaderManager
when setting up cache loaders.init in interface CacheLoaderinit in class AbstractCacheStoreconfig - the cache loader configuration beancache - cache associated with this cache loader. Implementations may use this to determine cache name when
selecting where refer to state in storage, for example, a different database table name.m - marshaller to use when loading state from a stream, if supported by the implementation.CacheLoaderExceptionpublic void start()
throws CacheLoaderException
start in interface CacheLoaderstart in class AbstractCacheStoreCacheLoaderExceptionprotected final void unlock(L key)
protected final void lockForWriting(L key)
protected final void lockForReading(L key)
protected final void upgradeLock(L key)
protected final void downgradeLock(L key)
protected final boolean immediateLockForWriting(L key)
lockForWriting(Object), but with 0 timeout.protected final boolean acquireGlobalLock(boolean exclusive)
protected final void releaseGlobalLock(boolean exclusive)
public final InternalCacheEntry load(Object key) throws CacheLoaderException
CacheLoaderkey - keyCacheLoaderException - in the event of problems reading from sourcepublic final Set<InternalCacheEntry> loadAll() throws CacheLoaderException
CacheLoaderCacheLoaderException - in the event of problems reading from sourcepublic final Set<InternalCacheEntry> load(int maxEntries) throws CacheLoaderException
CacheLoadermaxEntries - maximum number of entries to loadCacheLoaderExceptionpublic Set<Object> loadAllKeys(Set<Object> keysToExclude) throws CacheLoaderException
CacheLoaderkeysToExclude - a set of keys to exclude. An empty set or null will indicate that all keys should be returned.CacheLoaderExceptionpublic final void store(InternalCacheEntry ed) throws CacheLoaderException
CacheStoreed - entry to storeCacheLoaderException - in the event of problems writing to the storepublic final boolean remove(Object key) throws CacheLoaderException
CacheStorekey - key to removeCacheLoaderException - in the event of problems writing to the storepublic final void fromStream(ObjectInput objectInput) throws CacheLoaderException
CacheStoreCacheStore.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.
objectInput - stream to read fromCacheLoaderException - in the event of problems writing to the storepublic void toStream(ObjectOutput objectOutput) throws CacheLoaderException
CacheStoreCacheStore.fromStream(java.io.ObjectInput).
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 flush or 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 in CacheStore.fromStream(java.io.ObjectInput) should be employed, 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.
objectOutput - stream to write toCacheLoaderException - in the event of problems reading from the storepublic final void clear()
throws CacheLoaderException
CacheStoreCacheLoaderException - in the event of problems writing to the storepublic int getTotalLockCount()
protected abstract void clearLockSafe()
throws CacheLoaderException
CacheLoaderExceptionprotected abstract Set<InternalCacheEntry> loadAllLockSafe() throws CacheLoaderException
CacheLoaderExceptionprotected abstract Set<InternalCacheEntry> loadLockSafe(int maxEntries) throws CacheLoaderException
CacheLoaderExceptionprotected abstract Set<Object> loadAllKeysLockSafe(Set<Object> keysToExclude) throws CacheLoaderException
CacheLoaderExceptionprotected abstract void toStreamLockSafe(ObjectOutput oos) throws CacheLoaderException
CacheLoaderExceptionprotected abstract void fromStreamLockSafe(ObjectInput ois) throws CacheLoaderException
CacheLoaderExceptionprotected abstract boolean removeLockSafe(Object key, L lockingKey) throws CacheLoaderException
CacheLoaderExceptionprotected abstract void storeLockSafe(InternalCacheEntry ed, L lockingKey) throws CacheLoaderException
CacheLoaderExceptionprotected abstract InternalCacheEntry loadLockSafe(Object key, L lockingKey) throws CacheLoaderException
CacheLoaderExceptionprotected abstract L getLockFromKey(Object key) throws CacheLoaderException
CacheLoaderExceptionCopyright © 2012 JBoss by Red Hat. All Rights Reserved.