org.codehaus.wadi.core.util
Class SimpleLease
java.lang.Object
org.codehaus.wadi.core.util.SimpleLease
- All Implemented Interfaces:
- java.util.concurrent.locks.Lock, Lease
- Direct Known Subclasses:
- ExtendableLease
public class SimpleLease
- extends java.lang.Object
- implements Lease
SimpleLease - first shot at a scalable, best-effort Lease impl. It is written around Sync and ClockDaemon from the
Concurrency library...
- Version:
- $Revision$
- Author:
- jules
Nested classes/interfaces inherited from interface org.codehaus.wadi.core.util.Lease |
Lease.Handle |
Field Summary |
protected static java.util.concurrent.ScheduledThreadPoolExecutor |
_daemon
|
protected java.util.Set<Lease.Handle> |
_handles
|
protected java.lang.String |
_label
|
protected static org.apache.commons.logging.Log |
_lockLog
|
protected java.util.concurrent.locks.Lock |
_sync
|
Constructor Summary |
SimpleLease(java.lang.String label,
java.util.concurrent.locks.Lock sync)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
_lockLog
protected static final org.apache.commons.logging.Log _lockLog
_daemon
protected static final java.util.concurrent.ScheduledThreadPoolExecutor _daemon
_label
protected final java.lang.String _label
_sync
protected final java.util.concurrent.locks.Lock _sync
_handles
protected final java.util.Set<Lease.Handle> _handles
SimpleLease
public SimpleLease(java.lang.String label,
java.util.concurrent.locks.Lock sync)
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
lock
public void lock()
- Specified by:
lock
in interface java.util.concurrent.locks.Lock
lockInterruptibly
public void lockInterruptibly()
throws java.lang.InterruptedException
- Specified by:
lockInterruptibly
in interface java.util.concurrent.locks.Lock
- Throws:
java.lang.InterruptedException
tryLock
public boolean tryLock()
- Specified by:
tryLock
in interface java.util.concurrent.locks.Lock
tryLock
public boolean tryLock(long time,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
- Specified by:
tryLock
in interface java.util.concurrent.locks.Lock
- Throws:
java.lang.InterruptedException
unlock
public void unlock()
- Specified by:
unlock
in interface java.util.concurrent.locks.Lock
setAlarm
protected Lease.Handle setAlarm(long leasePeriod)
acquire
public Lease.Handle acquire(long leasePeriod)
throws java.lang.InterruptedException
- Description copied from interface:
Lease
- acquire a lease for a given period
- Specified by:
acquire
in interface Lease
- Parameters:
leasePeriod
- the given period (in millis)
- Returns:
- the handle of the lease acquired
- Throws:
java.lang.InterruptedException
attempt
public Lease.Handle attempt(long timeframe,
long leasePeriod)
throws java.lang.InterruptedException
- Description copied from interface:
Lease
- attempt the acquisition of a lease for a given period within a given timeframe
- Specified by:
attempt
in interface Lease
- Parameters:
timeframe
- the timeframe within which to try to acquire the lease (in millis)leasePeriod
- the period for which the lease is required (in millis)
- Returns:
- the handle of the lease acquire or null in the case of failure
- Throws:
java.lang.InterruptedException
release
public boolean release(Lease.Handle handle)
- Description copied from interface:
Lease
- A misleading name - 'release' as in 'unlock' the lease corresponding to the given handle
- Specified by:
release
in interface Lease
- Parameters:
handle
- the handle of the Lease to be 'released'
- Returns:
- whether or not the lease in question was still active at the point of 'release'
newCondition
public java.util.concurrent.locks.Condition newCondition()
- Specified by:
newCondition
in interface java.util.concurrent.locks.Lock
Copyright © 2011. All Rights Reserved.