Package com.sun.jini.landlord
Class FixedLeasePeriodPolicy
java.lang.Object
com.sun.jini.landlord.FixedLeasePeriodPolicy
- All Implemented Interfaces:
LeasePeriodPolicy
- Direct Known Subclasses:
SystemTimeFixedLeasePeriodPolicy
Simple implementation of
LeasePeriodPolicy that grants lease times based on a fixed
default and maximum lease. Will grant renewals longer than the maximum if the current lease and
the request are both longer than the maximum.- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.sun.jini.landlord.LeasePeriodPolicy
LeasePeriodPolicy.Result -
Constructor Summary
ConstructorsConstructorDescriptionFixedLeasePeriodPolicy(long maximum, long defaultLength) Create a newFixedLeasePeriodPolicywith the specified values for the maxium and default lease lengths. -
Method Summary
Modifier and TypeMethodDescriptionprotected longcalculateDuration(LeasedResource resource, long requestedDuration) Returns the duration this policy is willing to grant for the passed resource at this time.protected longMethod that provides some notion of the current time in milliseconds since the beginning of the epoch.grant(LeasedResource resource, long requestedDuration) Calculate the initial expiration and duration for a new lease.renew(LeasedResource resource, long requestedDuration) Calculate the expiration and duration for an existing lease that is being renewed.
-
Constructor Details
-
FixedLeasePeriodPolicy
public FixedLeasePeriodPolicy(long maximum, long defaultLength) Create a newFixedLeasePeriodPolicywith the specified values for the maxium and default lease lengths.- Parameters:
maximum- the length in milliseconds of the longest lease this object should normally grantdefaultLength- the length in milliseconds of the default lease grants- Throws:
IllegalArgumentException- if either argument is not positive.
-
-
Method Details
-
calculateDuration
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.Note the duration returned by this method will be shorter than the final duration granted if the requested duration extends past the current expiration, and duration return by this method is before the current expiration.
- Parameters:
resource- the resource having a lease granted or renewedrequestedDuration- the duration the client wants- Throws:
IllegalArgumentException- thrown if requestedDuration is less than 0 and not equal toLease.ANYLENGTHorLease.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() -
grant
public LeasePeriodPolicy.Result grant(LeasedResource resource, long requestedDuration) throws LeaseDeniedException Description copied from interface:LeasePeriodPolicyCalculate the initial expiration and duration for a new lease.- Specified by:
grantin interfaceLeasePeriodPolicy- Parameters:
resource- the server side representation of the new lease that needs an initial expiration and durationrequestedDuration- the initial duration the requester of the resources would like. May beLease.ANY- Returns:
- A
Resultthat holds both the expiration and duration. - Throws:
LeaseDeniedException- if the grant request is denied.
-
renew
public LeasePeriodPolicy.Result renew(LeasedResource resource, long requestedDuration) throws LeaseDeniedException Description copied from interface:LeasePeriodPolicyCalculate the expiration and duration for an existing lease that is being renewed.- Specified by:
renewin interfaceLeasePeriodPolicy- Parameters:
resource- the server side representation of the lease that is being renewedrequestedDuration- the duration the client is requesting. May beLease.ANY.- Returns:
- A
Resultthat holds both the expiration and duration. - Throws:
LeaseDeniedException- if the renewal request is denied.
-