|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.jini.norm.ClientLeaseWrapper
class ClientLeaseWrapper
Class that wraps client Leases. Provides hooks for synchronization
and data associated with each client lease while allowing us to
use LeaseRenewalManager
.
This code assumes most synchronization is being done at the set level, this works because no lease is in more than one set at a given time. The only place where additional synchronization is going on is in renewals and the logging of renewals.
Nested Class Summary | |
---|---|
private class |
ClientLeaseWrapper.FailureFactory
Nested top-level implementation of EventFactory that
generates RenewalFailureEvent events |
Field Summary | |
---|---|
private Lease |
clientLease
Transient copy of unpacked lease, null if we could not
unpack or prepare the lease. |
private long |
clientLeaseExpiration
Most current expiration time of client Lease that we know of |
private Throwable |
lastFailure
Throwable thrown by the last renew attempt on the client lease. |
private static Method[] |
leaseToLeaseMethods
|
private static Logger |
logger
Logger for logging messages for this class |
private MarshalledInstance |
marshalledClientLease
Client lease in marshalled form. |
private long |
membershipExpiration
Membership expiration of this lease |
private ProxyPreparer |
recoveredLeasePreparer
The proxy preparer to use to prepare a newly unmarshalled client lease, or null if this instance was created using an already prepared client lease, which is how instances are created initially. |
private boolean |
renewalPending
Flag used to check if lease has been persisted since last renewal, true means it has not been |
private long |
renewDuration
renewDuration of this lease |
private List |
renewedList
Reference to list of leases that have been renewed, but not persisted |
private static long |
serialVersionUID
|
private LeaseSet |
set
The LeaseSet we belong to |
private long |
UID
Sequence number that uniquely identifies this wrapper |
Fields inherited from interface net.jini.core.lease.Lease |
---|
ABSOLUTE, ANY, DURATION, FOREVER |
Constructor Summary | |
---|---|
ClientLeaseWrapper(Lease clientLease,
long UID,
List renewedList,
LeaseSet leaseSet,
long membershipDuration,
long renewDuration,
long now)
Simple constructor |
Method Summary | |
---|---|
private void |
calcMembershipExpiration(long membershipDuration,
long now)
Given the current time and a membershipDuration set membershipExpiration the correct value. |
boolean |
canBatch(Lease lease)
Another lease can be batched with this one if it is a ClientLeaseMapWrapper, if it is either a member of the same lease renewal set or sets are not isolated, if neither lease is deformed, if the leases either both have the same client constraints or do not implement RemoteMethodControl, and if the underlying client leases can be batched. |
void |
cancel()
Always throws UnsupportedOperationException since
a lease renewal service should never cancel a client lease. |
private void |
changed()
Called when a renewal thread changes the persistent state of the this wrapper. |
(package private) void |
clearRenewed()
Atomically clear the renewalPending flag. |
LeaseMap |
createLeaseMap(long duration)
Creates a Map object that can contain leases whose renewal or cancellation can be batched, and adds the current lease to that map. |
(package private) boolean |
ensureCurrent(long now)
Called by ClientLeaseMapWrapper to see if the set associated with this wrapper is still valid. |
boolean |
equals(Object that)
|
(package private) void |
failedRenewal(Throwable t)
Sets lastFailure and adds the this to the renewed list so it so the change can be logged. |
(package private) Lease |
getClientLease()
Get a reference to the client lease, unmarshalling and preparing it if necessary. |
long |
getExpiration()
Returns a long that indicates the time that the
lease will expire. |
(package private) Throwable |
getLastFailure()
Return the exception (if any) that occured at the last renewal attempt |
(package private) LeaseSet |
getLeaseSet()
The LeaseSet this lease is in |
(package private) MarshalledInstance |
getMarshalledClientLease()
Return the client lease in marshalled form. |
(package private) long |
getMembershipExpiration()
Return the membershipExpiration of this lease |
(package private) long |
getRenewDuration()
Return the renewDuration of this lease |
int |
getSerialFormat()
Always throws UnsupportedOperationException . |
int |
hashCode()
|
(package private) boolean |
isDeformed()
Return true if the underlying client lease has not yet been deserialized |
(package private) EventFactory |
newFailureFactory(LeaseRenewalSet source)
Return an EventFactory that will create an
appropriate RenewalFailureEvent for the client
lease associated with this wrapper. |
(package private) void |
recoverTransient(List renewedList,
UIDGenerator generator,
LeaseSet leaseSet,
ProxyPreparer recoveredLeasePreparer)
After recovering a lease wrapper call this method before using any other of the wrappers methods and before allocating any new wrappers can not recover itself. |
void |
renew(long duration)
Used to renew a lease for an additional period of time, specified in milliseconds. |
private static boolean |
sameConstraints(Lease l1,
Lease l2)
Returns true if the two leases both implement RemoteMethodControl and have the same constraints for Lease methods, or both don't implement RemoteMethodControl, else returns false. |
void |
setSerialFormat(int format)
Always throws UnsupportedOperationException . |
(package private) void |
successfulRenewal()
Log a successful lease renewalNote this is only called from from renew methods that are renewing the client lease associated with this wrapper so additional synchronization should not be necessary. |
private boolean |
testAndSetRenewalPending()
Atomically test and set the renewalPending flag. |
String |
toString()
|
(package private) void |
update(long membershipDuration,
long renewDuration,
long now)
Update the membership expiration and renewDuration of this lease |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
private static final Logger logger
private static final Method[] leaseToLeaseMethods
private Throwable lastFailure
null
if the renew has not been called yet or
the last renewal call succeeded.
private MarshalledInstance marshalledClientLease
private long clientLeaseExpiration
private long UID
private long membershipExpiration
private long renewDuration
private transient LeaseSet set
private transient Lease clientLease
null
if we could not
unpack or prepare the lease.
private transient ProxyPreparer recoveredLeasePreparer
private transient boolean renewalPending
true
means it has not been
private transient List renewedList
Constructor Detail |
---|
ClientLeaseWrapper(Lease clientLease, long UID, List renewedList, LeaseSet leaseSet, long membershipDuration, long renewDuration, long now) throws IOException
clientLease
- lease from client that is to be renewedUID
- ID number for this wrapper unique for all wrappers in a given
serverrenewedList
- list that wrapper should go on after renewing their
client lease is renewedleaseSet
- the LeaseSet
this lease is inmembershipDuration
- initial membership duration for this leaserenewDuration
- initial membership expiration for the leasenow
- the current time
IOException
Method Detail |
---|
private void calcMembershipExpiration(long membershipDuration, long now)
void update(long membershipDuration, long renewDuration, long now)
long getMembershipExpiration()
long getRenewDuration()
void clearRenewed()
Lease getClientLease()
MarshalledInstance getMarshalledClientLease()
Assumes that no one else will be serializing the lease during this call.
public boolean equals(Object that)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public long getExpiration()
Lease
long
that indicates the time that the
lease will expire. This time is represented as
milliseconds from the beginning of the epoch, relative to the local
clock.
getExpiration
in interface Lease
long
that indicates the time that the
lease will expirepublic void cancel()
UnsupportedOperationException
since
a lease renewal service should never cancel a client lease.
cancel
in interface Lease
Throwable getLastFailure()
private boolean testAndSetRenewalPending()
private void changed()
boolean ensureCurrent(long now)
void failedRenewal(Throwable t)
void successfulRenewal()
public void renew(long duration) throws LeaseDeniedException, UnknownLeaseException, RemoteException
Lease
renew
in interface Lease
duration
- the requested duration in milliseconds
LeaseDeniedException
- the lease grantor is unable or
unwilling to renew the lease
UnknownLeaseException
- the lease being renewed is unknown
to the lease grantor
RemoteException
public void setSerialFormat(int format)
UnsupportedOperationException
. The
LeaseRenewalManager
should never call this method and
norm always serializes the wrapper with absolute times.
setSerialFormat
in interface Lease
format
- DURATION or ABSOLUTELease.getSerialFormat()
public int getSerialFormat()
UnsupportedOperationException
. The
LeaseRenewalManager
should never call this method and
norm always serializes the wrapper with absolute times.
getSerialFormat
in interface Lease
Lease.setSerialFormat(int)
public LeaseMap createLeaseMap(long duration)
Lease
createLeaseMap
in interface Lease
duration
- the duration to put into a Long and use as the
value for the current lease in the created LeaseMap
public boolean canBatch(Lease lease)
canBatch
in interface Lease
lease
- the Lease to be evaluated
private static boolean sameConstraints(Lease l1, Lease l2)
void recoverTransient(List renewedList, UIDGenerator generator, LeaseSet leaseSet, ProxyPreparer recoveredLeasePreparer)
renewedList
- List that wrapper should go on after renewing their
client lease is renewedgenerator
- ID generator being used to generate IDs client lease
wrappersleaseSet
- the set this wrapper is associated withrecoveredLeasePreparer
- the proxy preparer to use to prepare
client leases recovered from persistent storageboolean isDeformed()
LeaseSet getLeaseSet()
LeaseSet
this lease is in
EventFactory newFailureFactory(LeaseRenewalSet source) throws IOException
EventFactory
that will create an
appropriate RenewalFailureEvent
for the client
lease associated with this wrapper. This method assumes
that no one else will be setting the serialization format
of the lease during the course of the call.
source
- Source object for the event
IOException
- if the client lease could not be pre
marshalled.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |