Class SegmentedHashMap
- All Implemented Interfaces:
- Map
- Direct Known Subclasses:
- SegmentedConcurrentMap
Retrieval and update operations to the map (e.g. get, put) are non-blocking and uncontended and will reflect some state of the map. Insert and remove operations to the map (e.g. put, remove) do require internal locking.
The entries in the map are internally segmented so as to permit a high level of concurrent "locked" operations without contention.
Retrievals and updates that run concurrently with bulk operations (e.g. putAll, clear may reflect insertion or removal of only some entries. Iterators on the Map may also reflect concurrent updates made since the Iterator was created. However, Iterators will not throw ConcurrentModificationException.
- Since:
- Coherence 3.5
- Author:
- rhl 2008.12.01
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classAction support for containsValue().protected static classA map entry (key-value pair).protected static interfaceAn EntryAction encapsulates a logical action to be executed in the context of a key (that may or may not exist in the map).protected static classEntryActionAdapter is a convenience class that provides default implementations for the EntryAction and IterableEntryAction interface methods.protected classA set of entries backed by this map.protected classAction support for getEntryInternal.protected classAction support for insert.protected static interfaceIterableEntryAction is an EntryAction that is suitable for applying to all keys in a map.protected classA set of entries backed by this map.protected classAction support for remove().protected static classSegment metadata.protected classA collection of values backed by this map.Nested classes/interfaces inherited from class com.tangosol.util.BaseBase.LoggingWriter
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final intBiggest possible modulo.static final floatUsing the default growth rate, the bucket array will grow by a factor of four.static final intDefault initial size provides a prime modulo and is large enough that resize is not immediate.static final floatThe default load factor is 100%, which means that the hash map will not resize until there is (on average) one entry in every bucket.static final Map<?, ?> An empty, immutable SegmentedHashMap instance.protected static final longThe bit-mask used to indicate that a lock-all is pending.protected static final intThe mutex number used to indicate that a lock-all is pending.protected static final intThe number of segment-locks.protected static final longThe lock representation used to indicate that all mutexes are locked.protected static final longThe lock representation used to indicate that no locks are set.protected SegmentedHashMap.ContainsValueActionThe singleton action for containsValue support.protected SegmentedHashMap.GetEntryActionThe singleton action for getEntryInternal support.protected SegmentedHashMap.InsertActionThe singleton action for insert support.protected SegmentedHashMap.RemoveActionThe singleton action for remove support.protected SegmentedHashMap.Entry[]The array of hash buckets.protected final SegmentedHashMap.Segment[]An array of the control-structures for the Map's segments.protected final AtomicLongThe "segment-locks".protected SegmentedHashMap.ValuesCollectionThe collection of values backed by this map.protected intThe capacity of each segment (the point at which we should resize).protected final floatThe rate of growth as a fraction of the current number of buckets, 0 < n, such that the hash map grows to bucketcount * (1 + growth-rate).protected final floatThe determining factor for the hash map capacity given a certain number of buckets, such that capacity = bucketcount * loadfactor.protected ObjectA holder for active Iterator(s): either WeakReference(<Iterator>) or WeakHashMap(<Iterator> null)protected SegmentedHashMap.EntrySetThe set of entries backed by this map.protected SegmentedHashMap.KeySetThe set of keys backed by this map.protected static final intThe minimum segment capacity.protected static final ObjectObject to be used as a value representing that the Entry object is "synthetic" and while logically associated with a key, does not represent a key-value mapping in the Map.protected static final int[]A list of possible modulos to use.protected static final intSize threshold used by the putAll operation.protected final ObjectWhen resizing completes, a notification is issued against this object.protected static final intThe number of segments to partition the hash buckets into.protected static final intMaximum number of times to spin while trying to acquire a segment lock before waiting.
- 
Constructor SummaryConstructorsConstructorDescriptionDefault constructor.SegmentedHashMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate) Construct a thread-safe hash map using the specified settings.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()Removes all mappings from this map.booleancontainsKey(Object oKey) Returns true iff this map contains a mapping for the specified key.booleancontainsValue(Object oValue) Returns true if this map maps one or more keys to the specified value.protected voidcontendForSegment(int nSegment) Wait for a segment to be unlocked.protected voidensureLoadFactor(SegmentedHashMap.Segment segment) Check whether or not the specified segment is overloaded and if so, grow the bucket array (which suggests with high probability that the per-segment load will decrease).protected static SegmentedHashMap.EntryentryFromBucket(SegmentedHashMap.Entry[] aeBucket, int nBucket) Return the first non-synthetic Entry object contained by in the specified bucket.entrySet()Returns a set view of the mappings contained in this map.booleanCompares the specified object with this map for equality.Returns the value to which this map maps the specified key.protected intgetBucketIndex(int nHash, int cBuckets) Calculate the bucket number for a particular hash code.protected SegmentedHashMap.ContainsValueActionReturn the registered action for containsValue().Locate an Entry in the this map based on its key.protected SegmentedHashMap.EntrygetEntryInternal(Object oKey) Locate an Entry in the hash map based on its key.protected SegmentedHashMap.EntrygetEntryInternal(Object oKey, boolean fSynthetic) Locate an Entry in the hash map based on its key.protected SegmentedHashMap.GetEntryActionReturn the registered action for getEntryInternal.protected SegmentedHashMap.InsertActionReturn the registered action for insert.protected SegmentedHashMap.RemoveActionReturn the registered action for remove().protected SegmentedHashMap.SegmentgetSegmentForKey(Object oKey) Return the Segment object for the specified key.protected intgetSegmentIndex(int nBucket) Calculate the segment index for the specified bucket.protected SegmentedHashMap.Entry[]Get the bucket array, or if a resize is occurring, wait for the resize to complete and return the new bucket array.protected voidgrow()Resize the bucket array, rehashing all Entries.protected voidgrow(int cNew) Resize the bucket array to the specified size, rehashing all Entries.inthashCode()Returns the hash code value for this Map.protected voidInitialize the EntryAction's for this map.protected SegmentedHashMap.ContainsValueActionFactory for ContainsValueActionprotected SegmentedHashMap.EntryinstantiateEntry(Object oKey, Object oValue, int nHash) Factory for Entry.protected SegmentedHashMap.EntrySetFactory for EntrySetprotected SegmentedHashMap.GetEntryActionFactory for GetEntryActionprotected SegmentedHashMap.InsertActionFactory for InsertActionprotected SegmentedHashMap.KeySetFactory for KeySet.protected SegmentedHashMap.RemoveActionFactory for RemoveActionprotected SegmentedHashMap.ValuesCollectionFactory for ValuesCollection.protected ObjectinvokeOnAllKeys(Object oContext, boolean fLock, SegmentedHashMap.IterableEntryAction actionEntry) Perform an action on all Entries in the map.protected ObjectinvokeOnKey(Object oKey, Object oContext, boolean fLock, SegmentedHashMap.EntryAction action) Perform an action on the specified key.protected booleanDetermine if there are any active Iterators, which may mean that they are in the middle of iterating over the Map.booleanisEmpty()Returns true if this map contains no key-value mappings.protected voiditeratorActivated(Iterator iter) Register the activation of an Iterator.keySet()Returns a Set view of the keys contained in this map.protected voidLock everything.protected booleanlockAllBuckets(int nBucketAlreadyLocked) Lock everything, assuming that the segment for the specified bucket has already been locked.protected booleanlockAllSegments(long lLocksHeld) Lock all segments except for the specified segments that have already been locked by the calling thread.protected booleanlockBucket(int nBucket) Attempt to lock the segment corresponding to the specified bucket.protected booleanlockSegment(int nSegment, boolean fBlock) Attempt to lock the specified segment.Associates the specified value with the specified key in this map.voidCopies all of the mappings from the specified map to this map.protected ObjectputInternal(Object oKey, Object oValue) Associates the specified value with the specified key in this map.protected ObjectputInternal(Object oKey, Object oValue, boolean fOnlyIfAbsent) Associates the specified value with the specified key in this map.voidreleaseIterator(Iterator iter) Release the (formerly-active) Iterator.Removes the mapping for this key from this map if present.protected ObjectremoveInternal(Object oKey, SegmentedHashMap.EntryAction actionRemove, Object oContext) Removes the mapping for this key from this map if present.protected voidSpecify the action for containsValue().protected voidSpecify the action for getEntryInternal.protected voidSpecify the action for insert.protected voidSpecify the action for remove().intsize()Returns the number of key-value mappings in this map.protected Object[]toArrayInternal(SegmentedHashMap.IterableEntryAction action, Object[] a) Apply the specified toArray() action to the entries in the map.toString()Returns a String representation of this map.protected voidUnlock everything.protected voidunlockAllBuckets(int nBucketLeaveLocked) Unlock everything, leaving only the segment for the specified bucket locked.protected voidunlockAllSegments(long lLocksKeep) Unlock all segments, except the segment-locks indicated by the specified bit-vector.protected voidunlockBucket(int nBucket) Unlock the segment corresponding to the specified bucket that was previously locked using thelockBucket(int)method.protected voidunlockSegment(int nSegment) Unlock the specified segment previously locked using thelockSegment(int, boolean)method.values()Returns a collection view of the values contained in this map.Methods inherited from class com.tangosol.util.Baseazzert, 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, waitMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
PRIME_MODULOprotected static final int[] PRIME_MODULOA list of possible modulos to use.
- 
DEFAULT_INITIALSIZEpublic static final int DEFAULT_INITIALSIZEDefault initial size provides a prime modulo and is large enough that resize is not immediate. (A hash map probably uses less than 128 bytes initially.)
- 
BIGGEST_MODULOprotected static final int BIGGEST_MODULOBiggest possible modulo.
- 
DEFAULT_LOADFACTORpublic static final float DEFAULT_LOADFACTORThe default load factor is 100%, which means that the hash map will not resize until there is (on average) one entry in every bucket. The cost of scanning a linked list in a particular bucket is very low, so there is little reason for having this value below 1.0, and the goal is constant order access, so assuming a perfect hash this will provide the optimal access speed relative to size.- See Also:
 
