public class WrapperConcurrentMap<K,V> extends WrapperObservableMap<K,V> implements ConcurrentMap<K,V>
Modifier and Type | Class and Description |
---|---|
protected static class |
WrapperConcurrentMap.Lock
A lock object.
|
WrapperObservableMap.InternalListener
AbstractKeySetBasedMap.EntrySet, AbstractKeySetBasedMap.KeyIterator, AbstractKeySetBasedMap.KeySet, AbstractKeySetBasedMap.ValuesCollection
AbstractKeyBasedMap.DeferredCacheEvent<K,V>
Base.LoggingWriter, Base.StackFrame
Modifier and Type | Field and Description |
---|---|
protected long |
m_cWaitMillis
The number of milliseconds to continue trying to obtain a lock
in case when the locking is enforced.
|
protected boolean |
m_fEnforceLocking
Flag indicating whether or not the locking is enforced for put, remove
and clear operations.
|
protected Gate |
m_gateMap
The ThreadGate object for the entire map.
|
protected SafeHashMap |
m_mapLock
The map containing all the locks.
|
m_fDeferredEvent, m_fTranslateEvents, m_listenerInternal, m_listenerSupport, m_map, m_stats
LOG_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_US
LOCK_ALL
Constructor and Description |
---|
WrapperConcurrentMap(Map<K,V> map)
Construct a ConcurrentMap wrapper based on the specified map with
locking enforced for put, remove and clear operations.
|
WrapperConcurrentMap(Map<K,V> map,
boolean fEnforceLocking,
long cWaitMillis)
Construct a ConcurrentMap wrapper based on the specified map.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all key/value mappings.
|
protected String |
getDescription()
Assemble a human-readable description.
|
String |
getLockDescription(Object oKey)
Make a human-readable description of the information kept about the
passed key.
|
long |
getWaitMillis()
Return the number of milliseconds to continue trying to obtain a lock
in case when the locking is enforced.
|
protected WrapperConcurrentMap.Lock |
instantiateLock(Object oKey)
Factory pattern.
|
protected boolean |
isInternalKeySetIteratorMutable()
Determine if this Iterator should remove an iterated item by calling
remove on the internal key Set Iterator, or by calling removeBlind on
the map itself.
|
boolean |
isLockingEnforced()
Obtain the flag indicating whether or not the locking is enforced for
put, remove and clear operations.
|
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.
|
V |
put(K oKey,
V oValue)
Associates the specified value with the specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map.
|
V |
remove(Object oKey)
Removes the mapping for this key from this map if present.
|
protected boolean |
removeBlind(Object oKey)
Removes the mapping for this key from this map if present.
|
void |
setLockingEnforced(boolean fEnforce)
Set the flag indicating whether or not the locking is enforced for
put, remove and clear operations.
|
void |
setWaitMillis(long cWaitMillis)
Specify the number of milliseconds to continue trying to obtain a lock
in case when the locking is enforced.
|
String |
toString()
Returns a string representation of this Map.
|
boolean |
unlock(Object oKey)
Unlock the specified item.
|
addMapListener, addMapListener, addMapListener, containsValue, dispatchEvent, dispatchPendingEvent, ensureInternalListener, ensureMapListenerSupport, equals, get, getCacheStatistics, getInternalKeySet, getMap, getMapListenerSupport, hashCode, hasListeners, instantiateInternalListener, isCollectStats, isEventFabricator, isSynthetic, isTranslateEvents, removeMapListener, removeMapListener, removeMapListener, setCollectStats, setTranslateEvents
containsKey, instantiateEntrySet, instantiateKeyIterator, instantiateKeySet, instantiateValues, isEmpty, iterateKeys, size
clone, entrySet, getAll, keySet, values
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, 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, 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
finalize, getClass, notify, notifyAll, wait, wait, wait
containsKey, containsValue, get, isEmpty, size
compute, computeIfAbsent, computeIfPresent, entrySet, equals, forEach, getOrDefault, hashCode, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, values
protected boolean m_fEnforceLocking
protected long m_cWaitMillis
protected final SafeHashMap m_mapLock
protected final Gate m_gateMap
public WrapperConcurrentMap(Map<K,V> map)
Note: it is assumed that while the WrapperConcurrentMap exists, there is no direct manipulation with the content of the wrapped map.
map
- the Map that will be wrapped by this WrapperConcurrentMappublic WrapperConcurrentMap(Map<K,V> map, boolean fEnforceLocking, long cWaitMillis)
Note: it is assumed that while the WrapperConcurrentMap exists, there is no direct manipulation with the content of the wrapped map.
map
- the Map that will be wrapped by this
WrapperConcurrentMapfEnforceLocking
- if true the locking is enforced for put, remove
and clear operations; otherwise a client is
responsible for calling lock and unlock explicitlycWaitMillis
- if locking enforcement is required then this
parameter specifies the number of milliseconds to
continue trying to obtain a lock; pass -1 to block
the calling thread until the lock could be obtainedpublic 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.
lock
in interface ConcurrentMap<K,V>
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 lock(Object oKey)
This method behaves exactly as if it simply performs the call lock(oKey, 0).
lock
in interface ConcurrentMap<K,V>
oKey
- key being lockedpublic boolean unlock(Object oKey)
unlock
in interface ConcurrentMap<K,V>
oKey
- key being unlockedpublic void clear()
If lock enforcement is required an attempt will be made to lock the
entire map using the ConcurrentMap.LOCK_ALL
object.
Note: if this operation fails due to a ConcurrentModificationException, then any subset of the current mappings could still remain in the map.
clear
in interface ConcurrentMap<K,V>
clear
in interface Map<K,V>
clear
in class WrapperObservableMap<K,V>
ConcurrentModificationException
- if any entry is locked
by another threadpublic V put(K oKey, V oValue)
put
in interface ConcurrentMap<K,V>
put
in interface Map<K,V>
put
in class WrapperObservableMap<K,V>
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keyConcurrentModificationException
- if the entry is locked
by another threadpublic void putAll(Map<? extends K,? extends V> map)
AbstractKeyBasedMap.put(K, V)
on this map once for each mapping in the passed map. The behavior of
this operation is unspecified if the passed map is modified while the
operation is in progress.putAll
in interface ConcurrentMap<K,V>
putAll
in interface Map<K,V>
putAll
in class WrapperObservableMap<K,V>
map
- the Map containing the key/value pairings to put into this
MapConcurrentModificationException
- if the entry is locked
by another threadpublic V remove(Object oKey)
remove
in interface ConcurrentMap<K,V>
remove
in interface Map<K,V>
remove
in class WrapperObservableMap<K,V>
oKey
- key whose mapping is to be removed from the mapConcurrentModificationException
- if the entry is locked
by another threadprotected boolean isInternalKeySetIteratorMutable()
isInternalKeySetIteratorMutable
in class WrapperObservableMap<K,V>
AbstractKeyBasedMap.removeBlind(Object)
methodprotected boolean removeBlind(Object oKey)
removeBlind
in class WrapperObservableMap<K,V>
oKey
- key whose mapping is to be removed from the mapConcurrentModificationException
- if the entry is locked
by another threadpublic String toString()
toString
in class WrapperObservableMap<K,V>
public boolean isLockingEnforced()
public void setLockingEnforced(boolean fEnforce)
fEnforce
- pass true to enforce locking; false otherwisepublic long getWaitMillis()
public void setWaitMillis(long cWaitMillis)
cWaitMillis
- the wait time in millisecondsprotected String getDescription()
getDescription
in class WrapperObservableMap<K,V>
public String getLockDescription(Object oKey)
oKey
- the keyprotected WrapperConcurrentMap.Lock instantiateLock(Object oKey)
oKey
- the key