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)
          Create a Segment with the given initial capacity, load-factor, primary element substitute factory, and identity element substitute factory.
 
Method Summary
protected  void diskHit()
          Record a hit in the disk tier
 float getDiskHitRate()
          Return the disk hit rate
 float getDiskMissRate()
          Return the disk miss rate
protected  void miss()
          Record a miss in the disk tier
 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)
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
Method Detail

toString

public String toString()
Overrides:
toString in class ReentrantReadWriteLock

getDiskHitRate

public float getDiskHitRate()
Return the disk hit rate

Returns:
the disk hit rate

getDiskMissRate

public float getDiskMissRate()
Return the disk miss rate

Returns:
the disk miss rate

diskHit

protected void diskHit()
Record a hit in the disk tier


miss

protected void miss()
Record a miss in the disk tier


ehcache

Copyright © 2003-2012 Terracotta, Inc.. All Rights Reserved.