Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.1.0 E18814-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.util
Interface ConcurrentMap

All Superinterfaces:
  java.util.Map

All Known Subinterfaces:
  NamedCache, OptimisticNamedCache, TransactionMap

All Known Implementing Classes:
  BundlingNamedCache, ContinuousQueryCache, ConverterCollections.ConverterConcurrentMap, ConverterCollections.ConverterNamedCache, NearCache, ReadonlyNamedCache, SegmentedConcurrentMap, VersionedNearCache, WrapperConcurrentMap, WrapperNamedCache

      public interface ConcurrentMap

extends java.util.Map

Map with additional concurrency features.

Author:
  gg 2001.12.16

Nested Class Summary

Nested classes/interfaces inherited from interface java.util.Map
`java.util.Map.Entry`

Field Summary
`static java.lang.Object` | `LOCK_ALL` Special key value indicating an intent to lock the entire map.

Method Summary
`void` | `clear()` Removes all mappings from this map.
`boolean` | `containsKey(java.lang.Object key)` Returns `true` if this map contains a mapping for the specified key.
`boolean` | `containsValue(java.lang.Object value)` Returns `true` if this map maps one or more keys to the specified value.
`java.lang.Object` | `get(java.lang.Object key)` Returns the value to which this map maps the specified key.
`boolean` | `isEmpty()` Returns `true` if this map contains no key-value mappings.
`boolean` | `lock(java.lang.Object oKey)` Attempt to lock the specified item and return immediately.
`boolean` | `lock(java.lang.Object oKey, long cWait)` Attempt to lock the specified item within the specified period of time.
`java.lang.Object` | `put(java.lang.Object key, java.lang.Object value)` Associates the specified value with the specified key in this map (optional operation).
`void` | `putAll(java.util.Map map)` Copies all of the mappings from the specified map to this map (optional operation).
`java.lang.Object` | `remove(java.lang.Object key)` Removes the mapping for this key from this map if present (optional operation).
`int` | `size()` Returns the number of key-value mappings in this map.
`boolean` | `unlock(java.lang.Object oKey)` Unlock the specified item.

Methods inherited from interface java.util.Map
`entrySet, equals, hashCode, keySet, values`

Field Detail

### LOCK_ALL

    static final java.lang.Object LOCK_ALL

  Special key value indicating an intent to lock the entire map.

Method Detail

