org.javagroups.service.lease
Interface LeaseFactory
- All Known Implementing Classes:
- LeaseFactoryClient
- public interface LeaseFactory
LeaseFactory
is responsible for granting new leases, renewing
existing leases and canceling leases when it is no longer needed. For batch
purposes, LeaseFactory
creates instances of LeaseGroup
.
- Author:
- Roman Rokytskyy (rrokytskyy@acm.org)
Field Summary |
static long |
DURATION_ANY
This constant represents arbitrary duration. |
static long |
DURATION_FOREVER
This constant represents maximum possible duration. |
Method Summary |
void |
cancelLease(Lease existingLease)
Cancels existing lease. |
Lease |
newLease(java.lang.Object leaseTarget,
java.lang.Object tenant,
long requestedDuration,
boolean isAbsolute)
Obtain new lease. |
Lease |
renewLease(Lease existingLease,
long requestedDuration,
boolean isAbsolute)
Renew existing lease. |
DURATION_ANY
public static final long DURATION_ANY
- This constant represents arbitrary duration. When passed to
LeaseFactory#newLease(Object, long, boolean)
, implementation
grants lease for a duration that best fits leased resource.
DURATION_FOREVER
public static final long DURATION_FOREVER
- This constant represents maximum possible duration. When passed to
LeaseFactory#newLease(Object, long, boolean)
, implementation
usually will grant lease for a maximum possible duration for leased
resource.
newLease
public Lease newLease(java.lang.Object leaseTarget,
java.lang.Object tenant,
long requestedDuration,
boolean isAbsolute)
throws LeaseDeniedException
- Obtain new lease. When client wants to access to resource that is
protected by leasing mechanism, he needs to obtain lease. Each lease
contains lease target that is unique identifier of resource and lease
duration, either relative or absolute.
LeaseFactory
checks its internal lease map and decides
if the lease can be granted or not. In latter case,
LeaseDeniedException
is thrown.
- Parameters:
leaseTarget
- unique identifier of resource to be leased.tenant
- unique identifier of entity that requests lease.leaseDuration
- duration of lease in milliseconds.isAbsolute
- specified if lease duration is absolute or relative.- Returns:
- instance of
Lease
representing granted lease. Note,
granted lease might have different duration than requested. - Throws:
LeaseDeniedException
- if lease cannot be granted.
renewLease
public Lease renewLease(Lease existingLease,
long requestedDuration,
boolean isAbsolute)
throws LeaseDeniedException
- Renew existing lease. This method extends lease duration from now for
a specified duration. If
existingLease
has expired, an
exception is thrown. In this case client has to use
#newLease(Object, long, boolean)
method to obtain a lease.
- Parameters:
leaseTarget
- unique identifier of resource to be leased.leaseDuration
- duration of lease in milliseconds.isAbsolute
- specified if lease duration is absolute or relative.- Returns:
- instance of
Lease
representing granted lease. Note,
granted lease might have different duration than requested. - Throws:
LeaseDeniedException
- if lease cannot be granted.
cancelLease
public void cancelLease(Lease existingLease)
throws UnknownLeaseException
- Cancels existing lease. After invoking this method leased resource is
free.
- Parameters:
existingLease
- lease to cancel.- Throws:
UnknownLeaseException
- if existingLease
is unknown
for this lease factory. Usually means that lease was granted by another
factory.
Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.