- 
DEFAULT_GROWTHRATEpublic static final float DEFAULT_GROWTHRATEUsing the default growth rate, the bucket array will grow by a factor of four. The relatively high growth rate helps to ensure less resize operations, an important consideration in a high-concurrency map.- See Also:
 
- 
MIN_SEGMENT_CAPACITYprotected static final int MIN_SEGMENT_CAPACITYThe minimum segment capacity.- See Also:
 
- 
SEGMENT_COUNTprotected static final int SEGMENT_COUNTThe number of segments to partition the hash buckets into. There is a single lock for each segment. This number is specially chosen as 61 is the largest prime number smaller than 64 (the size of the datatype used to represent the lock).- See Also:
 
- 
LOCK_COUNTprotected static final int LOCK_COUNTThe number of segment-locks. Each segment has its own lock and there is a global "intention" lock.- See Also:
 
- 
LOCKS_NONEprotected static final long LOCKS_NONEThe lock representation used to indicate that no locks are set.- See Also:
 
- 
LOCKS_ALLprotected static final long LOCKS_ALLThe lock representation used to indicate that all mutexes are locked.- See Also:
 
- 
LOCK_ALL_PENDING_IDXprotected static final int LOCK_ALL_PENDING_IDXThe mutex number used to indicate that a lock-all is pending.- See Also:
 