### lock

    boolean lock(java.lang.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 `LOCK_ALL` as the oKey parameter to indicate the map lock.

  Parameters:
    `oKey` - key being locked
    `cWait` - 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

    boolean lock(java.lang.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)`.

  Parameters:
    `oKey` - key being locked
  Returns:
    true if the item was successfully locked; false otherwise

### unlock

    boolean unlock(java.lang.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.
  Parameters:
    `oKey` - key being unlocked
  Returns:
    true if the item was successfully unlocked; false otherwise

### size

    int size()

  Returns the number of key-value mappings in this map. Note that this number does not include the items that were locked but didn't have corresponding map entries.
  Specified by:
    `size` in interface `java.util.Map`
  Returns:
    the number of key-value mappings in this map.

### isEmpty

    boolean isEmpty()

  Returns `true` if this map contains no key-value mappings. Note that the map could have some items locked and be empty at the same time.
  Specified by:
    `isEmpty` in interface `java.util.Map`
  Returns:
    `true` if this map contains no key-value mappings.

### containsKey

    boolean containsKey(java.lang.Object key)

  Returns `true` if this map contains a mapping for the specified key.
  Specified by:
    `containsKey` in interface `java.util.Map`
  Parameters:
    `key` - key whose presence in this map is to be tested.
  Returns:
    `true` if this map contains a mapping for the specified key.
  Throws:
    `java.lang.ClassCastException` - if the key is of an inappropriate type for this map.
    `java.lang.NullPointerException` - if the key is `null` and this map does not not permit `null` keys.

### containsValue

    boolean containsValue(java.lang.Object value)

  Returns `true` if this map maps one or more keys to the specified value. More formally, returns `true` if and only if this map contains at least one mapping to a value `v` such that `(value==null ? v==null : value.equals(v))`. This operation will probably require time linear in the map size for most implementations of the `ConcurrentMap` interface.
  Specified by:
    `containsValue` in interface `java.util.Map`
  Parameters:
    `value` - value whose presence in this map is to be tested.
  Returns:
    `true` if this map maps one or more keys to the specified value.

### get

    java.lang.Object get(java.lang.Object key)

  Returns the value to which this map maps the specified key. Returns `null` if the map contains no mapping for this key. A return value of `null` does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to `null`. The `containsKey` operation may be used to distinguish these two cases.
  Specified by:
    `get` in interface `java.util.Map`
  Parameters:
    `key` - key whose associated value is to be returned.
  Returns:
    the value to which this map maps the specified key, or `null` if the map contains no mapping for this key.
  Throws:
    `java.lang.ClassCastException` - if the key is of an inappropriate type for this map.
    `java.lang.NullPointerException` - key is `null` and this map does not not permit `null` keys.
  See Also:
    `containsKey(Object)`

### put

    java.lang.Object put(java.lang.Object key,
                         java.lang.Object value)

  Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced. Some implementations will attempt to obtain a lock for the key (if necessary) before proceeding with the put operation. For such implementations, the specified item has to be either already locked or able to be locked for this operation to succeed.
  Specified by:
    `put` in interface `java.util.Map`
  Parameters:
    `key` - key with which the specified value is to be associated.
    `value` - value to be associated with the specified key.
  Returns:
    previous value associated with specified key, or `null` if there was no mapping for key. A `null` return can also indicate that the map previously associated `null` with the specified key, if the implementation supports `null` values.
  Throws:
    `java.lang.IllegalArgumentException` - if the value cannot be stored in the map (i.e. not serializable)
    `java.util.ConcurrentModificationException` - if the lock could not be successfully obtained for the specified key.
    `java.lang.ClassCastException` - if the class of the specified key or value prevents it from being stored in this map.
    `java.lang.NullPointerException` - this map does not permit `null` keys or values, and the specified key or value is `null`.

### remove

    java.lang.Object remove(java.lang.Object key)

  Removes the mapping for this key from this map if present (optional operation). Some implementations will attempt to obtain a lock for the key (if necessary) before proceeding with the remove operation. For such implementations, the specified item has to be either already locked or able to be locked for this operation to succeed.
  Specified by:
    `remove` in interface `java.util.Map`
  Parameters:
    `key` - key whose mapping is to be removed from the map.
  Returns:
    previous value associated with specified key, or `null` if there was no mapping for key. A `null` return can also indicate that the map previously associated `null` with the specified key, if the implementation supports `null` values.
  Throws:
    `java.util.ConcurrentModificationException` - if the lock could not be successfully obtained for the specified key.

### putAll

    void putAll(java.util.Map map)

  Copies all of the mappings from the specified map to this map (optional operation). These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
  Specified by:
    `putAll` in interface `java.util.Map`
  Parameters:
    `map` - Mappings to be stored in this map.
  Throws:
    `java.lang.ClassCastException` - if the class of a key or value in the specified map prevents it from being stored in this map.
    `java.util.ConcurrentModificationException` - if the lock could not be successfully obtained for some key
    `java.lang.NullPointerException` - this map does not permit `null` keys or values, and the specified key or value is `null`.

### clear

    void clear()

  Removes all mappings from this map. Some implementations will attempt to lock the entire map (if necessary) before proceeding with the clear operation. For such implementations, the entire map has to be either already locked or able to be locked for this operation to succeed.
  Specified by:
    `clear` in interface `java.util.Map`
  Throws:
    `java.util.ConcurrentModificationException` - if a lock could not be successfully obtained for some key.

Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.1.0 E18814-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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