ehcache

net.sf.ehcache.store.disk
Class Segment

java.lang.Object
  extended by java.util.concurrent.locks.ReentrantReadWriteLock
      extended by net.sf.ehcache.store.disk.Segment
All Implemented Interfaces:
Serializable, ReadWriteLock

public class Segment
extends 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
ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock
 
Field Summary
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.
 
Constructor Summary
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.
 
Method Summary
 boolean isFaulted(int hash, Object key)
          Verifies if the mapping for a key is marked as faulted
 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 String toString()
Overrides:
toString in class ReentrantReadWriteLock

isFaulted

public boolean isFaulted(int hash,
                         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)

ehcache

Copyright 2001-2014, Terracotta, Inc.