- 
LOCK_ALL_PENDINGprotected static final long LOCK_ALL_PENDINGThe bit-mask used to indicate that a lock-all is pending.- See Also:
 
- 
SEGMENT_LOCK_MAX_SPINprotected static final int SEGMENT_LOCK_MAX_SPINMaximum number of times to spin while trying to acquire a segment lock before waiting.- See Also:
 
- 
PUTALL_THRESHOLDprotected static final int PUTALL_THRESHOLDSize threshold used by the putAll operation.- See Also:
 
- 
NO_VALUEObject to be used as a value representing that the Entry object is "synthetic" and while logically associated with a key, does not represent a key-value mapping in the Map.
- 
EMPTYAn empty, immutable SegmentedHashMap instance.
- 
RESIZINGWhen resizing completes, a notification is issued against this object.
- 
m_atomicLocksThe "segment-locks". This AtomicCounter is actually used just as an "Atomic Long" value, with each of the first 61 bits being used to represent a segment-lock. In this case, the number of "buckets" is fixed to 61 (the largest prime smaller than 64).
- 
m_aSegmentAn array of the control-structures for the Map's segments.
- 
m_aeBucketThe array of hash buckets. This field is declared volatile in order to reduce synchronization.
- 
m_cSegmentCapacityprotected int m_cSegmentCapacityThe capacity of each segment (the point at which we should resize).
- 
m_flLoadFactorprotected final float m_flLoadFactorThe determining factor for the hash map capacity given a certain number of buckets, such that capacity = bucketcount * loadfactor.
- 
m_flGrowthRateprotected final float m_flGrowthRateThe rate of growth as a fraction of the current number of buckets, 0 < n, such that the hash map grows to bucketcount * (1 + growth-rate).
- 
m_setEntriesThe set of entries backed by this map.
- 
m_setKeysThe set of keys backed by this map.
- 
m_colValuesThe collection of values backed by this map.
- 
m_oIterActiveA holder for active Iterator(s): either WeakReference(<Iterator>) or WeakHashMap(<Iterator> null)
- 
m_actionGetEntryThe singleton action for getEntryInternal support.
- 
m_actionInsertThe singleton action for insert support.
- 
m_actionRemoveThe singleton action for remove support.
- 
m_actionContainsValueThe singleton action for containsValue support.
 
