Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.util
Class InvocableMapHelper

java.lang.Object
  extended by com.tangosol.util.Base
      extended by 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
protected static class InvocableMapHelper.IndexAdapter
          MapListener implementation that routes the map events into the corresponding MapIndex calls.
static class InvocableMapHelper.SimpleEntry
          Simple implementation of the InvocableMap.Entry interface.

 

Field Summary
static Converter ENTRY_TO_KEY_CONVERTER
          Trivial Entry-to-Key converter.

 

Constructor Summary
InvocableMapHelper()
           

 

Method Summary
static void addIndex(ValueExtractor extractor, boolean fOrdered, java.util.Comparator comparator, ObservableMap map, java.util.Map mapIndex)
          Add an index to the given map of indexes, keyed by the given extractor.
protected static MapListener ensureListener(MapIndex index)
          Ensure a MapListener for the given index.
static boolean evaluateEntry(Filter filter, java.util.Map.Entry entry)
          Check if the entry passes the filter evaluation.
static boolean evaluateEntry(Filter filter, java.lang.Object oKey, java.lang.Object 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 java.lang.Object extractFromEntry(ValueExtractor extractor, java.util.Map.Entry entry)
          Extract a value from the specified entry using the specified extractor.
static java.lang.Object extractOriginalFromEntry(ValueExtractor extractor, MapTrigger.Entry entry)
          Extract a value from the "original value" of the specified entry using the specified extractor.
static java.util.Map invokeAllLocked(ConcurrentMap map, java.util.Set setEntries, InvocableMap.EntryProcessor agent)
          Invoke the passed EntryProcessor against the entries specified by the passed map and entries.
static java.lang.Object invokeLocked(ConcurrentMap map, InvocableMap.Entry entry, InvocableMap.EntryProcessor agent)
          Invoke the passed EntryProcessor against the specified Entry.
static java.util.List lockAll(ConcurrentMap map, java.util.Collection collKeys, long cWait)
          Attempt to lock all the specified keys within a specified period of time.
static InvocableMapHelper.SimpleEntry makeEntry(java.util.Map map, java.lang.Object oKey)
          Create a SimpleEntry object for the specified map and the key.
static java.util.Set makeEntrySet(java.util.Collection collEntries)
          Create a set of read-only SimpleEntry objects for the specified collection of Map.Entry objects.
static java.util.Set makeEntrySet(java.util.Map map, java.util.Collection collKeys, boolean fReadOnly)
          Create a set of SimpleEntry objects for the specified map and the key collection.
static java.util.Set query(java.util.Map map, Filter filter, boolean fEntries, boolean fSort, java.util.Comparator comparator)
          Generic implementation of the QueryMap API.
static java.util.Set query(java.util.Map map, java.util.Map mapIndexes, Filter filter, boolean fEntries, boolean fSort, java.util.Comparator comparator)
          Generic implementation of the QueryMap API.
static void removeIndex(ValueExtractor extractor, ObservableMap map, java.util.Map mapIndex)
          Remove the index keyed by the given extractor from the given map of indexes.
static void unlockAll(ConcurrentMap map, java.util.Collection collKeys)
          Unlock all the specified keys.
static void updateEntry(ValueUpdater updater, java.util.Map.Entry entry, java.lang.Object oValue)
          Update the specified entry using the specified updater and value.

 

Field Detail

ENTRY_TO_KEY_CONVERTER

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

Constructor Detail

InvocableMapHelper

public InvocableMapHelper()

Method Detail

invokeLocked

public static java.lang.Object invokeLocked(ConcurrentMap map,
                                            InvocableMap.Entry entry,
                                            InvocableMap.EntryProcessor 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 java.util.Map invokeAllLocked(ConcurrentMap map,
                                            java.util.Set setEntries,
                                            InvocableMap.EntryProcessor 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 java.util.List lockAll(ConcurrentMap map,
                                     java.util.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,
                             java.util.Collection collKeys)
Unlock all the specified keys.
Parameters:
map - the ConcurrentMap to use
collKeys - a collection of keys to unlock

makeEntry

public static InvocableMapHelper.SimpleEntry makeEntry(java.util.Map map,
                                                       java.lang.Object oKey)
Create a SimpleEntry object for the specified map and the key.
Parameters:
map - the ConcurrentMap to create entries for
oKey - the key to create an entry for; the key is not required to exist within the Map
Returns:
a SimpleEntry object

makeEntrySet

public static java.util.Set makeEntrySet(java.util.Map map,
                                         java.util.Collection 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 java.util.Set makeEntrySet(java.util.Collection 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

evaluateEntry

public static boolean evaluateEntry(Filter filter,
                                    java.util.Map.Entry 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 boolean evaluateEntry(Filter filter,
                                    java.lang.Object oKey,
                                    java.lang.Object 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 java.lang.Object extractFromEntry(ValueExtractor extractor,
                                                java.util.Map.Entry entry)
Extract a value from the specified entry using the specified extractor.
Parameters:
extractor - the extractor to use
entry - the entry to extract from
Returns:
the extracted value

extractOriginalFromEntry

public static java.lang.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 void updateEntry(ValueUpdater updater,
                               java.util.Map.Entry entry,
                               java.lang.Object 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 java.util.Set query(java.util.Map map,
                                  Filter filter,
                                  boolean fEntries,
                                  boolean fSort,
                                  java.util.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 java.util.Set query(java.util.Map map,
                                  java.util.Map mapIndexes,
                                  Filter filter,
                                  boolean fEntries,
                                  boolean fSort,
                                  java.util.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,
                            java.util.Comparator comparator,
                            ObservableMap map,
                            java.util.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,
                               java.util.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

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.