CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

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
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 boolean evaluateEntry(Filter filter, Map.Entry entry)
          Check if the entry passes the filters evaulation.
static boolean evaluateEntry(Filter filter, Object oKey, Object oValue)
          Check if an entry, expressed as a key and value, passes the filters evaulation.
static Object extractFromEntry(ValueExtractor extractor, Map.Entry entry)
          Extract a value from the specified entry using the specified extractor.
static Map invokeAllLocked(ConcurrentMap map, Set setEntries, InvocableMap.EntryProcessor agent)
          Invoke the passed EntryProcessor against the entries specified by the passed map and entries.
static Object invokeLocked(ConcurrentMap map, InvocableMap.Entry entry, InvocableMap.EntryProcessor 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 InvocableMapHelper.SimpleEntry makeEntry(Map map, Object oKey)
          Create a SimpleEntry object for the specified map and the key.
static Set makeEntrySet(Collection collEntries)
          Create a set of read-only SimpleEntry objects for the specified collection of Map.Entry objects.
static Set makeEntrySet(Map map, Collection 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 the QueryMap API.
static void unlockAll(ConcurrentMap map, Collection collKeys)
          Unlock all the specified keys.
 

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 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 Map invokeAllLocked(ConcurrentMap map,
                                  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 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 InvocableMapHelper.SimpleEntry makeEntry(Map map,
                                                       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 Set makeEntrySet(Map map,
                               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 Set makeEntrySet(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,
                                    Map.Entry entry)
Check if the entry passes the filters evaulation.

Parameters:
filter - the filter to evaulate 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,
                                    Object oKey,
                                    Object oValue)
Check if an entry, expressed as a key and value, passes the filters evaulation.

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

extractFromEntry

public static Object extractFromEntry(ValueExtractor extractor,
                                      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

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)

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation