leaseToRemove = (Lease) leasePreparer.prepareProxy(leaseToRemove);
logger.log(Level.FINE, "Removing lease {0}", leaseToRemove);
// The most up-to-date ref to the lease we have
Lease rslt = null;
try {
store.acquireMutatorLock();
synchronized (set) {
ensureCurrent(set);
final ClientLeaseWrapper clw
= set.getClientLeaseWrapper(leaseToRemove);
if (clw == null) {
// Lease must have been removed already
return null;
}
try {
lrm.remove(clw);
} catch (UnknownLeaseException e) {
// This can happen if there was some problem
// renewing the lease or its LRM expiration just
// ran out. Since we are removing the lease anyway
// ignore.
}
final boolean present = set.remove(clw);
// Only return a non-null result if the removed lease
// had not be removed already
if (present) {
// At this point we can assume clw is no
// longer deformed
rslt = clw.getClientLease();
}
}
} finally {
store.releaseMutatorLock();
}
if (rslt == null)
return null;
// Whenever we serialize a lease we have to make sure that
// its serial form will stay the same during the
// serialization. Since we have removed it from the set we
// don't have to worry about this lease being serialized to disk
// any more so changing the serial format here should be safe.
rslt.setSerialFormat(Lease.DURATION);
return rslt;
}