public class NearCache<K,V> extends CachingMap<K,V> implements NamedCache<K,V>, ClassLoaderAware
Invalidation strategies
Modifier and Type | Class and Description |
---|---|
protected class |
NearCache.BackServiceListener
MemberListener for the back cache's service.
|
CachingMap.DeactivationListener, CachingMap.FrontMapListener, CachingMap.PrimingListener, CachingMap.SimpleListener
NamedCache.Option
QueryMap.Entry<K,V>
InvocableMap.Entry<K,V>, InvocableMap.EntryAggregator<K,V,R>, InvocableMap.EntryProcessor<K,V,R>, InvocableMap.ParallelAwareAggregator<K,V,P,R>, InvocableMap.StreamingAggregator<K,V,P,R>
Modifier and Type | Field and Description |
---|---|
protected MemberListener |
f_listenerBackService
The back cache service MemberListener.
|
protected CacheService |
f_service
The back cache service.
|
protected String |
f_sName
The cache name.
|
protected String |
f_sServiceName
The back cache service name.
|
protected boolean |
m_fDestroyed
True if {#link destroy()} has been called on this cache.
|
INVALIDATION_STRATEGY, LISTEN_ALL, LISTEN_AUTO, LISTEN_LOGICAL, LISTEN_NONE, LISTEN_PRESENT, m_listenerDeactivation, m_nStrategyCurrent, m_nStrategyTarget
EXPIRY_DEFAULT, EXPIRY_NEVER
LOCK_ALL
Constructor and Description |
---|
NearCache(Map<K,V> mapFront,
NamedCache<K,V> mapBack)
Construct a NearCache, using a mapBack NamedCache as the
complete (back) storage and mapFront Map as a near (front)
storage using the
CachingMap.LISTEN_AUTO invalidation strategy. |
NearCache(Map<K,V> mapFront,
NamedCache<K,V> mapBack,
int nStrategy)
Construct a NearCache, using a mapBack NamedCache as the
complete (back) storage and mapFront Map as a near (front)
storage.
|
Modifier and Type | Method and Description |
---|---|
<T,E> void |
addIndex(ValueExtractor<? super T,? extends E> extractor,
boolean fOrdered,
Comparator<? super E> comparator)
Add an index to this QueryMap.
|
void |
addMapListener(MapListener<? super K,? super V> listener)
Add a standard map listener.
|
void |
addMapListener(MapListener<? super K,? super V> listener,
Filter filter,
boolean fLite)
Add a map listener that receives events based on a filter evaluation.
|
void |
addMapListener(MapListener<? super K,? super V> listener,
K oKey,
boolean fLite)
Add a map listener for a specific key.
|
<R> R |
aggregate(Collection<? extends K> collKeys,
InvocableMap.EntryAggregator<? super K,? super V,R> aggregator)
Perform an aggregating operation against the entries specified by the
passed keys.
|
<R> R |
aggregate(Filter filter,
InvocableMap.EntryAggregator<? super K,? super V,R> aggregator)
Perform an aggregating operation against the set of entries that are
selected by the given Filter.
|
void |
destroy()
Release and destroy this instance of NamedCollection.
|
Set<Map.Entry<K,V>> |
entrySet(Filter filter)
Return a set view of the entries contained in this map that satisfy the
criteria expressed by the filter.
|
Set<Map.Entry<K,V>> |
entrySet(Filter filter,
Comparator comparator)
Return a set view of the entries contained in this map that satisfy the
criteria expressed by the filter.
|
NamedCache<K,V> |
getBackCache()
Obtain the NamedCache object that sits behind this NearCache.
|
String |
getCacheName()
Return the cache name.
|
CacheService |
getCacheService()
Return the CacheService that this NamedCache is a part of.
|
ClassLoader |
getContextClassLoader()
Retrieve the context ClassLoader for this object.
|
String |
getRegistrationContext()
Obtain the context (tier) used to register a CacheMBean for this cache.
|
<R> R |
invoke(K key,
InvocableMap.EntryProcessor<K,V,R> processor)
Invoke the passed EntryProcessor against the Entry specified by the
passed key, returning the result of the invocation.
|
<R> Map<K,R> |
invokeAll(Collection<? extends K> collKeys,
InvocableMap.EntryProcessor<K,V,R> processor)
Invoke the passed EntryProcessor against the entries specified by the
passed keys, returning the result of the invocation for each.
|
<R> Map<K,R> |
invokeAll(Filter filter,
InvocableMap.EntryProcessor<K,V,R> processor)
Invoke the passed EntryProcessor against the set of entries that are
selected by the given Filter, returning the result of the invocation for
each.
|
boolean |
isActive()
Specifies whether or not the NamedCache is active.
|
boolean |
isDestroyed()
Specifies whether or not the NamedCache has been destroyed.
|
boolean |
isReleased()
Specifies whether or not the NamedCache has been released.
|
Set<K> |
keySet(Filter filter)
Return a set view of the keys contained in this map for entries that
satisfy the criteria expressed by the filter.
|
boolean |
lock(Object oKey)
Attempt to lock the specified item and return immediately.
|
boolean |
lock(Object oKey,
long lMillis)
Attempt to lock the specified item within the specified period of time.
|
V |
put(K oKey,
V oValue,
long cMillis)
Associates the specified value with the specified key in this cache and
allows to specify an expiry for the cache entry.
|
protected MemberListener |
registerBackServiceListener()
Instantiate and register a MemberListener with the back cache
service.
|
void |
registerMBean()
Register an MBean representing this NearCache.
|
void |
release()
Release the CachingMap.
|
protected void |
release(boolean fDestroy)
Release this cache, optionally destroying it.
|
<T,E> void |
removeIndex(ValueExtractor<? super T,? extends E> extractor)
Remove an index from this QueryMap.
|
void |
removeMapListener(MapListener<? super K,? super V> listener)
Remove a standard map listener.
|
void |
removeMapListener(MapListener<? super K,? super V> listener,
Filter filter)
Remove a map listener that previously signed up for events based on a
filter evaluation.
|
void |
removeMapListener(MapListener<? super K,? super V> listener,
K oKey)
Remove a map listener that previously signed up for events about a
specific key.
|
void |
setContextClassLoader(ClassLoader loader)
Specify the context ClassLoader for this object.
|
void |
setRegistrationContext(String sCtx)
Set the context (tier) used to register a CacheMBean for this cache.
|
void |
truncate()
Removes all mappings from this map.
|
boolean |
unlock(Object oKey)
Unlock the specified item.
|
protected void |
unregisterBackServiceListener()
Unregister back cache service member listener.
|
protected void |
unregisterMBean()
Unregister an associated CacheMBean.
|
clear, containsKey, containsValue, ensureInvalidationStrategy, entrySet, get, getAll, getAllFromFrontMap, getBackMap, getCacheStatistics, getControlMap, getFrontMap, getInvalidationHits, getInvalidationMisses, getInvalidationStrategy, getInvalidationStrategy, getTotalRegisterListener, instantiateBackMapListener, instantiateFrontMapListener, invalidateFront, isCheckPrimingExclusively, isCoherent, isEmpty, isPriming, keySet, put, put, putAll, registerDeactivationListener, registerFrontListener, registerListener, registerListener, registerListeners, remove, removeKeyHolder, resetFrontMap, resetInvalidationStrategy, setKeyHolder, size, toString, tryLock, unregisterDeactivationListener, unregisterFrontListener, unregisterListener, unregisterListener, unregisterListeners, validate, values
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
as, async, async, clear, getName, getService, view
close
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
containsKey, containsValue, get, isEmpty, put, putAll, remove, size
aggregate, compute, compute, computeIfAbsent, computeIfAbsent, computeIfPresent, computeIfPresent, getOrDefault, invokeAll, merge, merge, putIfAbsent, remove, replace, replace, replaceAll, replaceAll, replaceAll, replaceAll, stream, stream, stream, stream, stream, stream
protected boolean m_fDestroyed
protected final String f_sName
protected final CacheService f_service
protected final MemberListener f_listenerBackService
protected final String f_sServiceName
public NearCache(Map<K,V> mapFront, NamedCache<K,V> mapBack)
CachingMap.LISTEN_AUTO
invalidation strategy.mapFront
- Map to put in front of the back cachemapBack
- NamedCache to put behind the front cachepublic NearCache(Map<K,V> mapFront, NamedCache<K,V> mapBack, int nStrategy)
mapFront
- Map to put in front of the back cachemapBack
- NamedCache to put behind the front cachenStrategy
- specifies the strategy used for the front map
invalidation; valid values are:LISTEN_NONE
,
LISTEN_PRESENT
,
LISTEN_ALL
,
LISTEN_AUTO
public NamedCache<K,V> getBackCache()
IllegalStateException
- if this NamedCache has been releasedpublic String getRegistrationContext()
public void setRegistrationContext(String sCtx)
sCtx
- the corresponding context stringpublic String getCacheName()
getCacheName
in interface NamedCache<K,V>
public CacheService getCacheService()
getCacheService
in interface NamedCache<K,V>
public boolean isActive()
isActive
in interface Releasable
public void release()
release
in interface Releasable
release
in class CachingMap<K,V>
public void destroy()
Warning: This method is used to completely destroy the specified collection across the cluster. All references in the entire cluster to this collection will be invalidated, the collection data will be cleared, and all internal resources will be released.
destroy
in interface NamedCollection
public void truncate()
Note: the removal of entries caused by this truncate operation will
not be observable. This includes any registered listeners
, triggers
, or interceptors
. However, a
CacheLifecycleEvent
is raised to notify subscribers of the execution of this operation.
truncate
in interface NamedCache<K,V>
public boolean isDestroyed()
isDestroyed
in interface NamedCache<K,V>
public boolean isReleased()
isReleased
in interface NamedCache<K,V>
public void addMapListener(MapListener<? super K,? super V> listener)
addMapListener
in interface ObservableMap<K,V>
listener
- the MapEvent listener to addpublic void removeMapListener(MapListener<? super K,? super V> listener)
removeMapListener
in interface ObservableMap<K,V>
listener
- the MapEvent listener to removepublic void addMapListener(MapListener<? super K,? super V> listener, K oKey, boolean fLite)
addMapListener
in interface ObservableMap<K,V>
listener
- the listener to addoKey
- the key that identifies the entry for which to raise
eventsfLite
- true to indicate that the MapEvent objects do
not have to include the OldValue and NewValue
property values in order to allow optimizationspublic void removeMapListener(MapListener<? super K,? super V> listener, K oKey)
removeMapListener
in interface ObservableMap<K,V>
listener
- the listener to removeoKey
- the key that identifies the entry for which to raise
eventspublic void addMapListener(MapListener<? super K,? super V> listener, Filter filter, boolean fLite)
addMapListener
in interface ObservableMap<K,V>
listener
- the listener to addfilter
- a filter that will be passed MapEvent objects to
select from; a MapEvent will be delivered to the
listener only if the filter evaluates to true for
that MapEvent; null is equivalent to a filter
that always returns truefLite
- true to indicate that the MapEvent objects do
not have to include the OldValue and NewValue
property values in order to allow optimizationspublic void removeMapListener(MapListener<? super K,? super V> listener, Filter filter)
removeMapListener
in interface ObservableMap<K,V>
listener
- the listener to removefilter
- a filter used to evaluate eventspublic V put(K oKey, V oValue, long cMillis)
put
in interface CacheMap<K,V>
put
in interface NamedCache<K,V>
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keycMillis
- the number of milliseconds until the cache entry will
expireUnsupportedOperationException
- if the requested expiry is a
positive value and either the front map or the back map
implementations do not support the expiration functionalityCacheMap.put(Object oKey, Object oValue, long cMillis)
public boolean lock(Object oKey)
lock
in interface ConcurrentMap<K,V>
oKey
- key being lockedpublic boolean lock(Object oKey, long lMillis)
lock
in interface ConcurrentMap<K,V>
oKey
- key being lockedlMillis
- the number of milliseconds to continue trying to obtain
a lock; pass zero to return immediately; pass -1 to block
the calling thread until the lock could be obtainedpublic boolean unlock(Object oKey)
unlock
in interface ConcurrentMap<K,V>
oKey
- key being unlockedpublic Set<K> keySet(Filter filter)
Unlike the Map.keySet()
method, the set returned by this method may
not be backed by the map, so changes to the set may not reflected in the
map, and vice-versa.
Note: When using the Coherence Enterprise Edition or Grid Edition, the Partitioned Cache implements the QueryMap interface using the Parallel Query feature. When using Coherence Standard Edition, the Parallel Query feature is not available, resulting in lower performance for most queries, and particularly when querying large data sets.
The operation always executes against the back cache.
public Set<Map.Entry<K,V>> entrySet(Filter filter)
Map.Entry
.
Unlike the Map.entrySet()
method, the set returned by this method
may not be backed by the map, so changes to the set may not be reflected
in the map, and vice-versa.
Note: When using the Coherence Enterprise Edition or Grid Edition, the Partitioned Cache implements the QueryMap interface using the Parallel Query feature. When using Coherence Standard Edition, the Parallel Query feature is not available, resulting in lower performance for most queries, and particularly when querying large data sets.
The operation always executes against the back cache.
public Set<Map.Entry<K,V>> entrySet(Filter filter, Comparator comparator)
Map.Entry
. It is further guaranteed that its iterator
will traverse the set in such a way that the entry values come up in
ascending order, sorted by the specified Comparator or according to the
natural ordering (see Comparable
).
Unlike the Map.entrySet()
method, the set returned by this method
may not be backed by the map, so changes to the set may not be reflected
in the map, and vice-versa.
Note: When using the Coherence Enterprise Edition or Grid Edition, the Partitioned Cache implements the QueryMap interface using the Parallel Query feature. When using Coherence Standard Edition, the Parallel Query feature is not available, resulting in lower performance for most queries, and particularly when querying large data sets.
The operation always executes against the back cache.
entrySet
in interface QueryMap<K,V>
filter
- the Filter object representing the criteria that the
entries of this map should satisfycomparator
- the Comparator object which imposes an ordering on
entries in the resulting set; or null if the
entries' values natural ordering should be usedChainedComparator
public <T,E> void addIndex(ValueExtractor<? super T,? extends E> extractor, boolean fOrdered, Comparator<? super E> comparator)
The ordering maintained by this map (as determined by either the
specified Comparator or the natural ordering of the indexed values) must
be consistent with equals (see Comparable
or Comparator
for a precise definition of consistent with equals.)
This method is only intended as a hint to the cache implementation, and as such it may be ignored by the cache if indexes are not supported or if the desired index (or a similar index) already exists. It is expected that an application will call this method to suggest an index even if the index may already exist, just so that the application is certain that index has been suggested. For example in a distributed environment, each server will likely suggest the same set of indexes when it starts, and there is no downside to the application blindly requesting those indexes regardless of whether another server has already requested the same indexes.
Note: Indexes are a feature of Coherence Enterprise Edition and Coherence Grid Edition. This method will have no effect when using Coherence Standard Edition.
The operation always executes against the back cache.
addIndex
in interface QueryMap<K,V>
T
- the type of the value to extract fromE
- the type of value that will be extractedextractor
- the ValueExtractor object that is used to extract an
indexable Object from a value stored in the indexed
Map. Must not be null.fOrdered
- true iff the contents of the indexed information should
be ordered; false otherwisecomparator
- the Comparator object which imposes an ordering on
entries in the indexed map; or null if the
entries' values natural ordering should be usedReflectionExtractor
,
ChainedComparator
public <T,E> void removeIndex(ValueExtractor<? super T,? extends E> extractor)
The operation always executes against the back cache.
removeIndex
in interface QueryMap<K,V>
T
- the type of the value to extract fromE
- the type of value that will be extractedextractor
- the ValueExtractor object that is used to extract an
indexable Object from a value stored in the Map.public <R> R invoke(K key, InvocableMap.EntryProcessor<K,V,R> processor)
The operation always executes against the back cache.
invoke
in interface InvocableMap<K,V>
R
- the type of value returned by the EntryProcessorkey
- the key to process; it is not required to exist within
the Mapprocessor
- the EntryProcessor to use to process the specified keypublic <R> Map<K,R> invokeAll(Collection<? extends K> collKeys, InvocableMap.EntryProcessor<K,V,R> processor)
The operation always executes against the back cache.
invokeAll
in interface InvocableMap<K,V>
R
- the type of value returned by the EntryProcessorcollKeys
- the keys to process; these keys are not required to
exist within the Mapprocessor
- the EntryProcessor to use to process the specified keyspublic <R> Map<K,R> invokeAll(Filter filter, InvocableMap.EntryProcessor<K,V,R> processor)
Unless specified otherwise, InvocableMap implementations will perform
this operation in two steps: (1) use the filter to retrieve a matching
entry set; (2) apply the agent to every filtered entry. This algorithm
assumes that the agent's processing does not affect the result of the
specified filter evaluation, since the filtering and processing could be
performed in parallel on different threads. If this assumption does not
hold, the processor logic has to be idempotent, or at least re-evaluate
the filter. This could be easily accomplished by wrapping the processor
with the ConditionalProcessor
.
The operation always executes against the back cache.
invokeAll
in interface InvocableMap<K,V>
R
- the type of value returned by the EntryProcessorfilter
- a Filter that results in the set of keys to be
processedprocessor
- the EntryProcessor to use to process the specified keyspublic <R> R aggregate(Collection<? extends K> collKeys, InvocableMap.EntryAggregator<? super K,? super V,R> aggregator)
The operation always executes against the back cache.
aggregate
in interface InvocableMap<K,V>
R
- the type of value returned by the EntryAggregatorcollKeys
- the Collection of keys that specify the entries within
this Map to aggregate acrossaggregator
- the EntryAggregator that is used to aggregate across
the specified entries of this Mappublic <R> R aggregate(Filter filter, InvocableMap.EntryAggregator<? super K,? super V,R> aggregator)
The operation always executes against the back cache.
aggregate
in interface InvocableMap<K,V>
R
- the type of value returned by the EntryAggregatorfilter
- the Filter that is used to select entries within this
Map to aggregate acrossaggregator
- the EntryAggregator that is used to aggregate across
the selected entries of this Mapprotected void release(boolean fDestroy)
fDestroy
- true to destroy the cache as wellprotected MemberListener registerBackServiceListener()
The primary goal of that listener is invalidation of the front map in case of the service [automatic] restart.
protected void unregisterBackServiceListener()
public void registerMBean()
protected void unregisterMBean()
unregisterMBean
in class CachingMap<K,V>
public ClassLoader getContextClassLoader()
getContextClassLoader
in interface ClassLoaderAware
Thread.getContextClassLoader()
public void setContextClassLoader(ClassLoader loader)
setContextClassLoader
in interface ClassLoaderAware
loader
- the context ClassLoader for this object