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

pack-priv abstract Class AbstractReadWriteEhcacheAccessStrategy<T extends net.sf.ehcache.hibernate.regions.EhcacheTransactionalDataRegion>

extends AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion>
Class Inheritance
Known Direct Subclasses
net.sf.ehcache.hibernate.strategy.ReadWriteEhcacheCollectionRegionAccessStrategy, net.sf.ehcache.hibernate.strategy.ReadWriteEhcacheEntityRegionAccessStrategy
Type Parameters
<T>
the type of the enclosed cache region
Imports
java.io.Serializable, java.util.Comparator, .UUID, java.util.concurrent.atomic.AtomicLong, net.sf.ehcache.hibernate.regions.EhcacheTransactionalDataRegion, org.hibernate.cache.CacheException, org.hibernate.cache.access.SoftLock, org.hibernate.cfg.Settings, org.slf4j.Logger, .LoggerFactory

Superclass for all Ehcache specific read/write AccessStrategy implementations.
Author
Chris Dennis

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AbstractReadWriteEhcacheAccessStrategy.Item

Wrapper type representing unlocked items.

protected static class
AbstractReadWriteEhcacheAccessStrategy.Lock

Wrapper type representing locked items.

protected static interface
AbstractReadWriteEhcacheAccessStrategy.Lockable

Interface type implemented by all wrapper objects in the cache.

Field Summary

Modifier and TypeField and Description
private static final Logger
private final AtomicLong
private final UUID
private final Comparator<T>
Inherited from net.sf.ehcache.hibernate.strategy.AbstractEhcacheAccessStrategy:
regionsettings

Constructor Summary

AccessConstructor and Description
public
AbstractReadWriteEhcacheAccessStrategy(T region, Settings settings)

Creates a read/write cache access strategy around the given cache region.

Method Summary

Modifier and TypeMethod and Description
protected void
decrementLock(Object key, AbstractReadWriteEhcacheAccessStrategy.Lock lock)

Unlock and re-put the given key, lock combination.

public final Object
get(Object key, long txTimestamp)

Returns null if the item is not readable.

protected void
handleMissingLock(Object key, AbstractReadWriteEhcacheAccessStrategy.Lockable lock)

Handle the timeout of a previous lock mapped to this key

public final SoftLock
lockItem(Object key, Object version)

Soft-lock a cache item.

private long
public final boolean
putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)

Implements abstract net.sf.ehcache.hibernate.strategy.AbstractEhcacheAccessStrategy.putFromLoad.

Returns false and fails to put the value if there is an existing un-writeable item mapped to this key.
private void
private void
readLockIfNeeded(Object key)

Read lock the entry for the given key if internal cache locks will not provide correct exclusion.

private void
readUnlockIfNeeded(Object key)

Read unlock the entry for the given key if internal cache locks will not provide correct exclusion.

public final void
unlockItem(Object key, SoftLock lock)

Soft-unlock a cache item.

Inherited from net.sf.ehcache.hibernate.strategy.AbstractEhcacheAccessStrategy:
evictevictAlllockRegionputFromLoadremoveremoveAllunlockRegion

Field Detail

LOGback to summary
private static final Logger LOG
nextLockIdback to summary
private final AtomicLong nextLockId
uuidback to summary
private final UUID uuid
versionComparatorback to summary
private final Comparator<T> versionComparator

Constructor Detail

AbstractReadWriteEhcacheAccessStrategyback to summary
public AbstractReadWriteEhcacheAccessStrategy(T region, Settings settings)

Creates a read/write cache access strategy around the given cache region.

Method Detail

decrementLockback to summary
protected void decrementLock(Object key, AbstractReadWriteEhcacheAccessStrategy.Lock lock)

Unlock and re-put the given key, lock combination.

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

Returns null if the item is not readable. Locked items are not readable, nor are items created after the start of this transaction.

See Also
org.hibernate.cache.access.EntityRegionAccessStrategy#get(java.lang.Object, long), org.hibernate.cache.access.CollectionRegionAccessStrategy#get(java.lang.Object, long)
handleMissingLockback to summary
protected void handleMissingLock(Object key, AbstractReadWriteEhcacheAccessStrategy.Lockable lock)

Handle the timeout of a previous lock mapped to this key

lockItemback to summary
public final SoftLock lockItem(Object key, Object version) throws CacheException

Soft-lock a cache item.

See Also
org.hibernate.cache.access.EntityRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object), org.hibernate.cache.access.CollectionRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
nextLockIdback to summary
private long nextLockId()
putFromLoadback to summary
public final boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException

Implements abstract net.sf.ehcache.hibernate.strategy.AbstractEhcacheAccessStrategy.putFromLoad.

Returns false and fails to put the value if there is an existing un-writeable item mapped to this key.

Annotations
@Override
See Also
org.hibernate.cache.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean), org.hibernate.cache.access.CollectionRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean)
putLockback to summary
private void putLock(final Object key, final AbstractReadWriteEhcacheAccessStrategy.Lock newLock)
readLockIfNeededback to summary
private void readLockIfNeeded(Object key)

Read lock the entry for the given key if internal cache locks will not provide correct exclusion.

readUnlockIfNeededback to summary
private void readUnlockIfNeeded(Object key)

Read unlock the entry for the given key if internal cache locks will not provide correct exclusion.

unlockItemback to summary
public final void unlockItem(Object key, SoftLock lock) throws CacheException

Soft-unlock a cache item.

See Also
org.hibernate.cache.access.EntityRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.access.SoftLock), org.hibernate.cache.access.CollectionRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.access.SoftLock)
net.sf.ehcache.hibernate.strategy back to summary

protected final Class AbstractReadWriteEhcacheAccessStrategy.Item

