ehcache

net.sf.ehcache.transaction
Interface SoftLock

All Known Implementing Classes:
ReadCommittedSoftLockImpl

public interface SoftLock

A soft lock is used to lock elements in transactional stores

Author:
Ludovic Orban

Method Summary
 void clearTryLock()
          Clear the state of the soft lock after a tryLock() call succeeded.
 void freeze()
          Freeze the soft lock.
 Element getElement(TransactionID currentTransactionId)
          Get the element the current transaction is supposed to see.
 Element getFrozenElement()
          Get the Element with which this soft lock should be replaced by a commit, rollback or clean up
 Object getKey()
          Get the key of the element this soft lock is guarding
 TransactionID getTransactionID()
          Get the ID of the transaction under which this soft lock is operating
 boolean isExpired()
          Check if the soft lock expired, ie: that the thread which locked it died
 void lock()
          Lock the soft lock
 boolean tryLock(long ms)
          Attempt to lock the soft lock
 void unfreeze()
          Unfreeze the soft lock
 void unlock()
          Unlock the soft lock.
 Element updateElement(Element element)
          Change the Element at the key this soft lock is guarding
 

Method Detail

getKey

Object getKey()
Get the key of the element this soft lock is guarding

Returns:
the key

getTransactionID

TransactionID getTransactionID()
Get the ID of the transaction under which this soft lock is operating

Returns:
the TransactionID

getElement

Element getElement(TransactionID currentTransactionId)
Get the element the current transaction is supposed to see.

Parameters:
currentTransactionId - the current transaction under which this call is executed
Returns:
the Element visible to the current transaction

updateElement

Element updateElement(Element element)
Change the Element at the key this soft lock is guarding

Parameters:
element - the new Element
Returns:
the previous Element

lock

void lock()
Lock the soft lock


tryLock

boolean tryLock(long ms)
                throws InterruptedException
Attempt to lock the soft lock

Parameters:
ms - the time in milliseconds before this method gives up
Returns:
true if the soft lock was locked, false otherwise
Throws:
InterruptedException - if the thread calling this method was interrupted

clearTryLock

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


unlock

void 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


freeze

void 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) method calls. Freeze is used to mark the start of a commit / rollback phase


unfreeze

void unfreeze()
Unfreeze the soft lock


isExpired

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

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

getFrozenElement

Element getFrozenElement()
Get the Element with which this soft lock should be replaced by a commit, rollback or clean up

Returns:
the Element

ehcache

true