Top Description Inners Fields Constructors Methods
net.sf.ehcache.hibernate.ccs

public Class EhcacheReadWriteCache

extends AbstractEhcacheConcurrencyStrategy
Class Inheritance
Annotations
@Deprecated
Imports
java.io.Serializable, java.util.Comparator, .UUID, java.util.concurrent.atomic.AtomicLong, java.util.concurrent.locks.ReentrantReadWriteLock, .ReentrantReadWriteLock.ReadLock, .ReentrantReadWriteLock.WriteLock, org.hibernate.cache.CacheException, org.hibernate.cache.access.SoftLock, org.slf4j.Logger, .LoggerFactory

Deprecated

Ehcache specific read/write cache concurrency strategy.

This is the Ehcache specific equivalent to Hibernate's ReadWriteCache. This implementation uses a more robust soft-lock system (less prone to accidental collisions).

Author
Chris Dennis

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
EhcacheReadWriteCache.Item

Wrapper type representing unlocked items.

private static class
EhcacheReadWriteCache.Lock

Wrapper type representing locked items.

private static interface
EhcacheReadWriteCache.Lockable

Interface type implemented by all wrapper objects in the cache.

Field Summary

Modifier and TypeField and Description
private final ReentrantReadWriteLock.ReadLock
private final ReentrantReadWriteLock.WriteLock
private static final Logger
private final AtomicLong
private final UUID
Inherited from net.sf.ehcache.hibernate.ccs.AbstractEhcacheConcurrencyStrategy:
cache

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
afterInsert(Object key, Object value, Object version)

Implements org.hibernate.cache.CacheConcurrencyStrategy.afterInsert.

Called after an item has been inserted (after the transaction completes), instead of calling release().
public boolean
afterUpdate(Object key, Object value, Object version, SoftLock softlock)

Implements org.hibernate.cache.CacheConcurrencyStrategy.afterUpdate.

Called after an item has been updated (after the transaction completes), instead of calling release().
private void
public void
evict(Object key)

Implements org.hibernate.cache.CacheConcurrencyStrategy.evict.

A No-Op, since we are an asynchronous cache concurrency strategy.
public Object
get(Object key, long
a timestamp prior to the transaction start time
txTimestamp
)

Implements org.hibernate.cache.CacheConcurrencyStrategy.get.

Attempt to retrieve an object from the cache.
private void
public boolean
insert(Object key, Object value, Object currentVersion)

Implements org.hibernate.cache.CacheConcurrencyStrategy.insert.

A No-Op, since we are an asynchronous cache concurrency strategy.
public SoftLock
lock(Object key, Object version)

Implements org.hibernate.cache.CacheConcurrencyStrategy.lock.

Soft-locks the associated mapping prior to updating/inserting a new value.
private long
public boolean
put(Object key, Object value, long
a timestamp prior to the transaction start time
txTimestamp
,
Object
the item version number
version
,
Comparator<T>
a comparator used to compare version numbers
versionComparator
,
boolean
indicates that the cache should avoid a put is the item is already cached
minimalPut
)

Implements org.hibernate.cache.CacheConcurrencyStrategy.put.

Attempt to cache an object, after loading from the database.
private void
private void
public void
release(Object key, SoftLock lock)

Implements org.hibernate.cache.CacheConcurrencyStrategy.release.

Soft-unlocks the associated mapping.
public boolean
update(Object key, Object value, Object currentVersion, Object previousVersion)

Implements org.hibernate.cache.CacheConcurrencyStrategy.update.

A No-Op, since we are an asynchronous cache concurrency strategy.
private void
private void
Inherited from net.sf.ehcache.hibernate.ccs.AbstractEhcacheConcurrencyStrategy:
cleardestroygetCachegetRegionNameremovesetCache

Field Detail

coarseReadLockback to summary
private final ReentrantReadWriteLock.ReadLock coarseReadLock
coarseWriteLockback to summary
private final ReentrantReadWriteLock.WriteLock coarseWriteLock
LOGback to summary
private static final Logger LOG

Hides net.sf.ehcache.hibernate.ccs.AbstractEhcacheConcurrencyStrategy.LOG.

nextLockIdback to summary
private final AtomicLong nextLockId
uuidback to summary
private final UUID uuid

Constructor Detail

EhcacheReadWriteCacheback to summary
public EhcacheReadWriteCache()

Method Detail

afterInsertback to summary
public boolean afterInsert(Object key, Object value, Object version) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.afterInsert.

Doc from org.hibernate.cache.CacheConcurrencyStrategy.afterInsert.

