ehcache

net.sf.ehcache.constructs.nonstop.concurrency
Class NonstopSync

java.lang.Object
  extended by net.sf.ehcache.constructs.nonstop.concurrency.NonstopSync
All Implemented Interfaces:
Sync

public class NonstopSync
extends Object
implements Sync

Class implementing Sync and that can be executed without getting stuck.

Author:
Abhishek Sanoujam

Field Summary
 
Fields inherited from interface net.sf.ehcache.concurrent.Sync
ONE_CENTURY, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ONE_YEAR
 
Constructor Summary
NonstopSync(NonstopStore nonstopStore, Sync delegateSync)
          Constructor accepting the NonstopStore and the actual Sync
 
Method Summary
 boolean isHeldByCurrentThread(LockType type)
          Returns true is this is lock is held at given level by the current thread.
 void lock(LockType type)
          Acquire lock of LockType.READ or WRITE
 boolean tryLock(LockType type, long msec)
          Tries to acquire a LockType.READ or WRITE for a certain period
 void unlock(LockType type)
          Releases the lock held by the current Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonstopSync

public NonstopSync(NonstopStore nonstopStore,
                   Sync delegateSync)
Constructor accepting the NonstopStore and the actual Sync

Parameters:
nonstopStore -
delegateSync -
Method Detail

isHeldByCurrentThread

public boolean isHeldByCurrentThread(LockType type)
Returns true is this is lock is held at given level by the current thread.

Specified by:
isHeldByCurrentThread in interface Sync
Parameters:
type - the lock type to test
Returns:
true if the lock is held

lock

public void lock(LockType type)
Acquire lock of LockType.READ or WRITE

Specified by:
lock in interface Sync
Parameters:
type - the lock type to acquire

tryLock

public boolean tryLock(LockType type,
                       long msec)
                throws InterruptedException
Tries to acquire a LockType.READ or WRITE for a certain period

Specified by:
tryLock in interface Sync
Parameters:
type - the lock type to acquire
msec - timeout
Returns:
true if the lock got acquired, false otherwise
Throws:
InterruptedException - Should the thread be interrupted

unlock

public void unlock(LockType type)
Releases the lock held by the current Thread. In case of a LockType.WRITE, should the lock not be held by the current Thread, nothing happens

Specified by:
unlock in interface Sync
Parameters:
type - the lock type to acquire

ehcache

true