extends Object
implements Serializable, Lockable
Class Inheritance
  • java.lang.Object
  • net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Item
All Implemented Interfaces
net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.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
pack-priv
Item(Object value, Object version, long timestamp)

Creates an unlocked item wrapping the given value with a version and creation timestamp.

Method Summary

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

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isReadable.

Returns true if the enclosed value can be read by a transaction started at the given time.
public boolean
isUnlockable(SoftLock lock)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isUnlockable.

Returns true if the given lock can be unlocked using the given SoftLock instance as a handle.
public boolean
isWriteable(long txTimestamp, Object newVersion, Comparator<T> versionComparator)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isWriteable.

Returns true if the enclosed value can be replaced with one of the given version by a transaction started at the given time.
public AbstractReadWriteEhcacheAccessStrategy.Lock
lock(long timeout, UUID uuid, long lockId)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.lock.

Locks this entry, stamping it with the UUID and lockId given, with the lock timeout occuring at the specified time.
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
pack-priv Item(Object value, Object version, long timestamp)

Creates an unlocked item wrapping the given value with a version and creation timestamp.

Method Detail

getValueback to summary
public Object getValue()

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.getValue.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.getValue.

Returns the enclosed value.

isReadableback to summary
public boolean isReadable(long txTimestamp)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isReadable.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isReadable.

Returns true if the enclosed value can be read by a transaction started at the given time.

isUnlockableback to summary
public boolean isUnlockable(SoftLock lock)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isUnlockable.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isUnlockable.

Returns true if the given lock can be unlocked using the given SoftLock instance as a handle.

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

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isWriteable.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isWriteable.

Returns true if the enclosed value can be replaced with one of the given version by a transaction started at the given time.

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

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.lock.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.lock.

Locks this entry, stamping it with the UUID and lockId given, with the lock timeout occuring at the specified time. The returned Lock object can be used to unlock the entry in the future.

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

protected final Class AbstractReadWriteEhcacheAccessStrategy.Lock

extends Object
implements Serializable, Lockable, SoftLock
Class Inheritance
  • java.lang.Object
  • net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lock
All Implemented Interfaces
org.hibernate.cache.access.SoftLock, net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.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)

Creates a locked item with the given identifiers and 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

Returns:

true if locked, false otherwise
isLocked
()

Tells whether the Lock is currently held

public boolean
isReadable(long txTimestamp)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isReadable.

Returns true if the enclosed value can be read by a transaction started at the given time.
public boolean
isUnlockable(SoftLock lock)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isUnlockable.

Returns true if the given lock can be unlocked using the given SoftLock instance as a handle.
public boolean
isWriteable(long txTimestamp, Object newVersion, Comparator<T> versionComparator)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isWriteable.

Returns true if the enclosed value can be replaced with one of the given version by a transaction started at the given time.
public AbstractReadWriteEhcacheAccessStrategy.Lock
lock(long timeout, UUID uuid, long lockId)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.lock.

Locks this entry, stamping it with the UUID and lockId given, with the lock timeout occuring at the specified time.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
unlock(long timestamp)

Unlocks this Lock, and timestamps the unlock event.

public boolean
wasLockedConcurrently()

Returns true if this Lock has been concurrently locked by more than one transaction.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

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)

Creates a locked item with the given identifiers and 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.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.getValue.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.getValue.

Returns the enclosed value.

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
isLockedback to summary
public boolean isLocked()

Tells whether the Lock is currently held

Returns:boolean

true if locked, false otherwise

isReadableback to summary
public boolean isReadable(long txTimestamp)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isReadable.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isReadable.

Returns true if the enclosed value can be read by a transaction started at the given time.

isUnlockableback to summary
public boolean isUnlockable(SoftLock lock)

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isUnlockable.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isUnlockable.

Returns true if the given lock can be unlocked using the given SoftLock instance as a handle.

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

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isWriteable.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.isWriteable.

Returns true if the enclosed value can be replaced with one of the given version by a transaction started at the given time.

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

Implements net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.lock.

Doc from net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lockable.lock.

Locks this entry, stamping it with the UUID and lockId given, with the lock timeout occuring at the specified time. The returned Lock object can be used to unlock the entry in the future.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unlockback to summary
public void unlock(long timestamp)

Unlocks this Lock, and timestamps the unlock event.

wasLockedConcurrentlyback to summary
public boolean wasLockedConcurrently()

Returns true if this Lock has been concurrently locked by more than one transaction.

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

protected Interface AbstractReadWriteEhcacheAccessStrategy.Lockable

Known Direct Implementers
net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Item, net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.Lock

Interface type implemented by all wrapper objects in the cache.

Method Summary

Modifier and TypeMethod and Description
public Object
getValue()

Returns the enclosed value.

public boolean
isReadable(long txTimestamp)

Returns true if the enclosed value can be read by a transaction started at the given time.

public boolean
isUnlockable(SoftLock lock)

Returns true if the given lock can be unlocked using the given SoftLock instance as a handle.

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

Returns true if the enclosed value can be replaced with one of the given version by a transaction started at the given time.

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

Locks this entry, stamping it with the UUID and lockId given, with the lock timeout occuring at the specified time.

Method Detail

getValueback to summary
public Object getValue()

Returns the enclosed value.

isReadableback to summary
public boolean isReadable(long txTimestamp)

Returns true if the enclosed value can be read by a transaction started at the given time.

isUnlockableback to summary
public boolean isUnlockable(SoftLock lock)

Returns true if the given lock can be unlocked using the given SoftLock instance as a handle.

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

Returns true if the enclosed value can be replaced with one of the given version by a transaction started at the given time.

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

Locks this entry, stamping it with the UUID and lockId given, with the lock timeout occuring at the specified time. The returned Lock object can be used to unlock the entry in the future.