- 
- 
Constructor Details- 
SegmentedHashMappublic SegmentedHashMap()Default constructor.
- 
SegmentedHashMappublic SegmentedHashMap(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 Details- 
getInsertActionReturn the registered action for insert.- Returns:
- the registered action for insert
 
- 
setInsertActionSpecify the action for insert.- Parameters:
- action- the action for insert
 
- 
getGetEntryActionReturn the registered action for getEntryInternal.- Returns:
- the registered action for getEntryInternal
 
- 
setGetEntryActionSpecify the action for getEntryInternal.- Parameters:
- action- the action for getEntryInternal
 
- 
getRemoveActionReturn the registered action for remove().- Returns:
- the registered action for remove()
 
- 
setRemoveActionSpecify the action for remove().- Parameters:
- action- the action for remove()
 
- 
getContainsValueActionReturn the registered action for containsValue().- Returns:
- the registered action for containsValue()
 
- 
setContainsValueActionSpecify the action for containsValue().- Parameters:
- action- the action for containsValue()
 
- 
equalsCompares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps t1 and t2 represent the same mappings if t1.keySet().equals(t2.keySet()) and for every key k in t1.keySet(), (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))) . This ensures that the equals method works properly across different implementations of the map interface.
- 
hashCodepublic int hashCode()Returns the hash code value for this Map. The hash code of a Map is defined to be the sum of the hash codes of each entry in the Map's entrySet() view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by the general contract of Object.hashCode.
- 
toStringReturns a String representation of this map.
- 
sizepublic 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. 
- 
isEmptypublic boolean isEmpty()Returns true if this map contains no key-value mappings.
- 
containsKeyReturns true iff this map contains a mapping for the specified key.- Specified by:
- containsKeyin interface- Map
- Parameters:
- oKey- key whose presence in this map is to be tested
- Returns:
- true iff this map contains a mapping for the specified key
 
- 
containsValueReturns true if this map maps one or more keys to the specified value.- Specified by:
- containsValuein interface- Map
- Parameters:
- oValue- value whose presence in this map is to be tested
- Returns:
- true if this map maps one or more keys to the specified value
 
- 
getReturns 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.
- 
getEntryLocate an Entry in the this map based on its key.- Parameters:
- key- the key object to search for
- Returns:
- the Entry or null if the entry does not exist
 
- 
putAssociates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.- Specified by:
- putin interface- Map
- Parameters:
- oKey- key with which the specified value is to be associated
- oValue- 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
 
- 
putAllCopies all of the mappings from the specified map to this map. putAll is semantically equivalent to:for (Iterator iter = mapOther.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry) iter.next(); put(entry.getKey(), entry.getValue()); }
- 
removeRemoves the mapping for this key from this map if present.
- 
clearpublic void clear()Removes all mappings from this map.
- 
entrySetReturns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
- 
keySetReturns a Set view of the keys contained in this map. The Set is backed by the map, so changes to the map are reflected in the Set, and vice-versa. (If the map is modified while an iteration over the Set is in progress, the results of the iteration are undefined.) The Set supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.
- 
valuesReturns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
- 
initializeActionsprotected void initializeActions()Initialize the EntryAction's for this map.
- 
getEntryInternalLocate an Entry in the hash map based on its key.- Parameters:
- oKey- the key object to search for
- Returns:
- the Entry or null
 
- 
getEntryInternalLocate an Entry in the hash map based on its key.- Parameters:
- oKey- the key object to search for
- fSynthetic- include synthetic Entry objects representing keys that are not contained in the map
- Returns:
- the Entry or null
 
- 
putInternalAssociates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.- Parameters:
- oKey- key with which the specified value is to be associated
- oValue- value to be associated with the specified key
- Returns:
- previous value associated with specified key, or NO_VALUE if there was no mapping for key. A null return indicates that the map previously associated null with the specified key
 
