Skip navigation links

Oracle® Coherence Java API Reference
v3.5

E14977-01


com.tangosol.util
Class SegmentedConcurrentMap

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.SegmentedHashMap
          extended by com.tangosol.util.SegmentedConcurrentMap

All Implemented Interfaces:
ConcurrentMap, java.util.Map

public class SegmentedConcurrentMap
extends SegmentedHashMap
implements ConcurrentMap

An implementation of SegmentedHashMap that also implements the ConcurrentMap interface. <p/> See ConcurrentMap

Since:
Coherence 3.5
Author:
rhl 2008.12.01

Nested Class Summary
protected  class SegmentedConcurrentMap.LockableEntry
          LockableEntry is an Entry that supports locking.
protected  class SegmentedConcurrentMap.LockAction
          Action support for lock().
protected  class SegmentedConcurrentMap.RemoveAction
          Action support for remove().
protected static class SegmentedConcurrentMap.SizeAction
          Action support for size().
protected  class SegmentedConcurrentMap.UnlockAction
          Action support for unlock().

 

Nested classes/interfaces inherited from class com.tangosol.util.SegmentedHashMap
SegmentedHashMap.ContainsValueAction, SegmentedHashMap.Entry, SegmentedHashMap.EntryAction, SegmentedHashMap.EntryActionAdapter, SegmentedHashMap.EntrySet, SegmentedHashMap.GetEntryAction, SegmentedHashMap.InsertAction, SegmentedHashMap.IterableEntryAction, SegmentedHashMap.KeySet, SegmentedHashMap.Segment, SegmentedHashMap.ValuesCollection

 

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

 

Field Summary
protected  SegmentedConcurrentMap.LockAction m_actionLock
          The action for lock() support.
protected  SegmentedConcurrentMap.SizeAction m_actionSize
          The singleton action for size support.
protected  SegmentedConcurrentMap.UnlockAction m_actionUnlock
          The action for unlock() support.
protected  ThreadGate m_gateLockAll
          The ThreadGate controlling LOCK_ALL access for this map.

 

Fields inherited from class com.tangosol.util.SegmentedHashMap
BIGGEST_MODULO, DEFAULT_GROWTHRATE, DEFAULT_INITIALSIZE, DEFAULT_LOADFACTOR, LOCK_ALL_PENDING, LOCK_ALL_PENDING_IDX, LOCK_COUNT, LOCKS_ALL, LOCKS_NONE, m_actionContainsValue, m_actionGetEntry, m_actionInsert, m_actionRemove, m_aeBucket, m_aSegment, m_atomicLocks, m_colValues, m_cSegmentCapacity, m_flGrowthRate, m_flLoadFactor, m_oIterActive, m_setEntries, m_setKeys, MIN_SEGMENT_CAPACITY, NO_VALUE, PRIME_MODULO, PUTALL_THRESHOLD, RESIZING, SEGMENT_COUNT, SEGMENT_LOCK_MAX_SPIN

 

Fields inherited from interface com.tangosol.util.ConcurrentMap
LOCK_ALL

 

Constructor Summary
SegmentedConcurrentMap()
          Default constructor.
SegmentedConcurrentMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate)
          Construct a thread-safe hash map using the specified settings.

 

Method Summary
 void clear()
          Removes all mappings from this map.
protected  SegmentedConcurrentMap.LockAction getLockAction()
          Return the registered action for lock().
protected  SegmentedConcurrentMap.SizeAction getSizeAction()
          Return the registered action for size().
protected  SegmentedConcurrentMap.UnlockAction getUnlockAction()
          Return the registered action for unlock().
protected  void initializeActions()
          Initialize the EntryAction's for this map.
protected  SegmentedHashMap.Entry instantiateEntry(java.lang.Object oKey, java.lang.Object oValue, int nHash)
          Factory for Entry.
protected  SegmentedConcurrentMap.LockAction instantiateLockAction()
          Factory for LockAction
protected  SegmentedHashMap.RemoveAction instantiateRemoveAction()
          Factory for RemoveAction
protected  SegmentedConcurrentMap.SizeAction instantiateSizeAction()
          Factory for SizeAction
protected  SegmentedConcurrentMap.UnlockAction instantiateUnlockAction()
          Factory for UnlockAction
 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.
protected  void setLockAction(SegmentedConcurrentMap.LockAction action)
          Specify the action for lock().
protected  void setSizeAction(SegmentedConcurrentMap.SizeAction action)
          Specify the action for size().
protected  void setUnlockAction(SegmentedConcurrentMap.UnlockAction action)
          Specify the action for unlock().
 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 class com.tangosol.util.SegmentedHashMap
containsKey, containsValue, contendForSegment, ensureLoadFactor, entryFromBucket, entrySet, equals, get, getBucketIndex, getContainsValueAction, getEntry, getEntryInternal, getEntryInternal, getGetEntryAction, getInsertAction, getRemoveAction, getSegmentForEntry, getSegmentIndex, getStableBucketArray, grow, grow, hashCode, instantiateContainsValueAction, instantiateEntrySet, instantiateGetEntryAction, instantiateInsertAction, instantiateKeySet, instantiateValuesCollection, invokeOnAllKeys, invokeOnKey, isActiveIterator, iteratorActivated, keySet, lockAllBuckets, lockAllBuckets, lockAllSegments, lockBucket, lockSegment, put, putAll, putInternal, releaseIterator, remove, removeInternal, setContainsValueAction, setGetEntryAction, setInsertAction, setRemoveAction, toArrayInternal, toString, unlockAllBuckets, unlockAllBuckets, unlockAllSegments, unlockBucket, unlockSegment, values

 

Methods inherited from interface com.tangosol.util.ConcurrentMap
containsKey, containsValue, get, put, putAll, remove

 

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

 

Field Detail

m_gateLockAll

protected ThreadGate m_gateLockAll
The ThreadGate controlling LOCK_ALL access for this map.

m_actionLock

protected SegmentedConcurrentMap.LockAction m_actionLock
The action for lock() support.

m_actionUnlock

protected SegmentedConcurrentMap.UnlockAction m_actionUnlock
The action for unlock() support.

m_actionSize

protected SegmentedConcurrentMap.SizeAction m_actionSize
The singleton action for size support.

Constructor Detail

SegmentedConcurrentMap

public SegmentedConcurrentMap()
Default constructor.

SegmentedConcurrentMap

public SegmentedConcurrentMap(int cInitialBuckets,
                              float flLoadFactor,
                              float flGrowthRate)
Construct a thread-safe hash map using the specified settings.
Parameters:
cInitialBuckets - the initial number of hash buckets, 0 < n
flLoadFactor - the acceptable load factor before resizing occurs, 0 < n, such that a load factor of 1.0 causes resizing when the number of entries exceeds the number of buckets
flGrowthRate - the rate of bucket growth when a resize occurs, 0 < n, such that a growth rate of 1.0 will double the number of buckets: bucketcount = bucketcount * (1 + growthrate)

Method Detail

getLockAction

protected SegmentedConcurrentMap.LockAction getLockAction()
Return the registered action for lock().
Returns:
the registered action for lock()

setLockAction

protected void setLockAction(SegmentedConcurrentMap.LockAction action)
Specify the action for lock().
Parameters:
action - the action for lock()

getUnlockAction

protected SegmentedConcurrentMap.UnlockAction getUnlockAction()
Return the registered action for unlock().
Returns:
the registered action for unlock()

setUnlockAction

protected void setUnlockAction(SegmentedConcurrentMap.UnlockAction action)
Specify the action for unlock().
Parameters:
action - the action for unlock()

getSizeAction

protected SegmentedConcurrentMap.SizeAction getSizeAction()
Return the registered action for size().
Returns:
the registered action for size()

setSizeAction

protected void setSizeAction(SegmentedConcurrentMap.SizeAction action)
Specify the action for size().
Parameters:
action - the action for size()

clear

public void clear()
Removes all mappings from this map.
Specified by:
clear in interface ConcurrentMap
Specified by:
clear in interface java.util.Map
Overrides:
clear in class SegmentedHashMap

size

public int size()
Returns the number of key-value mappings in this map. <p/> Note: Unlike some Map implementations, the size() operation on this map may be relatively expensive.
Specified by:
size in interface ConcurrentMap
Specified by:
size in interface java.util.Map
Overrides:
size in class SegmentedHashMap
Returns:
the number of key-value mappings in this map

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings.
Specified by:
isEmpty in interface ConcurrentMap
Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class SegmentedHashMap
Returns:
true if this map contains no key-value mappings

lock

public 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).

Specified by:
lock in interface ConcurrentMap
Parameters:
oKey - key being locked
Returns:
true if the item was successfully locked; false otherwise

lock

public 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 ConcurrentMap.LOCK_ALL as the oKey parameter to indicate the map lock.

Specified by:
lock in interface ConcurrentMap
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

unlock

public 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.
Specified by:
unlock in interface ConcurrentMap
Parameters:
oKey - key being unlocked
Returns:
true if the item was successfully unlocked; false otherwise

initializeActions

protected void initializeActions()
Initialize the EntryAction's for this map.
Overrides:
initializeActions in class SegmentedHashMap

instantiateRemoveAction

protected SegmentedHashMap.RemoveAction instantiateRemoveAction()
Factory for RemoveAction
Overrides:
instantiateRemoveAction in class SegmentedHashMap

instantiateLockAction

protected SegmentedConcurrentMap.LockAction instantiateLockAction()
Factory for LockAction

instantiateUnlockAction

protected SegmentedConcurrentMap.UnlockAction instantiateUnlockAction()
Factory for UnlockAction

instantiateSizeAction

protected SegmentedConcurrentMap.SizeAction instantiateSizeAction()
Factory for SizeAction

instantiateEntry

protected SegmentedHashMap.Entry instantiateEntry(java.lang.Object oKey,
                                                  java.lang.Object oValue,
                                                  int nHash)
Factory for Entry.
Overrides:
instantiateEntry in class SegmentedHashMap
Returns:
a new instance of the Entry class (or a subclass thereof)

Skip navigation links

Oracle® Coherence Java API Reference
v3.5

E14977-01


Copyright © 2000, 2009, Oracle. All rights reserved.