Class SegmentedConcurrentMap
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.util.SegmentedHashMap
-
- com.tangosol.util.SegmentedConcurrentMap
-
- All Implemented Interfaces:
ConcurrentMap,ConcurrentMap,Map
public class SegmentedConcurrentMap extends SegmentedHashMap implements ConcurrentMap, ConcurrentMap
An implementation of SegmentedHashMap that also implements the ConcurrentMap interface.See
ConcurrentMap- Since:
- Coherence 3.5
- Author:
- rhl 2008.12.01
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classSegmentedConcurrentMap.ConditionalRemoveActionAction support for a conditional remove().static interfaceSegmentedConcurrentMap.ContentionObserverContentionObserver is used to observe the contention lock-related actions performed on the concurrent map.protected classSegmentedConcurrentMap.DumpHeldLocksActionAction support for dumping held locks for a NearCache key/events control map.classSegmentedConcurrentMap.LockableEntryLockableEntry is an Entry that supports locking.protected classSegmentedConcurrentMap.LockActionAction support for lock().protected classSegmentedConcurrentMap.RemoveActionAction support for remove().protected static classSegmentedConcurrentMap.SizeActionAction support for size().protected classSegmentedConcurrentMap.TruncateActionAction support for truncate() for a NearCache key/events control map.protected classSegmentedConcurrentMap.UnlockActionAction 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 class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected SegmentedConcurrentMap.ConditionalRemoveActionm_actionConditionalRemoveThe singleton action for conditional remove.protected SegmentedConcurrentMap.DumpHeldLocksActionm_actionDumpHeldLocksThe singleton action dump held locks.protected SegmentedConcurrentMap.LockActionm_actionLockThe action for lock() support.protected SegmentedConcurrentMap.SizeActionm_actionSizeThe singleton action for size support.protected SegmentedConcurrentMap.TruncateActionm_actionTruncateThe singleton action for truncate.protected SegmentedConcurrentMap.UnlockActionm_actionUnlockThe action for unlock() support.protected static AtomicReferenceFieldUpdaterm_atomicUpdaterValueAtomicUpdater for the entry value.protected SegmentedConcurrentMap.ContentionObserverm_contentionObserverThe ContentionObserver; may be null.protected Gatem_gateLockAllThe Gate controlling LOCK_ALL access for this map.-
Fields inherited from class com.tangosol.util.SegmentedHashMap
BIGGEST_MODULO, DEFAULT_GROWTHRATE, DEFAULT_INITIALSIZE, DEFAULT_LOADFACTOR, EMPTY, 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 class com.tangosol.util.Base
DEFAULT_LOAD_FACTOR, LOG_ALWAYS, LOG_CONFIG, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_MAX, LOG_MIN, LOG_QUIET, LOG_WARN, POWER_0, POWER_G, POWER_K, POWER_M, POWER_T, UNIT_D, UNIT_H, UNIT_M, UNIT_MS, UNIT_NS, UNIT_S, UNIT_US
-
Fields inherited from interface com.tangosol.util.ConcurrentMap
LOCK_ALL
-
-
Constructor Summary
Constructors Constructor Description SegmentedConcurrentMap()Default constructor.SegmentedConcurrentMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate)Construct a SegmentedConcurrentMap using the specified settings.SegmentedConcurrentMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate, SegmentedConcurrentMap.ContentionObserver contentionObserver)Construct a thread-safe hash map using the specified settings.SegmentedConcurrentMap(SegmentedConcurrentMap.ContentionObserver contentionObserver)Construct a SegmentedConcurrentMap with the default settings and the specified ContentionObserver
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all mappings from this map.voiddumpHeldLocks()Debug aid to dump threads holding locks.protected SegmentedConcurrentMap.ConditionalRemoveActiongetConditionalRemoveAction()Return the registered action for conditional remove.SegmentedConcurrentMap.ContentionObservergetContentionObserver()Return the ContentionObserver for this SegmentedConcurrentMap.protected SegmentedConcurrentMap.LockActiongetLockAction()Return the registered action for lock().protected SegmentedConcurrentMap.SizeActiongetSizeAction()Return the registered action for size().protected SegmentedConcurrentMap.UnlockActiongetUnlockAction()Return the registered action for unlock().protected voidinitializeActions()Initialize the EntryAction's for this map.protected SegmentedConcurrentMap.ConditionalRemoveActioninstantiateConditionalRemoveAction()Factory for ConditionalRemoveActionprotected SegmentedConcurrentMap.DumpHeldLocksActioninstantiateDumpHeldLocksAction()Factory for LocksDumpActionprotected SegmentedHashMap.EntryinstantiateEntry(Object oKey, Object oValue, int nHash)Factory for Entry.protected SegmentedConcurrentMap.LockActioninstantiateLockAction()Factory for LockActionprotected SegmentedHashMap.RemoveActioninstantiateRemoveAction()Factory for RemoveActionprotected SegmentedConcurrentMap.SizeActioninstantiateSizeAction()Factory for SizeActionprotected SegmentedConcurrentMap.TruncateActioninstantiateTruncateAction()Factory for TruncateActionprotected SegmentedConcurrentMap.UnlockActioninstantiateUnlockAction()Factory for UnlockActionstatic booleanisAlive(Thread t)For diagnostic use only, detect Daemon pool thread is no longer active.booleanisEmpty()Returns true if this map contains no key-value mappings.booleanlock(Object oKey)Attempt to lock the specified item and return immediately.booleanlock(Object oKey, long cWait)Attempt to lock the specified item within the specified period of time.ObjectputIfAbsent(Object oKey, Object oValue)booleanremove(Object oKey, Object oValue)Objectreplace(Object oKey, Object oValue)booleanreplace(Object oKey, Object oValueOld, Object oValueNew)protected voidsetConditionalRemoveAction(SegmentedConcurrentMap.ConditionalRemoveAction action)Specify the action for conditional remove.protected voidsetContentionObserver(SegmentedConcurrentMap.ContentionObserver contentionObserver)Set the ContentionObserver for this SegmentedConcurrentMap.protected voidsetDumpHeldLocksAction(SegmentedConcurrentMap.DumpHeldLocksAction action)Specify the action for dump held locks.protected voidsetLockAction(SegmentedConcurrentMap.LockAction action)Specify the action for lock().protected voidsetSizeAction(SegmentedConcurrentMap.SizeAction action)Specify the action for size().protected voidsetTruncateAction(SegmentedConcurrentMap.TruncateAction action)Specify the action for truncate.protected voidsetUnlockAction(SegmentedConcurrentMap.UnlockAction action)Specify the action for unlock().intsize()Returns the number of key-value mappings in this map.voidtruncate()Truncate operation for control map.booleanunlock(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, getSegmentForKey, getSegmentIndex, getStableBucketArray, grow, grow, hashCode, instantiateContainsValueAction, instantiateEntrySet, instantiateGetEntryAction, instantiateInsertAction, instantiateKeySet, instantiateValuesCollection, invokeOnAllKeys, invokeOnKey, isActiveIterator, iteratorActivated, keySet, lockAllBuckets, lockAllBuckets, lockAllSegments, lockBucket, lockSegment, put, putAll, putInternal, putInternal, releaseIterator, remove, removeInternal, setContainsValueAction, setGetEntryAction, setInsertAction, setRemoveAction, toArrayInternal, toString, unlockAllBuckets, unlockAllBuckets, unlockAllSegments, unlockBucket, unlockSegment, values
-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, newHashMap, newHashMap, newHashSet, newHashSet, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tangosol.util.ConcurrentMap
containsKey, containsValue, get, put, putAll, remove
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
-
-
-
Field Detail
-
m_atomicUpdaterValue
protected static AtomicReferenceFieldUpdater m_atomicUpdaterValue
AtomicUpdater for the entry value.
-
m_gateLockAll
protected Gate m_gateLockAll
The Gate 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.
-
m_actionConditionalRemove
protected SegmentedConcurrentMap.ConditionalRemoveAction m_actionConditionalRemove
The singleton action for conditional remove.
-
m_actionTruncate
protected SegmentedConcurrentMap.TruncateAction m_actionTruncate
The singleton action for truncate.- Since:
- 12.2.1.4.21
-
m_actionDumpHeldLocks
protected SegmentedConcurrentMap.DumpHeldLocksAction m_actionDumpHeldLocks
The singleton action dump held locks.- Since:
- 12.2.1.4.21
-
m_contentionObserver
protected SegmentedConcurrentMap.ContentionObserver m_contentionObserver
The ContentionObserver; may be null.
-
-
Constructor Detail
-
SegmentedConcurrentMap
public SegmentedConcurrentMap()
Default constructor.
-
SegmentedConcurrentMap
public SegmentedConcurrentMap(SegmentedConcurrentMap.ContentionObserver contentionObserver)
Construct a SegmentedConcurrentMap with the default settings and the specified ContentionObserver- Parameters:
contentionObserver- the ContentionObserver
-
SegmentedConcurrentMap
public SegmentedConcurrentMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate)Construct a SegmentedConcurrentMap using the specified settings.- Parameters:
cInitialBuckets- the initial number of hash buckets, 0 < nflLoadFactor- 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 bucketsflGrowthRate- 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)
-
SegmentedConcurrentMap
public SegmentedConcurrentMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate, SegmentedConcurrentMap.ContentionObserver contentionObserver)Construct a thread-safe hash map using the specified settings.- Parameters:
cInitialBuckets- the initial number of hash buckets, 0 < nflLoadFactor- 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 bucketsflGrowthRate- 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)contentionObserver- the ContentionObserver
-
-
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()
-
getConditionalRemoveAction
protected SegmentedConcurrentMap.ConditionalRemoveAction getConditionalRemoveAction()
Return the registered action for conditional remove.- Returns:
- the registered action for conditional remove
-
setConditionalRemoveAction
protected void setConditionalRemoveAction(SegmentedConcurrentMap.ConditionalRemoveAction action)
Specify the action for conditional remove.- Parameters:
action- the action for conditional remove
-
setTruncateAction
protected void setTruncateAction(SegmentedConcurrentMap.TruncateAction action)
Specify the action for truncate.- Parameters:
action- the action for truncate- Since:
- 12.2.1.4.21
-
setDumpHeldLocksAction
protected void setDumpHeldLocksAction(SegmentedConcurrentMap.DumpHeldLocksAction action)
Specify the action for dump held locks.- Parameters:
action- the action for dump held locks- Since:
- 12.2.1.4.21
-
getContentionObserver
public SegmentedConcurrentMap.ContentionObserver getContentionObserver()
Return the ContentionObserver for this SegmentedConcurrentMap.- Returns:
- the ContentionObserver
-
setContentionObserver
protected void setContentionObserver(SegmentedConcurrentMap.ContentionObserver contentionObserver)
Set the ContentionObserver for this SegmentedConcurrentMap.- Parameters:
contentionObserver- the contentionObserver
-
clear
public void clear()
Removes all mappings from this map.- Specified by:
clearin interfaceConcurrentMap- Specified by:
clearin interfaceMap- Overrides:
clearin classSegmentedHashMap
-
size
public int size()
Returns the number of key-value mappings in this map.Note: Unlike some Map implementations, the size() operation on this map may be relatively expensive.
- Specified by:
sizein interfaceConcurrentMap- Specified by:
sizein interfaceMap- Overrides:
sizein classSegmentedHashMap- 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:
isEmptyin interfaceConcurrentMap- Specified by:
isEmptyin interfaceMap- Overrides:
isEmptyin classSegmentedHashMap- Returns:
- true if this map contains no key-value mappings
-
putIfAbsent
public Object putIfAbsent(Object oKey, Object oValue)
- Specified by:
putIfAbsentin interfaceConcurrentMap- Specified by:
putIfAbsentin interfaceMap
-
replace
public boolean replace(Object oKey, Object oValueOld, Object oValueNew)
- Specified by:
replacein interfaceConcurrentMap- Specified by:
replacein interfaceMap
-
replace
public Object replace(Object oKey, Object oValue)
- Specified by:
replacein interfaceConcurrentMap- Specified by:
replacein interfaceMap
-
remove
public boolean remove(Object oKey, Object oValue)
- Specified by:
removein interfaceConcurrentMap- Specified by:
removein interfaceMap
-
lock
public boolean lock(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:
lockin interfaceConcurrentMap- Parameters:
oKey- key being locked- Returns:
- true if the item was successfully locked; false otherwise
-
lock
public boolean lock(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_ALLas the oKey parameter to indicate the map lock.- Specified by:
lockin interfaceConcurrentMap- Parameters:
oKey- key being lockedcWait- 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(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:
unlockin interfaceConcurrentMap- 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:
initializeActionsin classSegmentedHashMap
-
truncate
public void truncate()
Truncate operation for control map.- Since:
- 12.2.1.4.21
-
dumpHeldLocks
public void dumpHeldLocks()
Debug aid to dump threads holding locks.- Since:
- 12.2.1.4.21
-
instantiateRemoveAction
protected SegmentedHashMap.RemoveAction instantiateRemoveAction()
Factory for RemoveAction- Overrides:
instantiateRemoveActionin classSegmentedHashMap- Returns:
- a RemoveAction
-
instantiateConditionalRemoveAction
protected SegmentedConcurrentMap.ConditionalRemoveAction instantiateConditionalRemoveAction()
Factory for ConditionalRemoveAction- Returns:
- a ConditionalRemoveAction
-
instantiateLockAction
protected SegmentedConcurrentMap.LockAction instantiateLockAction()
Factory for LockAction- Returns:
- a LockAction
-
instantiateUnlockAction
protected SegmentedConcurrentMap.UnlockAction instantiateUnlockAction()
Factory for UnlockAction- Returns:
- an UnlockAction
-
instantiateSizeAction
protected SegmentedConcurrentMap.SizeAction instantiateSizeAction()
Factory for SizeAction- Returns:
- a SizeAction
-
instantiateTruncateAction
protected SegmentedConcurrentMap.TruncateAction instantiateTruncateAction()
Factory for TruncateAction- Returns:
- a TruncateAction
- Since:
- 12.2.1.4.21
-
instantiateDumpHeldLocksAction
protected SegmentedConcurrentMap.DumpHeldLocksAction instantiateDumpHeldLocksAction()
Factory for LocksDumpAction- Returns:
- a LocksDumpAction
- Since:
- 12.2.1.4.21
-
instantiateEntry
protected SegmentedHashMap.Entry instantiateEntry(Object oKey, Object oValue, int nHash)
Factory for Entry.- Overrides:
instantiateEntryin classSegmentedHashMap- Parameters:
oKey- the keyoValue- the valuenHash- the hashCode value of the key- Returns:
- a new instance of the Entry class (or a subclass thereof)
-
isAlive
public static boolean isAlive(Thread t)
For diagnostic use only, detect Daemon pool thread is no longer active. This method is only used in dumpHeldLocks() to automate checking if a LockableEntry is pointing to a DaemonThread pool that is in waiting state. This method does not account for any other ThreadPool implementation except Coherences.- Parameters:
t- the thread- Returns:
- true iff the stack trace does not include Daemon.wait().
- Since:
- 12.2.1.4.21
-
-