public class StronglyConsistentCacheAccessor extends EhcacheDecoratorAdapter
The accessor will then lock for all operations:
underlyingCache| Constructor and Description |
|---|
StronglyConsistentCacheAccessor(Ehcache underlyingCache)
Constructor accepting the cache to be decorated.
|
| Modifier and Type | Method and Description |
|---|---|
Element |
get(Object key)
Gets an element from the cache.
|
Element |
get(Serializable key)
Gets an element from the cache.
|
Map<Object,Element> |
getAll(Collection<?> keys)
Gets all the elements from the cache for the keys provided.
|
Map |
getAllWithLoader(Collection keys,
Object loaderArgument)
The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys".
|
Element |
getQuiet(Object key)
Gets an element from the cache, without updating Element statistics.
|
Element |
getQuiet(Serializable key)
Gets an element from the cache, without updating Element statistics.
|
Element |
getWithLoader(Object key,
CacheLoader loader,
Object loaderArgument)
This method will return, from the cache, the object associated with
the argument "key".
|
void |
put(Element element)
Put an element in the cache.
|
void |
put(Element element,
boolean doNotNotifyCacheReplicators)
Put an element in the cache.
|
void |
putAll(Collection<Element> elements)
Puts a collection of elements in to the cache.
|
Element |
putIfAbsent(Element element)
Put an element in the cache if no element is currently mapped to the elements key.
|
Element |
putIfAbsent(Element element,
boolean doNotNotifyCacheReplicators)
Put an element in the cache if no element is currently mapped to the elements key.
|
void |
putQuiet(Element element)
Put an element in the cache, without updating statistics, or updating listeners.
|
void |
putWithWriter(Element element)
Put an element in the cache writing through a CacheWriter.
|
boolean |
remove(Object key)
Removes an
Element from the Cache. |
boolean |
remove(Object key,
boolean doNotNotifyCacheReplicators)
Removes an
Element from the Cache. |
boolean |
remove(Serializable key)
Removes an
Element from the Cache. |
boolean |
remove(Serializable key,
boolean doNotNotifyCacheReplicators)
Removes an
Element from the Cache. |
void |
removeAll(Collection<?> keys)
Removes given set of
Element from the Cache. |
void |
removeAll(Collection<?> keys,
boolean doNotNotifyCacheReplicators)
Removes all cached items.
|
Element |
removeAndReturnElement(Object key)
Removes and returns the element associated with the key
|
boolean |
removeElement(Element element)
Remove the Element mapped to the key for the supplied element if the value of the supplied Element
compares equal to the value of the cached Element.
|
boolean |
removeQuiet(Object key)
Removes an
Element from the Cache, without notifying listeners. |
boolean |
removeQuiet(Serializable key)
Removes an
Element from the Cache, without notifying listeners. |
boolean |
removeWithWriter(Object key)
Removes an
Element from the Cache and any stores it might be in. |
Element |
replace(Element element)
Replace the cached element only if an Element is currently cached for this key
|
boolean |
replace(Element old,
Element element)
Replace the cached element only if the current Element is equal to the supplied old Element.
|
acquireReadLockOnKey, acquireWriteLockOnKey, addPropertyChangeListener, bootstrap, calculateInMemorySize, calculateOffHeapSize, calculateOnDiskSize, clone, createQuery, disableDynamicFeatures, dispose, evictExpiredElements, flush, getBootstrapCacheLoader, getCacheConfiguration, getCacheEventNotificationService, getCacheExceptionHandler, getCacheManager, getDiskStoreSize, getGuid, getInternalContext, getKeys, getKeysNoDuplicateCheck, getKeysWithExpiryCheck, getMemoryStoreSize, getName, getOffHeapStoreSize, getRegisteredCacheExtensions, getRegisteredCacheLoaders, getRegisteredCacheWriter, getSearchAttribute, getSearchAttributes, getSize, getStatistics, getStatus, getWriterManager, hasAbortedSizeOf, initialise, isClusterBulkLoadEnabled, isClusterCoherent, isDisabled, isElementInMemory, isElementInMemory, isElementOnDisk, isElementOnDisk, isExpired, isKeyInCache, isNodeBulkLoadEnabled, isNodeCoherent, isReadLockedByCurrentThread, isSearchable, isValueInCache, isWriteLockedByCurrentThread, load, loadAll, recalculateSize, registerCacheExtension, registerCacheLoader, registerCacheWriter, registerDynamicAttributesExtractor, releaseReadLockOnKey, releaseWriteLockOnKey, removeAll, removeAll, removePropertyChangeListener, setBootstrapCacheLoader, setCacheExceptionHandler, setCacheManager, setDisabled, setName, setNodeBulkLoadEnabled, setNodeCoherent, setTransactionManagerLookup, toString, tryReadLockOnKey, tryWriteLockOnKey, unregisterCacheExtension, unregisterCacheLoader, unregisterCacheWriter, waitUntilClusterBulkLoadComplete, waitUntilClusterCoherentpublic StronglyConsistentCacheAccessor(Ehcache underlyingCache) throws IllegalArgumentException
underlyingCache - a clustered cache configured with eventual consistencyIllegalArgumentException - if the underlying cache is not clustered and has not
eventual consistency.public Element putIfAbsent(Element element, boolean doNotNotifyCacheReplicators) throws NullPointerException
EhcacheputIfAbsent in interface EhcacheputIfAbsent in class EhcacheDecoratorAdapterelement - element to be addeddoNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peersNullPointerException - if the element is null, or has a null keypublic Element putIfAbsent(Element element) throws NullPointerException
EhcacheDecoratorAdapterputIfAbsent in interface EhcacheputIfAbsent in class EhcacheDecoratorAdapterelement - element to be addedNullPointerException - if the element is null, or has a null keypublic boolean replace(Element old, Element element) throws NullPointerException, IllegalArgumentException
EhcacheDecoratorAdapterreplace in interface Ehcachereplace in class EhcacheDecoratorAdapterold - Element to be test againstelement - Element to be cachedNullPointerException - if the either Element is null or has a null keyIllegalArgumentException - if the two Element keys are non-null but not equalpublic Element replace(Element element) throws NullPointerException
EhcacheDecoratorAdapterreplace in interface Ehcachereplace in class EhcacheDecoratorAdapterelement - Element to be cachedNullPointerException - if the Element is null or has a null keypublic boolean removeElement(Element element) throws NullPointerException
EhcacheDecoratorAdapterThis is equivalent to
if (elementValueComparator.equals(cache.get(element.getObjectKey()), element)) {
return cache.remove(element.getObjectKey());
} else return false;
except that the action is performed atomically.removeElement in interface EhcacheremoveElement in class EhcacheDecoratorAdapterelement - Element to be removedtrue if the value was removedNullPointerException - if the element is null, or has a null keyCacheConfiguration.addElementValueComparator(net.sf.ehcache.config.ElementValueComparatorConfiguration)public void put(Element element, boolean doNotNotifyCacheReplicators) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapterResets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener that:
put in interface Ehcacheput in class EhcacheDecoratorAdapterelement - An object. If Serializable it can fully participate in replication and the DiskStore.doNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peersIllegalArgumentException - if the element is nullIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionpublic void put(Element element) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapterResets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener that:
put in interface Ehcacheput in class EhcacheDecoratorAdapterelement - An object. If Serializable it can fully participate in replication and the DiskStore.IllegalArgumentException - if the element is nullIllegalStateException - if the cache is not Status.STATUS_ALIVECacheException - a runtime cache exceptionpublic void putAll(Collection<Element> elements) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapter
This method will throw a NullPointerException if a null element or null key is encountered
in the collection, and a partial completion may result (as only some of the elements may have been put).
For each element that is put the registered CacheEventListeners are notified of a newly put item
(notifyElementPut(...))
regardless of whether the individual put is a new put or an update.
putAll in interface EhcacheputAll in class EhcacheDecoratorAdapterelements - the collection of elements to be put in the cache.IllegalStateException - if the cache is not Status.STATUS_ALIVECacheException - a runtime cache exceptionIllegalArgumentExceptionpublic void putQuiet(Element element) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapterEhcache.getQuiet(java.io.Serializable)putQuiet in interface EhcacheputQuiet in class EhcacheDecoratorAdapterelement - An object. If Serializable it can fully participate in replication and the DiskStore.IllegalArgumentException - if the element is nullIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionpublic void putWithWriter(Element element) throws IllegalArgumentException, IllegalStateException, CacheException
EhcacheDecoratorAdapterResets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener, if the writer operation succeeds, that:
putWithWriter in interface EhcacheputWithWriter in class EhcacheDecoratorAdapterelement - An object. If Serializable it can fully participate in replication and the DiskStore.IllegalArgumentException - if the element is nullIllegalStateException - if the cache is not Status.STATUS_ALIVECacheException - if no CacheWriter was registeredpublic boolean remove(Object key, boolean doNotNotifyCacheReplicators) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache. This also removes it from any
stores it may be in.
Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
remove in interface Ehcacheremove in class EhcacheDecoratorAdapterkey - of the element to removedoNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peersIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic void removeAll(Collection<?> keys) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache. This also removes them from any
stores it may be in. Throws a NullPointerException if any key in the collection is null
Also notifies the CacheEventListener after the elements were removed. Notification is sent for every key irrespective of whether the key was present in the cache or not This operation is partially completed if any element or any key is null
removeAll in interface EhcacheremoveAll in class EhcacheDecoratorAdapterkeys - a collection of keys to operate onIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic boolean remove(Object key) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache. This also removes it from any
stores it may be in.
Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
remove in interface Ehcacheremove in class EhcacheDecoratorAdapterkey - the key of the element to removeIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic void removeAll(Collection<?> keys, boolean doNotNotifyCacheReplicators) throws IllegalStateException
EhcacheDecoratorAdapter
When using Terracotta clustered caches with nonstop enabled, the timeout used by this method is
NonstopConfiguration.getBulkOpsTimeoutMultiplyFactor() times the timeout value in the nonstop config.
removeAll in interface EhcacheremoveAll in class EhcacheDecoratorAdapterkeys - a collection of keys to operate ondoNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer,
in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peersIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic boolean remove(Serializable key, boolean doNotNotifyCacheReplicators) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache. This also removes it from any
stores it may be in.
Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
remove in interface Ehcacheremove in class EhcacheDecoratorAdapterkey - the key of the element to removedoNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peersIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic boolean remove(Serializable key) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache. This also removes it from any
stores it may be in.
Also notifies the CacheEventListener after the element was removed.
remove in interface Ehcacheremove in class EhcacheDecoratorAdapterkey - the key of the element to removeIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic boolean removeQuiet(Object key) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache, without notifying listeners. This also removes it from any
stores it may be in.removeQuiet in interface EhcacheremoveQuiet in class EhcacheDecoratorAdapterkey - of the element to removeIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic boolean removeQuiet(Serializable key) throws IllegalStateException
EhcacheDecoratorAdapterElement from the Cache, without notifying listeners. This also removes it from any
stores it may be in.
removeQuiet in interface EhcacheremoveQuiet in class EhcacheDecoratorAdapterkey - of the element to removeIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic boolean removeWithWriter(Object key) throws IllegalStateException, CacheException
EhcacheDecoratorAdapterElement from the Cache and any stores it might be in. This also removes through
to a CacheWriter. If no CacheWriter has been registered for the cache, then this method throws an exception.
Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
removeWithWriter in interface EhcacheremoveWithWriter in class EhcacheDecoratorAdapterkey - of the element to removeIllegalStateException - if the cache is not Status.STATUS_ALIVECacheException - if no CacheWriter was registeredpublic Element removeAndReturnElement(Object key) throws IllegalStateException
EhcacheDecoratorAdapterremoveAndReturnElement in interface InternalEhcacheremoveAndReturnElement in class EhcacheDecoratorAdapterkey - the key of the element to operate onIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic Element get(Object key) throws IllegalStateException, CacheException
EhcacheDecoratorAdapter
Note that the Element's lastAccessTime is always the time of this get.
Use Ehcache.getQuiet(Object) to peek into the Element to see its last access time with get
get in interface Ehcacheget in class EhcacheDecoratorAdapterkey - an Object valueIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionEhcache.isExpired(net.sf.ehcache.Element)public Map<Object,Element> getAll(Collection<?> keys) throws IllegalStateException, CacheException
EhcacheDecoratorAdapter
Note that the Element's lastAccessTime is always the time of this get.
Use Ehcache.getQuiet(Object) to peek into the Element to see its last access time with get
getAll in interface EhcachegetAll in class EhcacheDecoratorAdapterkeys - a collection of keys for which value is to be fetchedIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionEhcache.isExpired(net.sf.ehcache.Element)public Element get(Serializable key) throws IllegalStateException, CacheException
EhcacheDecoratorAdapter
Note that the Element's lastAccessTime is always the time of this get.
Use Ehcache.getQuiet(Object) to peak into the Element to see its last access time with get
get in interface Ehcacheget in class EhcacheDecoratorAdapterkey - a serializable valueIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionEhcache.isExpired(net.sf.ehcache.Element)public Element getQuiet(Object key) throws IllegalStateException, CacheException
EhcacheDecoratorAdaptergetQuiet in interface EhcachegetQuiet in class EhcacheDecoratorAdapterkey - a serializable valueIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionEhcache.isExpired(net.sf.ehcache.Element)public Element getQuiet(Serializable key) throws IllegalStateException, CacheException
EhcacheDecoratorAdaptergetQuiet in interface EhcachegetQuiet in class EhcacheDecoratorAdapterkey - a serializable valueIllegalStateException - if the cache is not Status.STATUS_ALIVECacheExceptionEhcache.isExpired(net.sf.ehcache.Element)public Element getWithLoader(Object key, CacheLoader loader, Object loaderArgument) throws CacheException
EhcacheDecoratorAdapterIf the object is not in the cache, the associated cache loader will be called. That is either the CacheLoader passed in, or if null, the one associated with the cache. If both are null, no load is performed and null is returned.
Because this method may take a long time to complete, it is not synchronized. The underlying cache operations are synchronized.
getWithLoader in interface EhcachegetWithLoader in class EhcacheDecoratorAdapterkey - key whose associated value is to be returned.loader - the override loader to use. If null, the cache's default loader will be usedloaderArgument - an argument to pass to the CacheLoader.CacheException - a runtime cache exceptionpublic Map getAllWithLoader(Collection keys, Object loaderArgument) throws CacheException
EhcacheDecoratorAdapterNote. If the getAll exceeds the maximum cache size, the returned map will necessarily be less than the number specified.
Because this method may take a long time to complete, it is not synchronized. The underlying cache operations are synchronized.
The constructs package provides similar functionality using the
decorator SelfPopulatingCache
getAllWithLoader in interface EhcachegetAllWithLoader in class EhcacheDecoratorAdapterkeys - a collection of keys to be returned/loadedloaderArgument - an argument to pass to the CacheLoader.CacheException - a runtime cache exceptionCopyright 2001-2021, Terracotta, Inc.