KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > service > lease > LeaseFactory


1 package org.jgroups.service.lease;
2
3 /**
4  * <code>LeaseFactory</code> is responsible for granting new leases, renewing
5  * existing leases and canceling leases when it is no longer needed. For batch
6  * purposes, <code>LeaseFactory</code> creates instances of {@link LeaseGroup}.
7  *
8  * @author Roman Rokytskyy (rrokytskyy@acm.org)
9  */

10 public interface LeaseFactory {
11     /**
12      * This constant represents arbitrary duration. When passed to
13      * {@link LeaseFactory#newLease(Object, long, boolean)}, implementation
14      * grants lease for a duration that best fits leased resource.
15      */

16     long DURATION_ANY = -1;
17
18     /**
19      * This constant represents maximum possible duration. When passed to
20      * {@link LeaseFactory#newLease(Object, long, boolean)}, implementation
21      * usually will grant lease for a maximum possible duration for leased
22      * resource.
23      */

24     long DURATION_FOREVER = Long.MAX_VALUE;
25
26     /**
27      * Obtain new lease. When client wants to access to resource that is
28      * protected by leasing mechanism, he needs to obtain lease. Each lease
29      * contains lease target that is unique identifier of resource and lease
30      * duration, either relative or absolute.
31      *
32      * <code>LeaseFactory</code> checks its internal lease map and decides
33      * if the lease can be granted or not. In latter case,
34      * {@link LeaseDeniedException} is thrown.
35      *
36      * @param leaseTarget unique identifier of resource to be leased.
37      *
38      * @param tenant unique identifier of entity that requests lease.
39      *
40      * @param leaseDuration duration of lease in milliseconds.
41      *
42      * @param isAbsolute specified if lease duration is absolute or relative.
43      *
44      * @return instance of {@link Lease} representing granted lease. Note,
45      * granted lease might have different duration than requested.
46      *
47      * @throws LeaseDeniedException if lease cannot be granted.
48      */

49     Lease newLease(Object JavaDoc leaseTarget, Object JavaDoc tenant, long requestedDuration,
50     boolean isAbsolute) throws LeaseDeniedException;
51
52     /**
53      * Renew existing lease. This method extends lease duration from now for
54      * a specified duration. If <code>existingLease</code> has expired, an
55      * exception is thrown. In this case client has to use
56      * {@link #newLease(Object, long, boolean)} method to obtain a lease.
57      *
58      * @param leaseTarget unique identifier of resource to be leased.
59      *
60      * @param leaseDuration duration of lease in milliseconds.
61      *
62      * @param isAbsolute specified if lease duration is absolute or relative.
63      *
64      * @return instance of {@link Lease} representing granted lease. Note,
65      * granted lease might have different duration than requested.
66      *
67      * @throws LeaseDeniedException if lease cannot be granted.
68      */

69     Lease renewLease(Lease existingLease, long requestedDuration,
70     boolean isAbsolute) throws LeaseDeniedException;
71
72     /**
73      * Cancels existing lease. After invoking this method leased resource is
74      * free.
75      *
76      * @param existingLease lease to cancel.
77      *
78      * @throws UnknownLeaseException if <code>existingLease</code> is unknown
79      * for this lease factory. Usually means that lease was granted by another
80      * factory.
81      */

82     void cancelLease(Lease existingLease)
83     throws UnknownLeaseException;
84
85 }
86
Popular Tags