Class Segment

  • All Implemented Interfaces:
    java.io.Serializable, java.util.concurrent.locks.ReadWriteLock

    public class Segment
    extends java.util.concurrent.locks.ReentrantReadWriteLock
    Segment implementation used in LocalStore.

    The segment extends ReentrantReadWriteLock to allow read locking on read operations. In addition to the typical CHM-like methods, this classes additionally supports replacement under a read lock - which is accomplished using an atomic CAS on the associated HashEntry.

    Author:
    Chris Dennis, Ludovic Orban
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock

        java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock, java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int count
      Count of elements in the map.
      protected int modCount
      Mod-count used to track concurrent modifications when doing size calculations or iterating over the store.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isFaulted​(int hash, java.lang.Object key)
      Verifies if the mapping for a key is marked as faulted
      java.lang.String toString()  
      • Methods inherited from class java.util.concurrent.locks.ReentrantReadWriteLock

        getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, writeLock
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • count

        protected volatile int count
        Count of elements in the map.

        A volatile reference is needed here for the same reasons as in the table reference.

      • modCount

        protected int modCount
        Mod-count used to track concurrent modifications when doing size calculations or iterating over the store.

        Note that we don't actually have any iterators yet...

    • Constructor Detail

      • Segment

        public Segment​(int initialCapacity,
                       float loadFactor,
                       DiskStorageFactory primary,
                       CacheConfiguration cacheConfiguration,
                       PoolAccessor onHeapPoolAccessor,
                       PoolAccessor onDiskPoolAccessor,
                       RegisteredEventListeners cacheEventNotificationService,
                       org.terracotta.statistics.observer.OperationObserver<CacheOperationOutcomes.EvictionOutcome> evictionObserver)
        Create a Segment with the given initial capacity, load-factor, primary element substitute factory, and identity element substitute factory.

        An identity element substitute factory is specified at construction time because only one subclass of IdentityElementProxyFactory can be used with a Segment. Without this requirement the mapping between bare Element instances and the factory responsible for them would be ambiguous.

        If a null identity element substitute factory is specified then encountering a raw element (i.e. as a result of using an identity element substitute factory) will result in a null pointer exception during decode.

        Parameters:
        initialCapacity - initial capacity of store
        loadFactor - fraction of capacity at which rehash occurs
        primary - primary element substitute factory
        cacheConfiguration - the cache configuration
        onHeapPoolAccessor - the pool tracking on-heap usage
        onDiskPoolAccessor - the pool tracking on-disk usage
        cacheEventNotificationService -
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.concurrent.locks.ReentrantReadWriteLock
      • isFaulted

        public boolean isFaulted​(int hash,
                                 java.lang.Object key)
        Verifies if the mapping for a key is marked as faulted
        Parameters:
        key - the key to check the mapping for
        Returns:
        true if faulted, false otherwise (including no mapping)