Called after an item has been inserted (after the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.

afterUpdateback to summary
public boolean afterUpdate(Object key, Object value, Object version, SoftLock softlock) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.afterUpdate.

Doc from org.hibernate.cache.CacheConcurrencyStrategy.afterUpdate.

Called after an item has been updated (after the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.

decrementLockback to summary
private void decrementLock(Object key, EhcacheReadWriteCache.Lock lock)
evictback to summary
public void evict(Object key) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.evict.

A No-Op, since we are an asynchronous cache concurrency strategy.

getback to summary
public Object get(Object key, long txTimestamp) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.get.

Doc from org.hibernate.cache.CacheConcurrencyStrategy.get.

Attempt to retrieve an object from the cache. Mainly used in attempting to resolve entities/collections from the second level cache.

Parameters
txTimestamp:long

a timestamp prior to the transaction start time

Returns:Object

the cached object or null

handleLockExpiryback to summary
private void handleLockExpiry(Object key)
insertback to summary
public boolean insert(Object key, Object value, Object currentVersion) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.insert.

A No-Op, since we are an asynchronous cache concurrency strategy.

lockback to summary
public SoftLock lock(Object key, Object version) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.lock.

Soft-locks the associated mapping prior to updating/inserting a new value.

nextLockIdback to summary
private long nextLockId()
putback to summary
public boolean put(Object key, Object value, long txTimestamp, Object version, Comparator<T> versionComparator, boolean minimalPut) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.put.

Doc from org.hibernate.cache.CacheConcurrencyStrategy.put.

Attempt to cache an object, after loading from the database.

Parameters
txTimestamp:long

a timestamp prior to the transaction start time

version:Object

the item version number

versionComparator:Comparator<T>

a comparator used to compare version numbers

minimalPut:boolean

indicates that the cache should avoid a put is the item is already cached

Returns:boolean

true if the object was successfully cached

readLockIfCoarseback to summary
private void readLockIfCoarse(Object key)
readUnlockIfCoarseback to summary
private void readUnlockIfCoarse(Object key)
releaseback to summary
public void release(Object key, SoftLock lock) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.release.

Soft-unlocks the associated mapping.

updateback to summary
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException

Implements org.hibernate.cache.CacheConcurrencyStrategy.update.

A No-Op, since we are an asynchronous cache concurrency strategy.

writeLockback to summary
private void writeLock(Object key)
writeUnlockback to summary
private void writeUnlock(Object key)
net.sf.ehcache.hibernate.ccs back to summary

private final Class EhcacheReadWriteCache.Item

extends Object
implements Serializable, Lockable
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable, java.io.Serializable

Wrapper type representing unlocked items.

Field Summary

Modifier and TypeField and Description
private static final long
private final long
private final Object
private final Object

Constructor Summary

AccessConstructor and Description
private
Item(Object value, Object version, long timestamp)

Method Summary

Modifier and TypeMethod and Description
public Object
public boolean
public boolean
public boolean
isWriteable(long txTimestamp, Object newVersion, Comparator<T> versionComparator)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isWriteable.

public EhcacheReadWriteCache.Lock
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID
timestampback to summary
private final long timestamp
valueback to summary
private final Object value
versionback to summary
private final Object version

Constructor Detail

Itemback to summary
private Item(Object value, Object version, long timestamp)

Method Detail

getValueback to summary
public Object getValue()

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.getValue.

isReadableback to summary
public boolean isReadable(long txTimestamp)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isReadable.

isUnlockableback to summary
public boolean isUnlockable(SoftLock lock)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isUnlockable.

isWriteableback to summary
public boolean isWriteable(long txTimestamp, Object newVersion, Comparator<T> versionComparator)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isWriteable.

lockback to summary
public EhcacheReadWriteCache.Lock lock(long timeout, UUID uuid, long lockId)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.lock.

net.sf.ehcache.hibernate.ccs back to summary

private final Class EhcacheReadWriteCache.Lock

extends Object
implements Serializable, Lockable, SoftLock
Class Inheritance
All Implemented Interfaces
org.hibernate.cache.access.SoftLock, net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable, java.io.Serializable

Wrapper type representing locked items.

Field Summary

Modifier and TypeField and Description
private boolean
private final long
private int
private static final long
private final UUID
private long
private long
private final Object

Constructor Summary

AccessConstructor and Description
pack-priv
Lock(long timeout, UUID sourceUuid, long lockId, Object version)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
public boolean
public boolean
isWriteable(long txTimestamp, Object newVersion, Comparator<T> versionComparator)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isWriteable.

public EhcacheReadWriteCache.Lock
private void
unlock(long timestamp)

private boolean
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

concurrentback to summary
private boolean concurrent
lockIdback to summary
private final long lockId
multiplicityback to summary
private int multiplicity
serialVersionUIDback to summary
private static final long serialVersionUID
sourceUuidback to summary
private final UUID sourceUuid
timeoutback to summary
private long timeout
unlockTimestampback to summary
private long unlockTimestamp
versionback to summary
private final Object version

Constructor Detail

Lockback to summary
pack-priv Lock(long timeout, UUID sourceUuid, long lockId, Object version)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getValueback to summary
public Object getValue()

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.getValue.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isReadableback to summary
public boolean isReadable(long txTimestamp)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isReadable.

isUnlockableback to summary
public boolean isUnlockable(SoftLock lock)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isUnlockable.

isWriteableback to summary
public boolean isWriteable(long txTimestamp, Object newVersion, Comparator<T> versionComparator)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.isWriteable.

lockback to summary
public EhcacheReadWriteCache.Lock lock(long timeout, UUID uuid, long lockId)

Implements net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lockable.lock.

unlockback to summary
private void unlock(long timestamp)
wasLockedConcurrentlyback to summary
private boolean wasLockedConcurrently()
net.sf.ehcache.hibernate.ccs back to summary

private Interface EhcacheReadWriteCache.Lockable

Known Direct Implementers
net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Item, net.sf.ehcache.hibernate.ccs.EhcacheReadWriteCache.Lock

Interface type implemented by all wrapper objects in the cache.

Method Summary

Modifier and TypeMethod and Description
public Object
public boolean
isReadable(long txTimestamp)

public boolean
public boolean
isWriteable(long txTimestamp, Object version, Comparator<T> versionComparator)

public EhcacheReadWriteCache.Lock
lock(long timeout, UUID uuid, long lockId)

Method Detail

getValueback to summary
public Object getValue()
isReadableback to summary
public boolean isReadable(long txTimestamp)
isUnlockableback to summary
public boolean isUnlockable(SoftLock lock)
isWriteableback to summary
public boolean isWriteable(long txTimestamp, Object version, Comparator<T> versionComparator)
lockback to summary
public EhcacheReadWriteCache.Lock lock(long timeout, UUID uuid, long lockId)