public class FixedLeasePeriodPolicy extends Object implements LeasePeriodPolicy
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.LeasePeriodPolicy.Result
Constructor and Description |
---|
FixedLeasePeriodPolicy(long maximum,
long defaultLength)
Create a new
FixedLeasePeriodPolicy with
the specified values for the maxium and default lease
lengths. |
Modifier and Type | Method and Description |
---|---|
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.
|
LeasePeriodPolicy.Result |
grant(LeasedResource resource,
long requestedDuration)
Calculate the initial expiration and duration for
a new lease.
|
LeasePeriodPolicy.Result |
renew(LeasedResource resource,
long requestedDuration)
Calculate the expiration and duration for an
existing lease that is being renewed.
|
public FixedLeasePeriodPolicy(long maximum, long defaultLength)
FixedLeasePeriodPolicy
with
the specified values for the maxium and default lease
lengths.maximum
- the length in milliseconds of the longest lease
this object should normally grantdefaultLength
- the length in milliseconds of the
default lease grantsIllegalArgumentException
- if either argument
is not positive.protected long calculateDuration(LeasedResource resource, long requestedDuration)
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.
resource
- the resource having a lease granted
or renewedrequestedDuration
- the duration the client wantsIllegalArgumentException
- thrown if requestedDuration
is less than 0 and not equal to
Lease.ANYLENGTH
or
Lease.FOREVER
.protected long currentTime()
public LeasePeriodPolicy.Result grant(LeasedResource resource, long requestedDuration) throws LeaseDeniedException
LeasePeriodPolicy
grant
in interface LeasePeriodPolicy
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 be
Lease.ANY
Result
that holds
both the expiration and duration.LeaseDeniedException
- if the grant request
is denied.public LeasePeriodPolicy.Result renew(LeasedResource resource, long requestedDuration) throws LeaseDeniedException
LeasePeriodPolicy
renew
in interface LeasePeriodPolicy
resource
- the server side representation of the lease that is
being renewedrequestedDuration
- the duration the client is requesting. May be
Lease.ANY
.Result
that holds
both the expiration and duration.LeaseDeniedException
- if the renewal request
is denied.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.