Class ConverterCollections.ConverterNamedCache<FK,TK,FV,TV>
- java.lang.Object
-
- com.tangosol.util.ConverterCollections.ConverterMap<FK,TK,FV,TV>
-
- com.tangosol.util.ConverterCollections.ConverterObservableMap<FK,TK,FV,TV>
-
- com.tangosol.util.ConverterCollections.ConverterCacheMap<FK,TK,FV,TV>
-
- com.tangosol.util.ConverterCollections.ConverterNamedCache<FK,TK,FV,TV>
-
- All Implemented Interfaces:
CacheMap<TK,TV>
,NamedCache<TK,TV>
,NamedCollection
,NamedMap<TK,TV>
,Releasable
,ConcurrentMap<TK,TV>
,InvocableMap<TK,TV>
,ObservableMap<TK,TV>
,QueryMap<TK,TV>
,Serializable
,AutoCloseable
,Map<TK,TV>
- Enclosing class:
- ConverterCollections
public static class ConverterCollections.ConverterNamedCache<FK,TK,FV,TV> extends ConverterCollections.ConverterCacheMap<FK,TK,FV,TV> implements NamedCache<TK,TV>, Serializable
A Converter NamedCache views an underlying NamedCache through a set of key and value Converters.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.tangosol.util.InvocableMap
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>
-
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K extends Object,V extends Object>
-
Nested classes/interfaces inherited from interface com.tangosol.net.NamedMap
NamedMap.Option
-
Nested classes/interfaces inherited from interface com.tangosol.util.QueryMap
QueryMap.Entry<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected ConcurrentMap<TK,TV>
m_mapConcurrent
A Converter ConcurrentMap around the underlying NamedCache.protected InvocableMap<TK,TV>
m_mapInvocable
A Converter InvocableMap around the underlying NamedCache.protected QueryMap<TK,TV>
m_mapQuery
A Converter QueryMap around the underlying NamedCache.-
Fields inherited from class com.tangosol.util.ConverterCollections.ConverterMap
m_convKeyDown, m_convKeyUp, m_convValDown, m_convValUp, m_map, m_set
-
Fields inherited from interface com.tangosol.net.cache.CacheMap
EXPIRY_DEFAULT, EXPIRY_NEVER
-
Fields inherited from interface com.tangosol.util.ConcurrentMap
LOCK_ALL
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T,E>
voidaddIndex(ValueExtractor<? super T,? extends E> extractor, boolean fOrdered, Comparator<? super E> comparator)
Add an index to this QueryMap.<R> R
aggregate(Filter filter, InvocableMap.EntryAggregator<? super TK,? super TV,R> agent)
Perform an aggregating operation against the set of entries that are selected by the given Filter.<R> R
aggregate(Collection<? extends TK> collKeys, InvocableMap.EntryAggregator<? super TK,? super TV,R> agent)
Perform an aggregating operation against the entries specified by the passed keys.void
destroy()
Release and destroy this instance of NamedCollection.Set<Map.Entry<TK,TV>>
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<TK,TV>>
entrySet(Filter filter, Comparator comparator)
Return a set view of the entries contained in this map that satisfy the criteria expressed by the filter.String
getCacheName()
Return the cache name.CacheService
getCacheService()
Return the CacheService that this NamedCache is a part of.NamedCache<FK,FV>
getNamedCache()
Return the underlying NamedCache.<R> R
invoke(TK key, InvocableMap.EntryProcessor<TK,TV,R> agent)
Invoke the passed EntryProcessor against the Entry specified by the passed key, returning the result of the invocation.<R> Map<TK,R>
invokeAll(Filter filter, InvocableMap.EntryProcessor<TK,TV,R> agent)
Invoke the passed EntryProcessor against the set of entries that are selected by the given Filter, returning the result of the invocation for each.<R> Map<TK,R>
invokeAll(Collection<? extends TK> collKeys, InvocableMap.EntryProcessor<TK,TV,R> agent)
Invoke the passed EntryProcessor against the entries specified by the passed keys, returning the result of the invocation for each.boolean
isActive()
Returnstrue
if this map is not released or destroyed.boolean
isDestroyed()
Specifies whether or not this NamedCollection has been destroyed.boolean
isReady()
Returns whether thisNamedMap
is ready to be used.boolean
isReleased()
Specifies whether or this Releasable has been released.Set<TK>
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 cWait)
Attempt to lock the specified item within the specified period of time.TV
merge(TK key, TV value, Remote.BiFunction<? super TV,? super TV,? extends TV> remappingFunction)
If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.TV
merge(TK key, TV value, BiFunction<? super TV,? super TV,? extends TV> remappingFunction)
TV
putIfAbsent(TK key, TV value)
void
release()
Release local resources associated with this Releasable instance.boolean
remove(Object key, Object value)
<T,E>
voidremoveIndex(ValueExtractor<? super T,? extends E> extractor)
Remove an index from this QueryMap.TV
replace(TK key, TV value)
boolean
replace(TK key, TV oldValue, TV newValue)
void
truncate()
Removes all mappings from this map.boolean
unlock(Object oKey)
Unlock the specified item.-
Methods inherited from class com.tangosol.util.ConverterCollections.ConverterCacheMap
getAll, getCacheMap, put
-
Methods inherited from class com.tangosol.util.ConverterCollections.ConverterObservableMap
addMapListener, addMapListener, addMapListener, getConverterListener, getObservableMap, removeMapListener, removeMapListener, removeMapListener
-
Methods inherited from class com.tangosol.util.ConverterCollections.ConverterMap
clear, containsKey, containsValue, entrySet, equals, get, getConverterKeyDown, getConverterKeyUp, getConverterValueDown, getConverterValueUp, getMap, hashCode, instantiateCollection, instantiateEntrySet, instantiateMap, instantiateSet, isEmpty, keySet, put, putAll, remove, size, subMap, toString, values
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tangosol.util.ConcurrentMap
containsKey, containsValue, get, isEmpty, put, putAll, remove, size
-
Methods inherited from interface com.tangosol.util.InvocableMap
aggregate, compute, compute, computeIfAbsent, computeIfAbsent, computeIfPresent, computeIfPresent, getOrDefault, invokeAll, replaceAll, replaceAll, replaceAll, replaceAll, stream, stream, stream, stream, stream, stream
-
Methods inherited from interface com.tangosol.net.NamedMap
clear, getAll, getName, getService
-
Methods inherited from interface com.tangosol.util.ObservableMap
addMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListener
-
Methods inherited from interface com.tangosol.util.QueryMap
addIndex, forEach, forEach, values, values
-
Methods inherited from interface com.tangosol.net.Releasable
close
-
-
-
-
Field Detail
-
m_mapConcurrent
protected ConcurrentMap<TK,TV> m_mapConcurrent
A Converter ConcurrentMap around the underlying NamedCache.
-
m_mapInvocable
protected InvocableMap<TK,TV> m_mapInvocable
A Converter InvocableMap around the underlying NamedCache.
-
-
Constructor Detail
-
ConverterNamedCache
public ConverterNamedCache(NamedCache<FK,FV> cache, Converter<FK,TK> convKeyUp, Converter<TK,FK> convKeyDown, Converter<FV,TV> convValUp, Converter<TV,FV> convValDown)
Constructor.- Parameters:
cache
- the underlying NamedCacheconvKeyUp
- the Converter to view the underlying NamedCache's keys throughconvKeyDown
- the Converter to use to pass keys down to the underlying NamedCacheconvValUp
- the Converter to view the underlying NamedCache's values throughconvValDown
- the Converter to use to pass values down to the underlying NamedCache
-
-
Method Detail
-
getCacheName
public String getCacheName()
Return the cache name.- Specified by:
getCacheName
in interfaceNamedCache<FK,TK>
- Returns:
- the cache name
-
getCacheService
public CacheService getCacheService()
Return the CacheService that this NamedCache is a part of.- Specified by:
getCacheService
in interfaceNamedCache<FK,TK>
- Returns:
- the CacheService
-
isActive
public boolean isActive()
Returnstrue
if this map is not released or destroyed. In other words, callingisActive()
is equivalent to calling!cache.isReleased() && !cache.isDestroyed()
.
-
isReady
public boolean isReady()
Description copied from interface:NamedMap
Returns whether thisNamedMap
is ready to be used. An example of when this method would returnfalse
would be where a partitioned cache service that owns this cache has no storage-enabled members.
-
release
public void release()
Release local resources associated with this Releasable instance.- Specified by:
release
in interfaceReleasable
-
destroy
public void destroy()
Release and destroy this instance of NamedCollection.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.
- Specified by:
destroy
in interfaceNamedCollection
-
truncate
public void truncate()
Removes all mappings from this map.Note: the removal of entries caused by this truncate operation will not be observable. This includes any registered
listeners
,triggers
, orinterceptors
. However, aCacheLifecycleEvent
is raised to notify subscribers of the execution of this operation.
-
isDestroyed
public boolean isDestroyed()
Specifies whether or not this NamedCollection has been destroyed. Implementations must override this method to provide the necessary information.- Specified by:
isDestroyed
in interfaceNamedCollection
- Returns:
- true if the NamedCollection has been destroyed; false otherwise
-
isReleased
public boolean isReleased()
Specifies whether or this Releasable has been released. Implementations must override this method to provide the necessary information.- Specified by:
isReleased
in interfaceReleasable
- Returns:
- true if the Releasable has been released; false otherwise
-
lock
public boolean lock(Object oKey, long cWait)
Attempt to lock the specified item within the specified period of time.The item doesn't have to exist to be locked. While the item is locked there is known to be a lock holder which has an exclusive right to modify (calling put and remove methods) that item.
Lock holder is an abstract concept that depends on the ConcurrentMap implementation. For example, holder could be a cluster member or a thread (or both).
Locking strategy may vary for concrete implementations as well. Lock could have an expiration time (this lock is sometimes called a "lease") or be held indefinitely (until the lock holder terminates).
Some implementations may allow the entire map to be locked. If the map is locked in such a way, then only a lock holder is allowed to perform any of the "put" or "remove" operations. Pass the special constant
ConcurrentMap.LOCK_ALL
as the oKey parameter to indicate the map lock.- Specified by:
lock
in interfaceConcurrentMap<FK,TK>
- Parameters:
oKey
- key being lockedcWait
- 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 obtained- Returns:
- true if the item was successfully locked within the specified time; false otherwise
-
lock
public boolean lock(Object oKey)
Attempt to lock the specified item and return immediately.This method behaves exactly as if it simply performs the call lock(oKey, 0).
- Specified by:
lock
in interfaceConcurrentMap<FK,TK>
- Parameters:
oKey
- key being locked- Returns:
- true if the item was successfully locked; false otherwise
-
unlock
public boolean unlock(Object oKey)
Unlock the specified item. The item doesn't have to exist to be unlocked. If the item is currently locked, only the holder of the lock could successfully unlock it.- Specified by:
unlock
in interfaceConcurrentMap<FK,TK>
- Parameters:
oKey
- key being unlocked- Returns:
- true if the item was successfully unlocked; false otherwise
-
invoke
public <R> R invoke(TK key, InvocableMap.EntryProcessor<TK,TV,R> agent)
Invoke the passed EntryProcessor against the Entry specified by the passed key, returning the result of the invocation.- Specified by:
invoke
in interfaceInvocableMap<FK,TK>
- Type Parameters:
R
- the type of value returned by the EntryProcessor- Parameters:
key
- the key to process; it is not required to exist within the Mapagent
- the EntryProcessor to use to process the specified key- Returns:
- the result of the invocation as returned from the EntryProcessor
-
invokeAll
public <R> Map<TK,R> invokeAll(Collection<? extends TK> collKeys, InvocableMap.EntryProcessor<TK,TV,R> agent)
Invoke the passed EntryProcessor against the entries specified by the passed keys, returning the result of the invocation for each.- Specified by:
invokeAll
in interfaceInvocableMap<FK,TK>
- Type Parameters:
R
- the type of value returned by the EntryProcessor- Parameters:
collKeys
- the keys to process; these keys are not required to exist within the Mapagent
- the EntryProcessor to use to process the specified keys- Returns:
- a Map containing the results of invoking the EntryProcessor against each of the specified keys
-
invokeAll
public <R> Map<TK,R> invokeAll(Filter filter, InvocableMap.EntryProcessor<TK,TV,R> agent)
Invoke the passed EntryProcessor against the set of entries that are selected by the given Filter, returning the result of the invocation for each.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
.- Specified by:
invokeAll
in interfaceInvocableMap<FK,TK>
- Type Parameters:
R
- the type of value returned by the EntryProcessor- Parameters:
filter
- a Filter that results in the set of keys to be processedagent
- the EntryProcessor to use to process the specified keys- Returns:
- a Map containing the results of invoking the EntryProcessor against the keys that are selected by the given Filter
-
aggregate
public <R> R aggregate(Collection<? extends TK> collKeys, InvocableMap.EntryAggregator<? super TK,? super TV,R> agent)
Perform an aggregating operation against the entries specified by the passed keys.- Specified by:
aggregate
in interfaceInvocableMap<FK,TK>
- Type Parameters:
R
- the type of value returned by the EntryAggregator- Parameters:
collKeys
- the Collection of keys that specify the entries within this Map to aggregate acrossagent
- the EntryAggregator that is used to aggregate across the specified entries of this Map- Returns:
- the result of the aggregation
-
aggregate
public <R> R aggregate(Filter filter, InvocableMap.EntryAggregator<? super TK,? super TV,R> agent)
Perform an aggregating operation against the set of entries that are selected by the given Filter.- Specified by:
aggregate
in interfaceInvocableMap<FK,TK>
- Type Parameters:
R
- the type of value returned by the EntryAggregator- Parameters:
filter
- the Filter that is used to select entries within this Map to aggregate acrossagent
- the EntryAggregator that is used to aggregate across the selected entries of this Map- Returns:
- the result of the aggregation
-
keySet
public Set<TK> keySet(Filter filter)
Return a set view of the keys contained in this map for entries that satisfy the criteria expressed by the 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: The Partitioned Cache implements the QueryMap interface using the Parallel Query feature.
-
entrySet
public Set<Map.Entry<TK,TV>> entrySet(Filter filter)
Return a set view of the entries contained in this map that satisfy the criteria expressed by the filter. Each element in the returned set is aMap.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: The Partitioned Cache implements the QueryMap interface using the Parallel Query feature.
-
entrySet
public Set<Map.Entry<TK,TV>> entrySet(Filter filter, Comparator comparator)
Return a set view of the entries contained in this map that satisfy the criteria expressed by the filter. Each element in the returned set is aMap.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 (seeComparable
).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: The Partitioned Cache implements the QueryMap interface using the Parallel Query feature.
- Specified by:
entrySet
in interfaceQueryMap<FK,TK>
- Parameters:
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 used- Returns:
- a set of entries that satisfy the specified criteria
- See Also:
ChainedComparator
-
addIndex
public <T,E> void addIndex(ValueExtractor<? super T,? extends E> extractor, boolean fOrdered, Comparator<? super E> comparator)
Add an index to this QueryMap. This allows to correlate values stored in this indexed Map (or attributes of those values) to the corresponding keys in the indexed Map and increase the performance of methods that useFilters
.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
orComparator
for a precise definition of consistent with equals.)This method is only intended as a hint to the map implementation, and as such it may be ignored by the map 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.
- Specified by:
addIndex
in interfaceQueryMap<FK,TK>
- Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extracted- Parameters:
extractor
- 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 used- See Also:
ReflectionExtractor
,ChainedComparator
-
removeIndex
public <T,E> void removeIndex(ValueExtractor<? super T,? extends E> extractor)
Remove an index from this QueryMap.- Specified by:
removeIndex
in interfaceQueryMap<FK,TK>
- Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extracted- Parameters:
extractor
- the ValueExtractor object that is used to extract an indexable Object from a value stored in the Map.
-
putIfAbsent
public TV putIfAbsent(TK key, TV value)
- Specified by:
putIfAbsent
in interfaceInvocableMap<FK,TK>
- Specified by:
putIfAbsent
in interfaceMap<FK,TK>
-
merge
public TV merge(TK key, TV value, Remote.BiFunction<? super TV,? super TV,? extends TV> remappingFunction)
Description copied from interface:InvocableMap
If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result isnull
.This method may be of use when combining multiple mapped values for a key. For example, to either create or append a
String msg
to a value mapping:map.merge(key, msg, String::concat)
null
the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.- Specified by:
merge
in interfaceInvocableMap<FK,TK>
- Parameters:
key
- key with which the resulting value is to be associatedvalue
- the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the keyremappingFunction
- the function to recompute a value if present- Returns:
- the new value associated with the specified key, or null if no value is associated with the key
-
merge
public TV merge(TK key, TV value, BiFunction<? super TV,? super TV,? extends TV> remappingFunction)
-
getNamedCache
public NamedCache<FK,FV> getNamedCache()
Return the underlying NamedCache.- Returns:
- the underlying NamedCache
-
-