Top Description Fields Constructors Methods
net.sf.ehcache.transaction

public Class ReadCommittedSoftLockImpl

extends Object
implements SoftLock
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.transaction.SoftLock
Imports
net.sf.ehcache.Element, java.util.concurrent.TimeUnit, java.util.concurrent.locks.ReentrantLock, .ReentrantReadWriteLock

A SoftLock implementation with Read-Committed isolation level
Author
Ludovic Orban

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final ReentrantReadWriteLock
private final Object
private final ReentrantLock
private final SoftLockManager
private static final int

Constructor Summary

AccessConstructor and Description
pack-priv
ReadCommittedSoftLockImpl(SoftLockManager
the creating manager
manager
,
Object
the element's key this soft lock is going to protect
key
)

Create a new ReadCommittedSoftLockImpl instance

Method Summary

Modifier and TypeMethod and Description
private void
public void
clearTryLock()

Implements net.sf.ehcache.transaction.SoftLock.clearTryLock.

Clear the state of the soft lock after a tryLock() call succeeded.
public void
freeze()

Implements net.sf.ehcache.transaction.SoftLock.freeze.

Freeze the soft lock.
public Element
getElement(TransactionID
the current transaction under which this call is executed
currentTransactionId
,
SoftLockID
the soft lock ID
softLockId
)

Implements net.sf.ehcache.transaction.SoftLock.getElement.

Get the element the current transaction is supposed to see.
public Object
getKey()

Implements net.sf.ehcache.transaction.SoftLock.getKey.

Get the key of the element this soft lock is guarding
public boolean
isExpired()

Implements net.sf.ehcache.transaction.SoftLock.isExpired.

Check if the soft lock expired, ie: that the thread which locked it died
private boolean
private boolean
public void
lock()

Implements net.sf.ehcache.transaction.SoftLock.lock.

Lock the soft lock
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public boolean
tryLock(long
the time in milliseconds before this method gives up
ms
)

Implements net.sf.ehcache.transaction.SoftLock.tryLock.

Attempt to lock the soft lock
public void
unfreeze()

Implements net.sf.ehcache.transaction.SoftLock.unfreeze.

Unfreeze the soft lock
public void
unlock()

Implements net.sf.ehcache.transaction.SoftLock.unlock.

Unlock the soft lock.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

expiredback to summary
private volatile boolean expired
freezeLockback to summary
private final ReentrantReadWriteLock freezeLock
keyback to summary
private final Object key
lockback to summary
private final ReentrantLock lock
managerback to summary
private final SoftLockManager manager
PRIMEback to summary
private static final int PRIME

Constructor Detail

ReadCommittedSoftLockImplback to summary
pack-priv ReadCommittedSoftLockImpl(SoftLockManager manager, Object key)

Create a new ReadCommittedSoftLockImpl instance

Parameters
manager:SoftLockManager

the creating manager

key:Object

the element's key this soft lock is going to protect

Method Detail

clearback to summary
private void clear()
clearTryLockback to summary
public void clearTryLock()

Implements net.sf.ehcache.transaction.SoftLock.clearTryLock.

Doc from net.sf.ehcache.transaction.SoftLock.clearTryLock.

Clear the state of the soft lock after a tryLock() call succeeded.

freezeback to summary
public void freeze()

Implements net.sf.ehcache.transaction.SoftLock.freeze.

Doc from net.sf.ehcache.transaction.SoftLock.freeze.

Freeze the soft lock. A soft lock should only be frozen for a very short period of time as this blocks the getElement(TransactionID, SoftLockID) method calls. Freeze is used to mark the start of a commit / rollback phase

getElementback to summary
public Element getElement(TransactionID currentTransactionId, SoftLockID softLockId)

Implements net.sf.ehcache.transaction.SoftLock.getElement.

Doc from net.sf.ehcache.transaction.SoftLock.getElement.

Get the element the current transaction is supposed to see.

Parameters
currentTransactionId:TransactionID

the current transaction under which this call is executed

softLockId:SoftLockID

the soft lock ID

Returns:Element

the Element visible to the current transaction

getKeyback to summary
public Object getKey()

Implements net.sf.ehcache.transaction.SoftLock.getKey.

Doc from net.sf.ehcache.transaction.SoftLock.getKey.

Get the key of the element this soft lock is guarding

Returns:Object

the key

isExpiredback to summary
public boolean isExpired()

Implements net.sf.ehcache.transaction.SoftLock.isExpired.

Doc from net.sf.ehcache.transaction.SoftLock.isExpired.

Check if the soft lock expired, ie: that the thread which locked it died

Returns:boolean

true if the soft lock is orphan and should be cleaned up, false otherwise

isFrozenback to summary
private boolean isFrozen()
isLockedback to summary
private boolean isLocked()
lockback to summary
public void lock()

Implements net.sf.ehcache.transaction.SoftLock.lock.

Doc from net.sf.ehcache.transaction.SoftLock.lock.

Lock the soft lock

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
tryLockback to summary
public boolean tryLock(long ms) throws InterruptedException

Implements net.sf.ehcache.transaction.SoftLock.tryLock.

Doc from net.sf.ehcache.transaction.SoftLock.tryLock.

Attempt to lock the soft lock

Parameters
ms:long

the time in milliseconds before this method gives up

Returns:boolean

true if the soft lock was locked, false otherwise

Exceptions
InterruptedException:
if the thread calling this method was interrupted
unfreezeback to summary
public void unfreeze()

Implements net.sf.ehcache.transaction.SoftLock.unfreeze.

Doc from net.sf.ehcache.transaction.SoftLock.unfreeze.

Unfreeze the soft lock

unlockback to summary
public void unlock()

Implements net.sf.ehcache.transaction.SoftLock.unlock.

Doc from net.sf.ehcache.transaction.SoftLock.unlock.

Unlock the soft lock. Once a soft lock got unlocked, it is considered 'dead': it cannot be locked again and must be cleaned up