Class SegmentedConcurrentMap

    • 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 < 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)
      • 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 < 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)
        contentionObserver - the ContentionObserver
    • Method Detail

      • setLockAction

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

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

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

        protected void setContentionObserver​(SegmentedConcurrentMap.ContentionObserver contentionObserver)
        Set the ContentionObserver for this SegmentedConcurrentMap.
        Parameters:
        contentionObserver - the contentionObserver
      • 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:
        size in interface ConcurrentMap
        Specified by:
        size in interface 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 Map
        Overrides:
        isEmpty in class SegmentedHashMap
        Returns:
        true if this map contains no key-value mappings
      • 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:
        lock in interface ConcurrentMap
        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_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​(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
      • instantiateEntry

        protected SegmentedHashMap.Entry instantiateEntry​(Object oKey,
                                                          Object oValue,
                                                          int nHash)
        Factory for Entry.
        Overrides:
        instantiateEntry in class SegmentedHashMap
        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)