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
  • Field Details

    • ENTRY_TO_KEY_CONVERTER

      public static final Converter ENTRY_TO_KEY_CONVERTER
      Trivial Entry-to-Key converter.
    • ENTRY_TO_VALUE_CONVERTER

      public static final Converter ENTRY_TO_VALUE_CONVERTER
      Trivial Entry-to-Value converter.
  • Constructor Details

    • InvocableMapHelper

      public InvocableMapHelper()
  • Method Details

    • invokeAsync

      public static <K, V, R> CompletableFuture<R> invokeAsync(NamedCache<K,V> cache, K key, InvocableMap.EntryProcessor<K,V,R> proc)
      Deprecated.
      Invoke the specified EntryProcessor asynchronously.
      Type Parameters:
      K - the key type
      V - the value type
      R - the result type
      Parameters:
      cache - the cache to invoke against
      key - the key to invoke upon
      proc - 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 type
      V - the value type
      R - the result type
      Parameters:
      cache - the cache to invoke against
      key - the key to invoke upon
      nOrderId - the unit of order
      proc - the processor to invoke
      continuations - 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, 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 type
      V - the value type
      R - the result type
      Parameters:
      cache - the cache to invoke against
      setKey - the set of keys to invoke upon
      nOrderId - the unit of order
      proc - the processor to invoke
      continuations - 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 type
      V - the value type
      R - the result type
      Parameters:
      cache - the cache to invoke against
      setKey - the set of keys to invoke upon
      funcOrder - function to compute unit of order based on th ekey
      proc - the processor to invoke
      continuations - 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 against
      entry - the InvocableMap.Entry to process; it is not required to exist within the Map
      agent - 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 against
      setEntries - a set of InvocableMap.Entry objects to process
      agent - 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 use
      collKeys - a collection of keys to lock
      cWait - 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 use
      collKeys - 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 for
      key - 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 for
      collKeys - collection of keys to create entries for; these keys are not required to exist within the Map
      fReadOnly - 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 of InvocableMap.Entry objects using the specified collection of Map.Entry objects.
      Parameters:
      map - the parent Map for the entries
      collEntries - collection of Map.Entry objects to copy from
      fReadOnly - 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 against
      entry - 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 against
      oKey - the key for the entry
      oValue - 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 against
      entry - 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 from
      E - the type of value that will be extracted
      K - the entry key type
      V - the entry value type
      Parameters:
      extractor - the extractor to use
      entry - 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 use
      entry - 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 use
      entry - the entry to update
      oValue - the new value
    • query

      public static Set query(Map map, Filter filter, boolean fEntries, boolean fSort, Comparator comparator)
      Generic implementation of the QueryMap API.
      Parameters:
      map - the underlying Map
      filter - the Filter
      fEntries - if true, return an entry-set; otherwise a key-set
      fSort - if true, sort the entry-set before returning
      comparator - 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 the QueryMap API.
      Parameters:
      map - the underlying Map
      mapIndexes - the map of available MapIndex objects keyed by the related ValueExtractor; read-only
      filter - the Filter
      fEntries - if true, return an entry-set; otherwise a key-set
      fSort - if true, sort the entry-set before returning
      comparator - 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 entry
      fOrdered - true if the contents of the indexed information should be ordered; false otherwise
      comparator - the Comparator object which imposes an ordering on entries in the indexed map or null if the entries' values natural ordering should be used
      map - the resource map that the newly created MapIndex will use for initialization and listen to for changes
      mapIndex - 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 for
      mapIndex - 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