- 
putInternalAssociates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.- Parameters:
- oKey- key with which the specified value is to be associated
- oValue- value to be associated with the specified key
- fOnlyIfAbsent- if true, perform a logical insert only; no action if the key already exists
- Returns:
- previous value associated with specified key, or NO_VALUE if there was no mapping for key. A null return indicates that the map previously associated null with the specified key
 
- 
removeInternalprotected Object removeInternal(Object oKey, SegmentedHashMap.EntryAction actionRemove, Object oContext) Removes the mapping for this key from this map if present.- Parameters:
- oKey- key whose mapping is to be removed from the map
- actionRemove- the EntryAction to apply
- oContext- the context for the remove action
- Returns:
- previous value associated with specified key, or NO_VALUE if there was no mapping for key. A null return indicates that the map previously associated null with the specified key.
 
- 
toArrayInternalApply the specified toArray() action to the entries in the map. The toArray() action is not applied under any segment lock and is expected to accept a List instance as a context.- Parameters:
- action- the toArray() action
- a- the array into which the elements of the Collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
- Returns:
- an array containing the elements returned by the specified action
- Throws:
- ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type of the elements returned by the specified action
 
- 
ensureLoadFactorCheck whether or not the specified segment is overloaded and if so, grow the bucket array (which suggests with high probability that the per-segment load will decrease).- Parameters:
- segment- the segment to ensure the load-factor for
 
- 
growprotected void grow()Resize the bucket array, rehashing all Entries.Note: caller of this method is expected to hold locks on all segments of the map while making this call. 
- 
growprotected void grow(int cNew) Resize the bucket array to the specified size, rehashing all Entries.Note: caller of this method is expected to hold locks on all segments of the map while making this call. - Parameters:
- cNew- the minimum size to attempt to grow to
 
- 
invokeOnAllKeysprotected Object invokeOnAllKeys(Object oContext, boolean fLock, SegmentedHashMap.IterableEntryAction actionEntry) Perform an action on all Entries in the map. The action is provided as an EntryAction and (if the fLock is specified) it are invoked while holding the locks for all segments.The semantics of invokeOnAllKeys are equivalent to: for (Iterator iter = entrySet().iterator(); iter.hasNext(); ) { Entry entry = (Entry) iter.next(); actionEntry.invokeFound(...); } return oContext;Except that if fLock is specified, it is performed atomically while holding all segment-locks.- Parameters:
- oContext- opaque context for the specified action
- fLock- true if all segment-locks should be acquired before invoking the specified action
- actionEntry- the action to perform for each entry
- Returns:
- the specified opaque context
 
- 
invokeOnKeyprotected Object invokeOnKey(Object oKey, Object oContext, boolean fLock, SegmentedHashMap.EntryAction action) Perform an action on the specified key. The action operation is provided as an EntryAction and (if fLock is specified), is invoked while holding the appropriate segment lock for the key.The semantics of invokeOnKey are equivalent to: Object oResult; if (containsKey(oKey)) { oResult = action.invokeFound(...); } else { oResult = action.invokeNotFound(...); } return oResult;Except that if fLock is specified, it is performed atomically while holding the segment-lock.- Parameters:
- oKey- the key to act on
- oContext- opaque context for the specified action
- fLock- true iff the segment should be locked before invoking the specified action
- action- the action to invoke
- Returns:
- the result of performing the action
 
- 
getBucketIndexprotected int getBucketIndex(int nHash, int cBuckets) Calculate the bucket number for a particular hash code.- Parameters:
- nHash- the hash code
- cBuckets- the number of buckets
- Returns:
- the bucket index for the specified hash code
 
- 
getSegmentIndexprotected int getSegmentIndex(int nBucket) Calculate the segment index for the specified bucket.- Parameters:
- nBucket- the bucket number
- Returns:
- the segment index
 
- 
getSegmentForKeyReturn the Segment object for the specified key.- Parameters:
- oKey- the key
- Returns:
- the Segment for the specified key
 
- 
getStableBucketArrayGet the bucket array, or if a resize is occurring, wait for the resize to complete and return the new bucket array.- Returns:
- the latest bucket array
 
- 
iteratorActivatedRegister the activation of an Iterator.Note: The map will not grow while there are any active iterators. - Parameters:
- iter- the activated iterator
 
