Class InvocableMapHelper
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.util.InvocableMapHelper
-
public abstract class InvocableMapHelper extends Base
Helper methods for InvocableMap implementations and Filter related evaluation.- Since:
- Coherence 3.1
- Author:
- gg 2005.10.24
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
InvocableMapHelper.IndexAdapter
MapListener implementation that routes the map events into the corresponding MapIndex calls.protected static class
InvocableMapHelper.RoutingBinaryEntry
BinaryEntry wrapper that routes the getValue()/getBinaryValue() calls onto getOriginalValue()/getOriginalBinaryValue().protected static class
InvocableMapHelper.RoutingMapTriggerEntry
MapTrigger.Entry wrapper that routes the getValue() call onto getOriginalValue().static class
InvocableMapHelper.SimpleEntry<K,V>
Simple implementation of the InvocableMap.Entry interface.-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description static Converter
ENTRY_TO_KEY_CONVERTER
Trivial Entry-to-Key converter.static Converter
ENTRY_TO_VALUE_CONVERTER
Trivial Entry-to-Value converter.
-
Constructor Summary
Constructors Constructor Description InvocableMapHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addIndex(ValueExtractor extractor, boolean fOrdered, Comparator comparator, ObservableMap map, Map mapIndex)
Add an index to the given map of indexes, keyed by the given extractor.static <K,V>
Set<InvocableMap.Entry<K,V>>duplicateEntrySet(Map<K,V> map, Collection<? extends Map.Entry<K,V>> collEntries, boolean fReadOnly)
Create a set ofInvocableMap.Entry
objects using the specified collection of Map.Entry objects.protected static MapListener
ensureListener(MapIndex index)
Ensure a MapListener for the given index.static <K,V>
booleanevaluateEntry(Filter filter, Map.Entry<K,V> entry)
Check if the entry passes the filter evaluation.static <K,V>
booleanevaluateEntry(Filter filter, K oKey, V oValue)
Check if an entry, expressed as a key and value, passes the filter evaluation.static boolean
evaluateOriginalEntry(Filter filter, MapTrigger.Entry entry)
Check if the entry, in its "original" form, passes the filter evaluation.static <T,E,K,V>
EextractFromEntry(ValueExtractor<? super T,? extends E> extractor, Map.Entry<? extends K,? extends V> entry)
Extract a value from the specified entry using the specified extractor.static Object
extractOriginalFromEntry(ValueExtractor extractor, MapTrigger.Entry entry)
Extract a value from the "original value" of the specified entry using the specified extractor.static <K,V,R>
CompletableFuture<Map<K,R>>invokeAllAsync(NamedCache<K,V> cache, Collection<? extends K> setKey, int nOrderId, InvocableMap.EntryProcessor<K,V,R> proc, Executor executor, BiConsumer<? super Map<? extends K,? extends R>,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.static <K,V,R>
CompletableFuture<Map<K,R>>invokeAllAsync(NamedCache<K,V> cache, Collection<? extends K> setKey, ToIntFunction<K> funcOrder, InvocableMap.EntryProcessor<K,V,R> proc, Executor executor, BiConsumer<? super Map<? extends K,? extends R>,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.static <K,V,R>
CompletableFuture<Map<K,R>>invokeAllAsync(NamedCache<K,V> cache, Collection<? extends K> setKey, ToIntFunction<K> funcOrder, InvocableMap.EntryProcessor<K,V,R> proc, BiConsumer<? super Map<? extends K,? extends R>,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.static <K,V,R>
Map<K,R>invokeAllLocked(ConcurrentMap<K,V> map, Set<? extends InvocableMap.Entry<K,V>> setEntries, InvocableMap.EntryProcessor<K,V,R> agent)
Invoke the passed EntryProcessor against the entries specified by the passed map and entries.static <K,V,R>
CompletableFuture<R>invokeAsync(NamedCache<K,V> cache, K key, int nOrderId, InvocableMap.EntryProcessor<K,V,R> proc, Executor executor, BiConsumer<? super R,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.static <K,V,R>
CompletableFuture<R>invokeAsync(NamedCache<K,V> cache, K key, int nOrderId, InvocableMap.EntryProcessor<K,V,R> proc, BiConsumer<? super R,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.static <K,V,R>
CompletableFuture<R>invokeAsync(NamedCache<K,V> cache, K key, InvocableMap.EntryProcessor<K,V,R> proc)
Deprecated.As of Coherence 14.1.1, use enhancedinvokeAsync(NamedCache, Object, int, InvocableMap.EntryProcessor, BiConsumer[])
.static <K,V,R>
RinvokeLocked(ConcurrentMap<K,V> map, InvocableMap.Entry<K,V> entry, InvocableMap.EntryProcessor<K,V,R> agent)
Invoke the passed EntryProcessor against the specified Entry.static List
lockAll(ConcurrentMap map, Collection collKeys, long cWait)
Attempt to lock all the specified keys within a specified period of time.static <K,V>
InvocableMapHelper.SimpleEntry<K,V>makeEntry(Map<K,V> map, K key)
Create a SimpleEntry object for the specified map and the key.static <K,V>
Set<InvocableMap.Entry<K,V>>makeEntrySet(Collection<? extends Map.Entry<K,V>> collEntries)
Create a set of read-only SimpleEntry objects for the specified collection of Map.Entry objects.static <K,V>
Set<InvocableMap.Entry<K,V>>makeEntrySet(Map<K,V> map, Collection<? extends K> collKeys, boolean fReadOnly)
Create a set of SimpleEntry objects for the specified map and the key collection.static Set
query(Map map, Filter filter, boolean fEntries, boolean fSort, Comparator comparator)
Generic implementation of theQueryMap
API.static Set
query(Map map, Map mapIndexes, Filter filter, boolean fEntries, boolean fSort, Comparator comparator)
Generic implementation of theQueryMap
API.static void
removeIndex(ValueExtractor extractor, ObservableMap map, Map mapIndex)
Remove the index keyed by the given extractor from the given map of indexes.static void
unlockAll(ConcurrentMap map, Collection collKeys)
Unlock all the specified keys.static <K,V,U>
voidupdateEntry(ValueUpdater<V,U> updater, Map.Entry<K,V> entry, U oValue)
Update the specified entry using the specified updater and value.-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
-
-
-
Method Detail
-
invokeAsync
public static <K,V,R> CompletableFuture<R> invokeAsync(NamedCache<K,V> cache, K key, InvocableMap.EntryProcessor<K,V,R> proc)
Deprecated.As of Coherence 14.1.1, use enhancedinvokeAsync(NamedCache, Object, int, InvocableMap.EntryProcessor, BiConsumer[])
.Invoke the specified EntryProcessor asynchronously.- Type Parameters:
K
- the key typeV
- the value typeR
- the result type- Parameters:
cache
- the cache to invoke againstkey
- the key to invoke uponproc
- the processor to invoke- Returns:
- a CompletableFuture which will contain the result
-
invokeAsync
@SafeVarargs public static <K,V,R> CompletableFuture<R> invokeAsync(NamedCache<K,V> cache, K key, int nOrderId, InvocableMap.EntryProcessor<K,V,R> proc, BiConsumer<? super R,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.The continuation which will be invoked when the processor completes and most importantly on the thread on which the operation completes which is not something that can be guaranteed if the continuation is applied via the returned CompletableFuture.
- Type Parameters:
K
- the key typeV
- the value typeR
- the result type- Parameters:
cache
- the cache to invoke againstkey
- the key to invoke uponnOrderId
- the unit of orderproc
- the processor to invokecontinuations
- continuations which will be invoked when the operation completes- Returns:
- a CompletableFuture which will contain the result
-
invokeAsync
@SafeVarargs public static <K,V,R> CompletableFuture<R> invokeAsync(NamedCache<K,V> cache, K key, int nOrderId, InvocableMap.EntryProcessor<K,V,R> proc, Executor executor, BiConsumer<? super R,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.The continuation which will be invoked when the processor completes and most importantly on the thread on which the operation completes which is not something that can be guaranteed if the continuation is applied via the returned CompletableFuture.
- Type Parameters:
K
- the key typeV
- the value typeR
- the result type- Parameters:
cache
- the cache to invoke againstkey
- the key to invoke uponnOrderId
- the unit of orderproc
- the processor to invokeexecutor
- an optionalExecutor
to use to complete the returned futurecontinuations
- continuations which will be invoked when the operation completes- Returns:
- a CompletableFuture which will contain the result
-
invokeAllAsync
@SafeVarargs public static <K,V,R> CompletableFuture<Map<K,R>> invokeAllAsync(NamedCache<K,V> cache, Collection<? extends K> setKey, int nOrderId, InvocableMap.EntryProcessor<K,V,R> proc, Executor executor, BiConsumer<? super Map<? extends K,? extends R>,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.The continuation which will be invoked when the processor completes and most importantly on the thread on which the operation completes which is not something that can be guaranteed if the continuation is applied via the returned CompletableFuture.
- Type Parameters:
K
- the key typeV
- the value typeR
- the result type- Parameters:
cache
- the cache to invoke againstsetKey
- the set of keys to invoke uponnOrderId
- the unit of orderproc
- the processor to invokecontinuations
- continuations which will be invoked when the operation completes- Returns:
- a CompletableFuture which will contain the result
-
invokeAllAsync
@SafeVarargs public static <K,V,R> CompletableFuture<Map<K,R>> invokeAllAsync(NamedCache<K,V> cache, Collection<? extends K> setKey, ToIntFunction<K> funcOrder, InvocableMap.EntryProcessor<K,V,R> proc, BiConsumer<? super Map<? extends K,? extends R>,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.The continuation which will be invoked when the processor completes and most importantly on the thread on which the operation completes which is not something that can be guaranteed if the continuation is applied via the returned CompletableFuture.
- Type Parameters:
K
- the key typeV
- the value typeR
- the result type- Parameters:
cache
- the cache to invoke againstsetKey
- the set of keys to invoke uponfuncOrder
- function to compute unit of order based on th ekeyproc
- the processor to invokecontinuations
- continuations which will be invoked when the operation completes- Returns:
- a CompletableFuture which will contain the result
-
invokeAllAsync
@SafeVarargs public static <K,V,R> CompletableFuture<Map<K,R>> invokeAllAsync(NamedCache<K,V> cache, Collection<? extends K> setKey, ToIntFunction<K> funcOrder, InvocableMap.EntryProcessor<K,V,R> proc, Executor executor, BiConsumer<? super Map<? extends K,? extends R>,? super Throwable>... continuations)
Invoke the specified EntryProcessor asynchronously.The continuation which will be invoked when the processor completes and most importantly on the thread on which the operation completes which is not something that can be guaranteed if the continuation is applied via the returned CompletableFuture.
- Type Parameters:
K
- the key typeV
- the value typeR
- the result type- Parameters:
cache
- the cache to invoke againstsetKey
- the set of keys to invoke uponfuncOrder
- function to compute unit of order based on the keyproc
- the processor to invokeexecutor
- an optionalExecutor
to use to complete the futurecontinuations
- continuations which will be invoked when the operation completes- Returns:
- a CompletableFuture which will contain the result
-
invokeLocked
public static <K,V,R> R invokeLocked(ConcurrentMap<K,V> map, InvocableMap.Entry<K,V> entry, InvocableMap.EntryProcessor<K,V,R> agent)
Invoke the passed EntryProcessor against the specified Entry. The invocation is made thread safe by locking the corresponding key on the map.- Parameters:
map
- the ConcurrentMap that the EntryProcessor works againstentry
- the InvocableMap.Entry 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
-
invokeAllLocked
public static <K,V,R> Map<K,R> invokeAllLocked(ConcurrentMap<K,V> map, Set<? extends InvocableMap.Entry<K,V>> setEntries, InvocableMap.EntryProcessor<K,V,R> agent)
Invoke the passed EntryProcessor against the entries specified by the passed map and entries. The invocation is made thread safe by locking the corresponding keys on the map. If an attempt to lock all the entries at once fails, they will be processed individually one-by-one.- Parameters:
map
- the ConcurrentMap that the EntryProcessor works againstsetEntries
- a set of InvocableMap.Entry objects to processagent
- the EntryProcessor to use to process the specified keys- Returns:
- a Map containing the results of invoking the EntryProcessor against each of the specified entry
-
lockAll
public static List lockAll(ConcurrentMap map, Collection collKeys, long cWait)
Attempt to lock all the specified keys within a specified period of time.- Parameters:
map
- the ConcurrentMap to usecollKeys
- a collection of keys to lockcWait
- the number of milliseconds to continue trying to obtain locks; pass zero to return immediately; pass -1 to block the calling thread until the lock could be obtained- Returns:
- a List containing all the locked keys in the order opposite to the locking order (LIFO); null if timeout has occurred
-
unlockAll
public static void unlockAll(ConcurrentMap map, Collection collKeys)
Unlock all the specified keys.- Parameters:
map
- the ConcurrentMap to usecollKeys
- a collection of keys to unlock
-
makeEntry
public static <K,V> InvocableMapHelper.SimpleEntry<K,V> makeEntry(Map<K,V> map, K key)
Create a SimpleEntry object for the specified map and the key.- Parameters:
map
- the ConcurrentMap to create entries forkey
- the key to create an entry for; the key is not required to exist within the Map- Returns:
- a SimpleEntry object
-
makeEntrySet
public static <K,V> Set<InvocableMap.Entry<K,V>> makeEntrySet(Map<K,V> map, Collection<? extends K> collKeys, boolean fReadOnly)
Create a set of SimpleEntry objects for the specified map and the key collection.- Parameters:
map
- the Map to create entries forcollKeys
- collection of keys to create entries for; these keys are not required to exist within the MapfReadOnly
- if true, the returned entries will be marked as read-only- Returns:
- a Set of SimpleEntry objects
-
makeEntrySet
public static <K,V> Set<InvocableMap.Entry<K,V>> makeEntrySet(Collection<? extends Map.Entry<K,V>> collEntries)
Create a set of read-only SimpleEntry objects for the specified collection of Map.Entry objects.- Parameters:
collEntries
- collection of Map.Entry objects to create SimpleEntry objects for- Returns:
- a Set of SimpleEntry objects
-
duplicateEntrySet
public static <K,V> Set<InvocableMap.Entry<K,V>> duplicateEntrySet(Map<K,V> map, Collection<? extends Map.Entry<K,V>> collEntries, boolean fReadOnly)
Create a set ofInvocableMap.Entry
objects using the specified collection of Map.Entry objects.- Parameters:
map
- the parent Map for the entriescollEntries
- collection of Map.Entry objects to copy fromfReadOnly
- if true, the returned entries will be marked as read-only- Returns:
- a Set of SimpleEntry objects
-
evaluateEntry
public static <K,V> boolean evaluateEntry(Filter filter, Map.Entry<K,V> entry)
Check if the entry passes the filter evaluation.- Parameters:
filter
- the filter to evaluate againstentry
- a key value pair to filter- Returns:
- true if the entry passes the filter, false otherwise
-
evaluateEntry
public static <K,V> boolean evaluateEntry(Filter filter, K oKey, V oValue)
Check if an entry, expressed as a key and value, passes the filter evaluation.- Parameters:
filter
- the filter to evaluate againstoKey
- the key for the entryoValue
- the value for the entry- Returns:
- true if the entry passes the filter, false otherwise
-
evaluateOriginalEntry
public static boolean evaluateOriginalEntry(Filter filter, MapTrigger.Entry entry)
Check if the entry, in its "original" form, passes the filter evaluation.- Parameters:
filter
- the filter to evaluate againstentry
- the entry whose "original" value to evaluate- Returns:
- true iff the entry has an original value and passes the filter
-
extractFromEntry
public static <T,E,K,V> E extractFromEntry(ValueExtractor<? super T,? extends E> extractor, Map.Entry<? extends K,? extends V> entry)
Extract a value from the specified entry using the specified extractor.- Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extractedK
- the entry key typeV
- the entry value type- Parameters:
extractor
- the extractor to useentry
- the entry to extract from- Returns:
- the extracted value
-
extractOriginalFromEntry
public static Object extractOriginalFromEntry(ValueExtractor extractor, MapTrigger.Entry entry)
Extract a value from the "original value" of the specified entry using the specified extractor.- Parameters:
extractor
- the extractor to useentry
- the entry to extract from- Returns:
- the extracted original value
-
updateEntry
public static <K,V,U> void updateEntry(ValueUpdater<V,U> updater, Map.Entry<K,V> entry, U oValue)
Update the specified entry using the specified updater and value.- Parameters:
updater
- the updater to useentry
- the entry to updateoValue
- the new value
-
query
public static Set query(Map map, Filter filter, boolean fEntries, boolean fSort, Comparator comparator)
Generic implementation of theQueryMap
API.- Parameters:
map
- the underlying Mapfilter
- the FilterfEntries
- if true, return an entry-set; otherwise a key-setfSort
- if true, sort the entry-set before returningcomparator
- the Comparator to use for sorting (optional)- Returns:
- the query result set
-
query
public static Set query(Map map, Map mapIndexes, Filter filter, boolean fEntries, boolean fSort, Comparator comparator)
Generic implementation of theQueryMap
API.- Parameters:
map
- the underlying MapmapIndexes
- the map of availableMapIndex
objects keyed by the related ValueExtractor; read-onlyfilter
- the FilterfEntries
- if true, return an entry-set; otherwise a key-setfSort
- if true, sort the entry-set before returningcomparator
- the Comparator to use for sorting (optional)- Returns:
- the query result set
-
addIndex
public static void addIndex(ValueExtractor extractor, boolean fOrdered, Comparator comparator, ObservableMap map, Map mapIndex)
Add an index to the given map of indexes, keyed by the given extractor. Also add the index as a listener to the given ObservableMap.- Parameters:
extractor
- the ValueExtractor object that is used to extract an indexable property value from a resource map entryfOrdered
- true if 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 usedmap
- the resource map that the newly created MapIndex will use for initialization and listen to for changesmapIndex
- the map of indexes that the newly created MapIndex will be added to
-
removeIndex
public static void removeIndex(ValueExtractor extractor, ObservableMap map, Map mapIndex)
Remove the index keyed by the given extractor from the given map of indexes. Also, remove the index as a listener from the given ObservableMap.- Parameters:
extractor
- the ValueExtractor object that is used to extract an indexable Object from a value stored in the Map.map
- the resource map to remove the index formapIndex
- the map of indexes to remove the MapIndex from
-
ensureListener
protected static MapListener ensureListener(MapIndex index)
Ensure a MapListener for the given index. The listener will route the map events into the corresponding MapIndex calls.- Parameters:
index
- the index- Returns:
- a listener for given index
-
-