com.sun.jini.lease.landlord
Class LeaseDurationPolicy
java.lang.Object
|
+--com.sun.jini.lease.landlord.LeaseDurationPolicy
- public class LeaseDurationPolicy
- extends java.lang.Object
- implements LeasePolicy
Provides an implementation of LeasePolicy that grants and renews
leases based on constant values for maximum and default lease
durations.
When an instance of the class is created a
LeaseManager
may be associated with it. The manager
will be notified when a Lease is created or renewed.
- See Also:
Landlord
,
LeasedResource
,
LeaseManager
,
Lease
Method Summary |
protected long |
calculateDuration(LeasedResource resource,
long requestedDuration)
Returns the duration this policy is willing to grant for the
passed resource at this time. |
protected long |
currentTime()
Method that provides some notion of the current time in milliseconds
since the beginning of the epoch. |
boolean |
ensureCurrent(LeasedResource resource)
Returns true if the lease on the passed resource
has not expired yet. |
Lease |
leaseFor(LeasedResource resource,
long requestedDuration)
Factory method that returns lease objects for the specified
resource. |
long |
renew(LeasedResource resource,
long requestedDuration)
Renews the expiration of the passed resource. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
LeaseDurationPolicy
public LeaseDurationPolicy(long maximum,
long defaultLength,
Landlord landlord,
LeaseManager mgr,
LandlordLeaseFactory factory)
- Create a
LeaseDurationPolicy
that will handout the
leases with the specified maximum and default durations.
Leases with a requested duration less than maximum will be
granted exactly.
- Parameters:
maximum
- The length in milliseconds of the longest lease
this manager should handout.defaultLength
- The length in milliseconds of lease this
manager should handout if the client expresses
no preference.landlord
- The owner of the leased resources being managed
by this manager.mgr
- LeaseManager
that will be notified
of lease creations and renewals. May be
null
factory
- Factory that will be used to generate new leases.
If null
a LandlordLease
factory will be used.- Throws:
- java.lang.IllegalArgumentException - thrown if
defaultLength
and maximum
are not larger than 0 or if landlord
is
null
.
leaseFor
public Lease leaseFor(LeasedResource resource,
long requestedDuration)
throws LeaseDeniedException
- Factory method that returns lease objects for the specified
resource. The lease will call the
Landlord
object
passed to the manager's constructor to handle renewal and
cancel requests. The cookie passed to these calls will be the
same as the cookie returned by
resource.getCookie()
. The duration of the lease
will be affected by the requested duration, and the default and
maximum parameters passed to the constructor.
- Specified by:
- leaseFor in interface LeasePolicy
- Parameters:
resource
- The resource the lease is for.
resource.setExpiration
will be called
to initialize the expiration time of the resource.requestedDuration
- The length of lease the client wants.- Returns:
- A lease for the passed resource
- Throws:
- java.lang.IllegalArgumentException - thrown if requestedDuration
is less than 0 and not equal to Lease.ANYLENGTH or Lease.FOREVER.
renew
public long renew(LeasedResource resource,
long requestedDuration)
- Renews the expiration of the passed resource. The duration of
renewal is based on the requested duration
and the default and maximum parameters passed to the constructor.
- Specified by:
- renew in interface LeasePolicy
- Parameters:
resource
- The resource having its lease renewed.
resource.setExpiration
will be called
to update the expiration time of the resource.requestedDuration
- The new duration the client wants- Returns:
- The new duration the lease should have.
- Throws:
- java.lang.IllegalArgumentException - thrown if requestedDuration
is less than 0 and not equal to
Lease.ANYLENGTH
or
Lease.FOREVER
.
ensureCurrent
public boolean ensureCurrent(LeasedResource resource)
- Returns
true
if the lease on the passed resource
has not expired yet.
- Specified by:
- ensureCurrent in interface LeasePolicy
calculateDuration
protected long calculateDuration(LeasedResource resource,
long requestedDuration)
- Returns the duration this policy is willing to grant for the
passed resource at this time. The duration actually granted
will be shorter if the duration extends pass the end of the
epoch. Must return a positive number.
- Parameters:
resource
- The resource having a lease granted
or renewedrequestedDuration
- The duration the client wants- Throws:
- java.lang.IllegalArgumentException - thrown if requestedDuration
is less than 0 and not equal to
Lease.ANYLENGTH
or
Lease.FOREVER
.
currentTime
protected long currentTime()
- Method that provides some notion of the current time in milliseconds
since the beginning of the epoch. Default implementation
calls System.currentTimeMillis()
Copyright © 1999 Sun Microsystems, Inc. All rights reserved