org.codehaus.wadi.core.util
Interface Lease

All Superinterfaces:
java.util.concurrent.locks.Lock
All Known Implementing Classes:
ExtendableLease, SimpleLease

public interface Lease
extends java.util.concurrent.locks.Lock

Lease - like a Sync, but locks are only granted for a given period after which they automatically unlock themselves. This is an important construct in a distributed, HA system as, even in the case of failure, a locked resource will be correctly unlocked.

Version:
$Revision$
Author:
jules

Nested Class Summary
static interface Lease.Handle
           
 
Method Summary
 Lease.Handle acquire(long leasePeriod)
          acquire a lease for a given period
 Lease.Handle attempt(long timeframe, long leasePeriod)
          attempt the acquisition of a lease for a given period within a given timeframe
 boolean release(Lease.Handle handle)
          A misleading name - 'release' as in 'unlock' the lease corresponding to the given handle
 
Methods inherited from interface java.util.concurrent.locks.Lock
lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock
 

Method Detail

acquire

Lease.Handle acquire(long leasePeriod)
                     throws java.lang.InterruptedException
acquire a lease for a given period

Parameters:
leasePeriod - the given period (in millis)
Returns:
the handle of the lease acquired
Throws:
java.lang.InterruptedException

attempt

Lease.Handle attempt(long timeframe,
                     long leasePeriod)
                     throws java.lang.InterruptedException
attempt the acquisition of a lease for a given period within a given timeframe

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

boolean release(Lease.Handle handle)
A misleading name - 'release' as in 'unlock' the lease corresponding to the given handle

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'


Copyright © 2011. All Rights Reserved.