public class SegmentedConcurrentMap extends SegmentedHashMap implements ConcurrentMap, ConcurrentMap
See ConcurrentMap
| Modifier and Type | Class and Description |
|---|---|
protected class |
SegmentedConcurrentMap.ConditionalRemoveAction
Action support for a conditional remove().
|
static interface |
SegmentedConcurrentMap.ContentionObserver
ContentionObserver is used to observe the contention lock-related actions performed on the concurrent map.
|
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().
|
SegmentedHashMap.ContainsValueAction, SegmentedHashMap.Entry, SegmentedHashMap.EntryAction, SegmentedHashMap.EntryActionAdapter, SegmentedHashMap.EntrySet, SegmentedHashMap.GetEntryAction, SegmentedHashMap.InsertAction, SegmentedHashMap.IterableEntryAction, SegmentedHashMap.KeySet, SegmentedHashMap.Segment, SegmentedHashMap.ValuesCollectionBase.LoggingWriter, Base.StackFrame| Modifier and Type | Field and Description |
|---|---|
protected SegmentedConcurrentMap.ConditionalRemoveAction |
m_actionConditionalRemove
The singleton action for conditional remove.
|
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 static AtomicReferenceFieldUpdater |
m_atomicUpdaterValue
AtomicUpdater for the entry value.
|
protected SegmentedConcurrentMap.ContentionObserver |
m_contentionObserver
The ContentionObserver; may be null.
|
protected Gate |
m_gateLockAll
The Gate controlling LOCK_ALL access for this map.
|
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_SPINLOG_ALWAYS, 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_USLOCK_ALL| Constructor and 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
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all mappings from this map.
|
protected SegmentedConcurrentMap.ConditionalRemoveAction |
getConditionalRemoveAction()
Return the registered action for conditional remove.
|
SegmentedConcurrentMap.ContentionObserver |
getContentionObserver()
Return the ContentionObserver for this SegmentedConcurrentMap.
|
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 SegmentedConcurrentMap.ConditionalRemoveAction |
instantiateConditionalRemoveAction()
Factory for ConditionalRemoveAction
|
protected SegmentedHashMap.Entry |
instantiateEntry(Object oKey, 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(Object oKey)
Attempt to lock the specified item and return immediately.
|
boolean |
lock(Object oKey, long cWait)
Attempt to lock the specified item within the specified period of time.
|
Object |
putIfAbsent(Object oKey, Object oValue) |
boolean |
remove(Object oKey, Object oValue) |
Object |
replace(Object oKey, Object oValue) |
boolean |
replace(Object oKey, Object oValueOld, Object oValueNew) |
protected void |
setConditionalRemoveAction(SegmentedConcurrentMap.ConditionalRemoveAction action)
Specify the action for conditional remove.
|
protected void |
setContentionObserver(SegmentedConcurrentMap.ContentionObserver contentionObserver)
Set the ContentionObserver for this SegmentedConcurrentMap.
|
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(Object oKey)
Unlock the specified item.
|
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, valuesazzert, 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, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, 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, waitclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsKey, containsValue, get, put, putAll, removecompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAllprotected static AtomicReferenceFieldUpdater m_atomicUpdaterValue
protected Gate m_gateLockAll
protected SegmentedConcurrentMap.LockAction m_actionLock
protected SegmentedConcurrentMap.UnlockAction m_actionUnlock
protected SegmentedConcurrentMap.SizeAction m_actionSize
protected SegmentedConcurrentMap.ConditionalRemoveAction m_actionConditionalRemove
protected SegmentedConcurrentMap.ContentionObserver m_contentionObserver
public SegmentedConcurrentMap()
public SegmentedConcurrentMap(SegmentedConcurrentMap.ContentionObserver contentionObserver)
contentionObserver - the ContentionObserver
public SegmentedConcurrentMap(int cInitialBuckets,
float flLoadFactor,
float flGrowthRate)
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)
public SegmentedConcurrentMap(int cInitialBuckets,
float flLoadFactor,
float flGrowthRate,
SegmentedConcurrentMap.ContentionObserver contentionObserver)
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 ContentionObserverprotected SegmentedConcurrentMap.LockAction getLockAction()
protected void setLockAction(SegmentedConcurrentMap.LockAction action)
action - the action for lock()protected SegmentedConcurrentMap.UnlockAction getUnlockAction()
protected void setUnlockAction(SegmentedConcurrentMap.UnlockAction action)
action - the action for unlock()protected SegmentedConcurrentMap.SizeAction getSizeAction()
protected void setSizeAction(SegmentedConcurrentMap.SizeAction action)
action - the action for size()protected SegmentedConcurrentMap.ConditionalRemoveAction getConditionalRemoveAction()
protected void setConditionalRemoveAction(SegmentedConcurrentMap.ConditionalRemoveAction action)
action - the action for conditional removepublic SegmentedConcurrentMap.ContentionObserver getContentionObserver()
protected void setContentionObserver(SegmentedConcurrentMap.ContentionObserver contentionObserver)
contentionObserver - the contentionObserverpublic void clear()
clear in interface Mapclear in class SegmentedHashMappublic int size()
Note: Unlike some Map implementations, the size() operation on this map may be relatively expensive.
size in interface Mapsize in class SegmentedHashMappublic boolean isEmpty()
isEmpty in interface MapisEmpty in class SegmentedHashMappublic Object putIfAbsent(Object oKey, Object oValue)
putIfAbsent in interface ConcurrentMapputIfAbsent in interface Mappublic boolean replace(Object oKey, Object oValueOld, Object oValueNew)
replace in interface ConcurrentMapreplace in interface Mappublic Object replace(Object oKey, Object oValue)
replace in interface ConcurrentMapreplace in interface Mappublic boolean remove(Object oKey, Object oValue)
remove in interface ConcurrentMapremove in interface Mappublic boolean lock(Object oKey)
This method behaves exactly as if it simply performs the call lock(oKey, 0).
oKey - key being lockedpublic boolean lock(Object oKey, long cWait)
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.
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 obtainedpublic boolean unlock(Object oKey)
oKey - key being unlockedprotected void initializeActions()
initializeActions in class SegmentedHashMapprotected SegmentedHashMap.RemoveAction instantiateRemoveAction()
instantiateRemoveAction in class SegmentedHashMapprotected SegmentedConcurrentMap.ConditionalRemoveAction instantiateConditionalRemoveAction()
protected SegmentedConcurrentMap.LockAction instantiateLockAction()
protected SegmentedConcurrentMap.UnlockAction instantiateUnlockAction()
protected SegmentedConcurrentMap.SizeAction instantiateSizeAction()
protected SegmentedHashMap.Entry instantiateEntry(Object oKey, Object oValue, int nHash)
instantiateEntry in class SegmentedHashMapoKey - the keyoValue - the valuenHash - the hashCode value of the key