Spec Index | A Collection of Jini Technology Helper Utilities and Services Specifications |
Version 1.0 |
LM - JiniTM Lease Utilities Specification
LM.1 Introduction
This specification defines helper utility classes, along with supporting interfaces and classes, that encapsulate functionality which provides for the coordination, systematic renewal, and overall management of a set of leases associated with some object on behalf of another object. Currently, this specification defines only one helper utility class:
LM.2 The
LeaseRenewalManager
The
LeaseRenewalManager
class (belonging to the packagenet.jini.lease
) encapsulates functionality that provides for the systematic renewal and overall management of a set of leases associated with one or more remote entities on behalf of a local entity.The concept of leased resources is fundamental to the Jini technology programming model. Providing a leasing mechanism helps to prevent the accumulation of outdated and unwanted resources in time-based distributed systems, such as the Jini technology infrastructure. The leasing model for Jini network technology (Jini technology), defined in the Jini Distributed Leasing Specification, Section LE.1.1, "Leasing and Distributed Systems", requires renewed proof of interest to continue the existence of a leased resource. Thus, any Jini technology-enabled client (Jini client) or Jini technology-enabled service (Jini service) that requests the use of the leased resources provided by another Jini service may be granted access to those resources for a negotiated period of time, and must continue to request renewal of the lease on each resource for as long as the client or service wishes to have access to the resource.
For example, the Jini lookup service leases two resources: residency in its database and registration with its event notification mechanism. Thus, if a service that is registered with a Jini lookup service wishes to continue its residency beyond the length of the current lease, the service must request a lease renewal from that lookup service. This renewal process must be repeated for as long as the service wishes to maintain its residency in the lookup service. Similarly, if a client has requested that a lookup service notify it of events of interest, then prior to the expiration of the lease on the event registration, the client must request that the lookup service continue to send such events. As with residency in the lookup service, these renewal requests must be repeated for as long as the client wishes to receive event notifications.
Another example of a Jini service providing leased resources would be a service that implements the Jini Transaction Specification to manage transactions on behalf of registered participants. That specification requires that a transaction must be a leased resource. Therefore, any entity that creates such a transaction object is required to negotiate (with an entity referred to as a transaction manager) a lease on that object, repeatedly requesting lease renewals prior to the lease's expiration, for as long as the transaction is to remain in effect.
The
LeaseRenewalManager
class is designed to be a simple mechanism that provides for the systematic renewal and overall management of leases granted on resources that are provided by Jini services and for which a Jini client or service has registered interest. TheLeaseRenewalManager
is a utility class, not a remote service. In order to use this utility, an entity must create, in its own address space, an instance of theLeaseRenewalManager
to manage the entity's leases locally.LM.2.1 Other Types
The types defined in the specification of the
LeaseRenewalManager
utility class are in thenet.jini.lease
package. The following types may be referenced in this specification. Whenever referenced, these types will be referenced in unqualified form:net.jini.config.Configuration net.jini.config.ConfigurationException net.jini.core.lease.Lease net.jini.core.lease.UnknownLeaseException net.jini.core.lease.LeaseDeniedException java.rmi.RemoteException java.rmi.NoSuchObjectException java.util.EventObject java.util.EventListenerLM.3 The Interface
The public methods provided by the
LeaseRenewalManager
class are:package net.jini.lease; public class LeaseRenewalManager { public LeaseRenewalManager() {...} public LeaseRenewalManager(Configuration config) throws ConfigurationException {...} public LeaseRenewalManager(Lease lease, long desiredExpiration, LeaseListener listener) {...} public void renewUntil(Lease lease, long desiredExpiration, long renewDuration, LeaseListener listener) {...} public void renewUntil(Lease lease, long desiredExpiration, LeaseListener listener) {...} public void renewFor(Lease lease, long desiredDuration, long renewDuration, LeaseListener listener) {...} public void renewFor(Lease lease, long desiredDuration, LeaseListener listener) {...} public long getExpiration(Lease lease) throws UnknownLeaseException {...} public void setExpiration(Lease lease, long desiredExpiration) throws UnknownLeaseException {...} public void remove(Lease lease) throws UnknownLeaseException {...} public void cancel(Lease lease) throws UnknownLeaseException, RemoteException {...} public void clear() {...} }LM.4 The Semantics
The term client is used in this specification to refer to the local entity that is using the
LeaseRenewalManager
to manage a collection of leases on its behalf. This collection is referred to as the managed set.The
LeaseRenewalManager
distinguishes between two time values associated with lease expiration: the desired expiration time for the lease and the actual expiration time granted when the lease is created or last renewed. The desired expiration represents when the client would like the lease to expire. The actual expiration represents when the lease is going to expire if it is not renewed. Both time values are absolute times, not relative time durations. The desired expiration time can be retrieved using the renewal manager'sgetExpiration
method, which is described below. The actual expiration time of a lease object can be retrieved by invoking thegetExpiration
method directly on the lease (see theLease
interface defined in the Jini Distributed Leasing Specification).Each lease in the managed set also has two other associated attributes: a renewal duration and a remaining desired duration. The remaining desired duration is always the desired expiration less the current time. The renewal duration is usually a positive number and is the new duration that will be requested when the renewal manager renews the lease, unless the renewal duration is greater than the remaining desired duration. If the renewal duration is greater than the remaining desired duration, then the remaining desired duration will be requested when renewing the lease. One exception is that when the desired expiration is
Lease.FOREVER
, the renewal duration may beLease.ANY
, in which caseLease.ANY
will be requested when renewing the client lease, regardless of the value of the remaining desired duration.For example, if the renewal duration associated with a given lease is 360,000 milliseconds, then when the renewal manager renews the lease, it will ask for a new duration of 360,000 milliseconds--unless the lease is going to reach its desired expiration in less than 360,000 milliseconds. If the lease's desired expiration is within 360,000 milliseconds, the renewal manager will ask for the difference between the current time and the desired expiration. If the renewal duration had been
Lease.ANY
, the renewal manager would have asked for a new duration ofLease.ANY
.The term definite exception is used to refer to exceptions that result from operations on a lease (such as a renewal attempt) that are indicative of a permanent failure of the lease. The term indefinite exception refers to exceptions that do not imply anything about the probability of success of any future lease operations. The algorithm used to classify exceptions as definite or indefinite is implementation-specific.
The
LeaseRenewalManager
generates two kinds of local events. The first kind is a renewal failure event that is generated when the renewal manager finds that it can't renew a lease. The second kind is a desired expiration reached event, which is generated when a lease's desired expiration is reached. Each event signals that the renewal manager has removed a lease from the managed set without an explicit request by the client. When placing a lease in the managed set, the client can provide either aLeaseListener
object that will receive any renewal failure events associated with the lease, or aDesiredExpirationListener
(a subinterface ofLeaseListener
) object that will receive both renewal failure and desired expiration reached events associated with the lease. Both kinds of event are represented byLeaseRenewalEvent
objects.The
LeaseRenewalManager
makes a concurrency guarantee. When theLeaseRenewalManager
makes a remote call (for example, when requesting the renewal of a lease), any invocations made on the methods of theLeaseRenewalManager
will not be blocked. Because of these concurrency guarantees, it is not possible for the various methods that remove leases from the managed set (for example,remove
,cancel
, andclear
) to guarantee that the renewal manager will not attempt to renew leases that have just been removed. Similarly, it is not possible for the methods that change the desired expiration or renewal duration associated with a lease (for example,renewUntil
,renewFor
, andsetExpiration
) to guarantee that the next renewal of the lease will request a duration that is consistent with the new desired expiration and/or renewal duration (it will be consistent with either the old pair or the new pair). However, implementations should keep the window where such renewals could occur as small as possible.The
LeaseRenewalManager
makes a similar reentrancy guarantee with respect toLeaseListener
andDesiredExpirationListener
objects registered with theLeaseRenewalManager
. Should theLeaseRenewalManager
invoke a method on a registered listener (a local call), calls from that method to any method of theLeaseRenewalManager
are guaranteed not to result in a deadlock condition. One implication of this guarantee is that the delivery of events is asynchronous with respect to any call (or sequence of calls) made on the renewal manager after the event occurs; this allows events to be delivered after they have been made moot by intervening calls on the renewal manager. For example, the renewal manager may deliver events regarding leases that were removed from the managed set after the calls that removed the leases in question completed. Implementations should keep the window where such notifications could occur as small as possible.The
equals
method for this class returns true if and only if two instances of this class refer to the same object. That is,x
andy
are equal instances of this class if and only ifx
==
y
has the valuetrue
.The constructor has three forms:
- The first form of the constructor takes no arguments. This form of the constructor instantiates a
LeaseRenewalManager
object that initially manages no leases.
- The second form of the constructor creates a
LeaseRenewalManager
for which the configuration argument controls implementation-specific details of the behavior of the instance created. This form of the constructor instantiates aLeaseRenewalManager
object that initially manages no leases.
- The third form of the constructor creates a
LeaseRenewalManager
that initially manages a single lease. This form of the constructor requires that a reference to the initial lease be supplied as an argument. This form of the constructor also takes adesiredExpiration
argument that represents the desired expiration time for the lease and a reference to aLeaseListener
object that should receive notifications of events associated with the lease.Creating a
LeaseRenewalManager
using the third form of the constructor is equivalent to invoking the no-argument constructor followed by an invocation of the three-argument form of therenewUntil
method (described later).The
renewUntil
method adds a lease to the set of leases being managed by theLeaseRenewalManager
. There are two versions of this method: a four-argument form that allows the client to specify the renewal duration directly, and a three-argument form that infers the renewal duration from the desired expiration argument. The four-argument form will be described first.This method takes as arguments: a reference to the lease to manage, the desired expiration time of the lease, the renewal duration time for the lease, and a reference to the
LeaseListener
object that will receive notification of events associated with this lease. TheLeaseListener
argument may benull
.If
null
is passed as the lease parameter, aNullPointerException
will be thrown. If thedesiredExpiration
parameter isLease.FOREVER
, therenewDuration
parameter may beLease.ANY
or any positive value; otherwise, therenewDuration
parameter must be a positive value. If therenewDuration
parameter does not meet these requirements, anIllegalArgumentException
will be thrown.If the lease passed to this method is already in the set of managed leases, the listener object, the desired expiration, and the renewal duration associated with that lease will be replaced with the new listener, desired expiration, and renewal duration.
A lease will remain in the set of managed leases until one of the following occurs:
- The lease's desired expiration time is reached; this will generate a desired expiration reached event
.
- An explicit removal of the lease from the set is requested via a
cancel
,clear
, orremove
call on the renewal manager.
- The lease's actual expiration time is reached before its desired expiration; this will generate a renewal failure event.
- The renewal manager tries to renew the lease and gets a definite exception; this will generate a renewal failure event.
The
renewUntil
method interprets the value of thedesiredExpiration
parameter as the desired absolute system time after which the lease is no longer valid. This argument provides the ability to indicate an expiration time that extends beyond the actual expiration of the lease. If the value passed for this argument does indeed extend beyond the lease's actual expiration time, then the lease will be systematically renewed at appropriate times until one of the conditions listed above occurs. If the value is less than or equal to the actual expiration time, nothing will be done to modify the time when the lease actually expires. That is, the lease will not be renewed with an expiration time that is less than the actual expiration time of the lease at the time of the call.The
renewDuration
parameter is interpreted as the renewal duration, in milliseconds, to associate with the lease.If a non-
null
object reference is passed in as theLeaseListener
parameter, this object will receive notification of exceptional conditions occurring upon a renewal attempt of the lease. In particular, exceptional conditions include the reception of a definite exception or the lease's actual expiration being reached before its desired expiration. If the listener implements the interfaceDesiredExpirationListener
it will also receive notification if the lease's desired expiration is reached while the lease is still in the set.If a definite exception occurs during a lease renewal request, the exception will be wrapped in an instance of the
LeaseRenewalEvent
class (described later) and sent to the listener'snotify
method.If an indefinite exception occurs during a renewal request for a particular lease, renewal requests will continue to be made for that lease until: the lease is renewed successfully, a renewal attempt results in a definite exception, or the lease's actual expiration time has been exceeded. If the lease cannot be successfully renewed before its actual expiration is reached, the exception associated with the most recent renewal attempt will be wrapped in an instance of the
LeaseRenewalEvent
class and sent to the listener'
snotify
method.If the lease's actual expiration is reached before the lease's desired expiration time and either (1) the last renewal attempt succeeded or (2) there have been no renewal attempts, a
LeaseRenewalEvent
containinga
null
exception will be sent to the listener'snotify
method. Case 1 can occur if the extension granted by the last renewal was very short. Case 2 can occur if the client adds a lease that has already expired (or is about to) to the managed set of leases.If
null
is passed as the value of theLeaseListener
parameter, then no notifications will be delivered.Calling the three-argument form of
renewUntil
with adesiredExpiration
ofLease.ANY
is equivalent to making the following call:renewUntil(lease, Lease.FOREVER, Lease.ANY, listener);Otherwise, the three-argument form is equivalent to:
renewUntil(lease, desiredExpiration, Lease.FOREVER, listener);
Usage Note: Unless an application has a good reason for doing otherwise, it should useLease.ANY
orLease.FOREVER
for the renewal duration of a given lease. Using these values gives the grantor of the lease the most flexibility in the length of time for which it grants renewals. In most cases, the grantor of a lease is in a better position than the lease holder to make trade-offs between renewal frequency and the risk of holding on to resources longer than necessary. Specifying a value for the renewal duration of a lease might make sense if the holder of the lease has more information on the value of the leased resource than the grantor, or if the holder needs to ensure that there is an upper bound on how long the lease will remain valid.
The
renewFor
method adds a lease to the set of leases being managed by theLeaseRenewalManager
. LikerenewUntil
this method has both three- and four-argument forms. The four-argument form of this method takes as parameters:lease
, a reference to the lease to manage;desiredDuration
, along
representing the desired duration oflease
;renewDuration
, along
representing the renewal duration; andlistener
, a reference to aLeaseListener
object that will receive notifications of events associated with this lease. BothdesiredDuration
andrenewDuration
are expressed in milliseconds.The semantics of the four-argument form of
renewFor
are similar to those of the four-argument form ofrenewUntil
, withdesiredDuration
+ current time being used for the value of thedesiredExpiration
parameter ofrenewUntil
. The only exception is that, in the context ofrenewFor
, the value of therenewDuration
parameter may beLease.ANY
only if the value of thedesiredDuration
parameter is exactlyLease.FOREVER
.This method tests for arithmetic overflow in the desired expiration time computed from the value of
desiredDuration
parameter (desiredDuration
+ current time). Should such overflow be present, a value ofLease.FOREVER
is used to represent the lease's desired expiration time.The three-argument form of this method is equivalent to the following call:
renewFor(lease, desiredDuration, Lease.FOREVER, listener);Note that for both versions of
renewFor
, a value ofLease.ANY
for thedesiredDuration
parameter does not have any special semantics associated with it. Calling either version ofrenewFor
with adesiredDuration
ofLease.ANY
will result in the lease having a desired expiration one millisecond in the past, causing the lease to be immediately dropped from the managed set. The method will not throw an exception in this circumstance. A renewal failure event will be generated if the actual expiration is before the desired expiration; otherwise a desired expiration reached event will be generated.The
getExpiration
method returns the current desired expiration time requested for a particular lease, not the actual expiration that was granted when the lease was created or last renewed. The only argument to this method is the reference to the lease object. If the lease is not in the set of managed leases, anUnknownLeaseException
will be thrown.The
setExpiration
method replaces the current desired expiration of a given lease contained in the set of managed leases with a new desired expiration time. The only arguments to this method are the reference to the lease object and the new expiration time.An invocation of this method with a lease that is currently a member of the managed set is equivalent to an invocation of the
renewUntil
method with the lease's current listener input to the listener parameter. In particular, if the value of the expiration parameter is less than or equal to the lease's current actual expiration, this method takes no action.An invocation of this method with a lease that is not in the set of managed leases will result in an
UnknownLeaseException
.The
remove
method removes a given lease from the set of managed leases. The only argument to this method is the reference to the lease object. If the lease is not in the set of managed leases, anUnknownLeaseException
will be thrown.Note that this method does not cancel the given lease; activities such as lease cancellation are left for the client to manage.
The
cancel
method both removes a given lease from the set of managed leases and cancels the given lease. The only argument to this method is the reference to the lease object. If the lease is not in the set of managed leases, anUnknownLeaseException
will be thrown.Any exception (definite or otherwise) occurring during the cancellation of the lease will have no effect on the removal of the lease from the managed set. That is, even if an exception occurs during the
cancel
operation, the lease will have been removed from the managed set upon return from this method.Any exception thrown by the
cancel
method of the lease object itself may also be thrown by this method.The
clear
method removes all leases from the set of managed leases. It does not request the cancellation of those leases. This method takes no arguments.LM.5 Supporting Interfaces and Classes
The
LeaseRenewalManager
utility class depends on the interfacesLeaseListener
andDesiredExpirationListener
. Both of these interfaces reference one class,LeaseRenewalEvent
.LM.5.1 The
LeaseListener
InterfaceThe public methods specified by the
LeaseListener
interface are as follows:package net.jini.lease; public interface LeaseListener extends EventListener { void notify(LeaseRenewalEvent e); }The
LeaseListener
interface defines the mechanism through which the client receives notification of renewal failure events generated by the renewal manager. These events are delivered using thenotify
method. Renewal failure events are generated when theLeaseRenewalManager
has failed to renew one of the leases that it is managing. Such renewal failures typically occur because one of the following conditions is met:
- After successfully renewing a lease any number of times and experiencing no failures, the
LeaseRenewalManager
determines--prior to the next renewal attempt--that the actual expiration time of the lease has passed; implying that any further attempt to renew the lease would be fruitless.
- An indefinite exception occurs during each attempt to renew a lease from the point that the first such exception occurs until the point when the
LeaseRenewalManager
determines that lease's actual expiration time has passed.
- A definite exception occurs during a lease renewal attempt.
It is the responsibility of the client to pass into the
LeaseRenewalManager
a reference to an object that implements theLeaseListener
interface, which defines the actions to take upon receipt of a renewal failure event notification. When one of the above conditions occurs, theLeaseRenewalManager
will send an instance ofLeaseRenewalEvent
to that listener object.LM.5.1.1 The Semantics
The
notify
method is invoked by theLeaseRenewalManager
when it fails to renew a lease because one of the conditions described above has occurred. This method takes one parameter, an instance of theLeaseRenewalEvent
class, which contains information about the lease on which the failed renewal attempt was made and information on what caused the failure.Note that prior to invoking the
notify
method, theLeaseRenewalManager
removes the lease that could not be renewed from the managed set of leases. Note also that because of the reentrancy guarantee made by theLeaseRenewalManager
, new leases can be added safely from within thenotify
method.LM.5.2 The
DesiredExpirationListener
InterfaceThe public methods specified by the
DesiredExpirationListener
interface are as follows:package net.jini.lease; public interface DesiredExpirationListener extends LeaseListener { void expirationReached(LeaseRenewalEvent e); }The
expirationReached
method receives desired expiration reached events. These are generated when theLeaseRenewalManager
removes a lease from the managed set because the lease's desired expiration has been reached. Note that any object that has been registered to receive desired expiration reached events will also receive renewal failure events.It is the responsibility of the client to pass into the
LeaseRenewalManager
a reference to an object that implements theDesiredExpirationListener
interface, which defines the actions to take upon receipt of a desired expiration reached event notification.LM.5.2.1 The Semantics
The
expirationReached
method is invoked by theLeaseRenewalManager
when a lease in the managed set reaches its desired expiration. This method takes one parameter: an instance of theLeaseRenewalEvent
class, which contains information about the lease who's desired expiration has been reached.Note that prior to invoking the
expirationReached
method, theLeaseRenewalManager
removes the affected lease from the managed set of leases. Note also that because of the reentrancy guarantee made by theLeaseRenewalManager
, callbacks into the renewal manager can be made safely from within theexpirationReached
method.LM.5.3 The
LeaseRenewalEvent
ClassThis class defines the local event that is sent by the
LeaseRenewalManager
to the client's registered listener when theLeaseRenewalManager
generates a renewal failure event or desired expiration reached event. As previously stated, a renewal failure event typically occurs because the actual expiration time of a lease has been reached before a successful renewal request could be made, or a renewal request resulted in a definite exception. A desired expiration reached event occurs when a lease reaches its desired expiration time at or before its actual expiration. TheLeaseRenewalEvent
class encapsulates information about the lease on which such an event occurs and, if it is a renewal failure, the cause.package net.jini.lease; public class LeaseRenewalEvent extends EventObject { public LeaseRenewalEvent(LeaseRenewalManager source, Lease lease, long expiration, Throwable ex) {...} public Lease getLease() {...} public long getExpiration() {...} public Throwable getException() {...} }The
LeaseRenewalEvent
class is a subclass of theEventObject
class, adding the following additional items of abstract state: a reference to the associatedLease
object; along
value representing the desired expiration of the lease; and the exception (if any) that caused the event to be sent. In addition to the methods of theEventObject
class, this class defines methods through which this additional state may be retrieved.LM.5.3.1 The Semantics
The constructor of the
LeaseRenewalEvent
class takes the following parameters as input:
- A reference to the instance of the
LeaseRenewalManager
that generated the event
- The lease associated with this event
- The desired expiration time of the lease
- The
Throwable
associated with the last renewal attempt (if any)The
getLease
method returns a reference to theLease
object associated with the event. This method takes no arguments.The
getExpiration
method returns along
value representing the desired expiration of theLease
object associated with the event. This method takes no arguments.The
getException
method returns the exception, if any, that is associated with the event. This method takes no arguments. If theLeaseRenewalEvent
represents a desired expiration reached event this method will returnnull
.If the
LeaseRenewalEvent
represents a renewal failure event thegetException
method will return the exception that caused the event to be sent. The conditions under which a renewal failure event may be sent, and the related values returned by this method, are as follows:
- When any lease in the managed set has passed its actual expiration time, and either the most recent renewal attempt was successful or there have been no renewal attempts, the
LeaseRenewalManager
will cease any further attempts to renew the lease, and will send aLeaseRenewalEvent
with no associated exception. In this case, invoking this method will returnnull
.
- For any lease from the managed set for which the most recent renewal attempt was unsuccessful because of the occurrence of a indefinite exception, the
LeaseRenewalManager
will continue to attempt to renew the affected lease at the appropriate times until: the renewal succeeds, the lease's actual expiration time has passed, or a renewal attempt throws a definite exception. If a definite exception is thrown or the lease expires, theLeaseRenewalManager
will cease any further attempts to renew the lease, and will send aLeaseRenewalEvent
containing the exception associated with the last renewal attempt.
- If, while attempting to renew a lease from the managed set, a definite exception is encountered, the
LeaseRenewalManager
will cease any further attempts to renew the lease, and will send aLeaseRenewalEvent
containing the particular exception that occurred.LM.5.4 Serialized Forms
Class serialVersionUID Serialized Fields LeaseRenewalEvent
-626399341646348302L Lease lease
long expiration
Throwable exLM.6 History
Version Description v1.0 Initial release of this specification. License
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Spec Index | A Collection of Jini Technology Helper Utilities and Services Specifications |