- 
releaseIteratorRelease the (formerly-active) Iterator.Note: This method could be used to accelerate the destruction of unexhausted iterators. - Parameters:
- iter- the iterator to be released
 
- 
isActiveIteratorprotected boolean isActiveIterator()Determine if there are any active Iterators, which may mean that they are in the middle of iterating over the Map.- Returns:
- true iff there is at least one active Iterator
 
- 
lockBucketprotected boolean lockBucket(int nBucket) Attempt to lock the segment corresponding to the specified bucket.- Parameters:
- nBucket- the bucket index
- Returns:
- true iff the segment was successfully locked
 
- 
lockSegmentprotected boolean lockSegment(int nSegment, boolean fBlock) Attempt to lock the specified segment.- Parameters:
- nSegment- the segment to lock
- fBlock- should we block on trying to lock the segment
- Returns:
- true iff the segment was successfully locked
 
- 
unlockBucketprotected void unlockBucket(int nBucket) Unlock the segment corresponding to the specified bucket that was previously locked using thelockBucket(int)method.- Parameters:
- nBucket- the bucket to unlock
 
- 
unlockSegmentprotected void unlockSegment(int nSegment) Unlock the specified segment previously locked using thelockSegment(int, boolean)method.- Parameters:
- nSegment- the segment to unlock
 
- 
contendForSegmentprotected void contendForSegment(int nSegment) Wait for a segment to be unlocked.- Parameters:
- nSegment- the segment-lock to be waited for
 
- 
lockAllBucketsprotected void lockAllBuckets()Lock everything. This method will not return until the lock is placed. It must not be called on a thread that could already hold a lock.
- 
lockAllBucketsprotected boolean lockAllBuckets(int nBucketAlreadyLocked) Lock everything, assuming that the segment for the specified bucket has already been locked.- Parameters:
- nBucketAlreadyLocked- the bucket that was already locked.
- Returns:
- false if the operation failed because another thread was also trying to lock everything (indicating potential deadlock)
 
- 
unlockAllBucketsprotected void unlockAllBuckets()Unlock everything.
- 
unlockAllBucketsprotected void unlockAllBuckets(int nBucketLeaveLocked) Unlock everything, leaving only the segment for the specified bucket locked.- Parameters:
- nBucketLeaveLocked- the bucket that was already locked
 
- 
lockAllSegmentsprotected boolean lockAllSegments(long lLocksHeld) Lock all segments except for the specified segments that have already been locked by the calling thread.- Parameters:
- lLocksHeld- the bit-mask representing all segment-locks that the calling thread already holds
- Returns:
- false if the operation failed because another thread was also trying to lock everything (indicating potential deadlock)
 
- 
unlockAllSegmentsprotected void unlockAllSegments(long lLocksKeep) Unlock all segments, except the segment-locks indicated by the specified bit-vector. This method must only be called by a thread if that thread has successfully calledlockAllSegments(long).- Parameters:
- lLocksKeep- the segment-locks to keep locked
 
- 
instantiateGetEntryActionFactory for GetEntryAction- Returns:
- a GetEntryAction
 
- 
instantiateInsertActionFactory for InsertAction- Returns:
- an InsertAction
 
- 
instantiateRemoveActionFactory for RemoveAction- Returns:
- a RemoveAction
 
- 
instantiateContainsValueActionFactory for ContainsValueAction- Returns:
- a ContainsValueAction
 
- 
instantiateEntryFactory for Entry.- Parameters:
- oKey- the key
- oValue- the value
- nHash- the hashCode value of the key
- Returns:
- a new instance of the Entry class (or a subclass thereof)
 
- 
entryFromBucketprotected static SegmentedHashMap.Entry entryFromBucket(SegmentedHashMap.Entry[] aeBucket, int nBucket) Return the first non-synthetic Entry object contained by in the specified bucket.- Parameters:
- aeBucket- the array of hash buckets
- nBucket- the bucket index
- Returns:
- the first non-synthetic Entry in the specified bucket or null
 
- 
instantiateEntrySetFactory for EntrySet- Returns:
- a new instance of the EntrySet class (or a subclass thereof)
 
- 
instantiateKeySetFactory for KeySet.- Returns:
- a new instance of the KeySet class (or subclass thereof)
 
- 
instantiateValuesCollectionFactory for ValuesCollection.- Returns:
- a new instance of the ValuesCollection class (or subclass thereof)
 
 
-