// inherit javadoc
// This method assumes that none of the leases in the map are
// also being renewed by some other thread.
public void renewAll() throws LeaseMapException, RemoteException {
LeaseMapException lme = null;
Map newExceptionMap = null;
// Iterate over the wrappers, causing the appropriate exceptions
// for the ones who's sets have expired.
final long now = System.currentTimeMillis();
for (Iterator i=wrapperMap.values().iterator(); i.hasNext(); ) {
final ClientLeaseWrapper clw = (ClientLeaseWrapper) i.next();
if (!clw.ensureCurrent(now)) {
// Map an exception to this lease and drop from the map
// If necessary create newExceptionMap
if (newExceptionMap == null)
newExceptionMap = new HashMap(wrapperMap.size());
// Add to the newExceptionMap
newExceptionMap.put(clw,
LRMEventListener.EXPIRED_SET_EXCEPTION);
// Drop from both the wrapper and inner map
i.remove();
clientLeaseMap.remove(clw.getClientLease());
// Note, we don't call failedRenewal() because the set is
// dead so logging changes is pointless. Besides, there
// is no change to log.
}
}
// If the map is now empty don't bother calling renewAll()
if (clientLeaseMap.isEmpty()) {
if (newExceptionMap == null)
return;
throw new LeaseMapException("Expired Sets", newExceptionMap);
}
try {
clientLeaseMap.renewAll();
} catch (LeaseMapException e) {
lme = e;
} catch (RemoteException e) {
applyException(e);
throw e;
} catch (Error e) {
applyException(e);
throw e;
} catch (RuntimeException e) {
applyException(e);
throw e;
}
// For each Lease still in the map we need to update the wrapper
for (Iterator i=clientLeaseMap.keySet().iterator(); i.hasNext(); ) {
final Lease cl = (Lease) i.next();
final ClientLeaseWrapper clw =
(ClientLeaseWrapper) wrapperMap.get(cl);
clw.successfulRenewal();
}
// If there were no errors just return
if (lme == null && newExceptionMap == null)
return;
// If the renewAll() threw a LeaseMapException we have to
// remove the problem leases from the wrapper and place
// them in newExceptionMap
if (lme != null) {
final Map exceptionMap = lme.exceptionMap;
// Create the newExceptionMap if we don't have one
if (newExceptionMap == null)
newExceptionMap = new HashMap(exceptionMap.size());
// Copy each lease out of the exception's map into newExceptionMap,
// also remove these leases from the wrapper and get the
// failure logged
for (Iterator i = exceptionMap.entrySet().iterator();
i.hasNext(); )
{
final Map.Entry e = (Map.Entry) i.next();
final Lease cl = (Lease) e.getKey();
final Throwable t = (Throwable) e.getValue();
final ClientLeaseWrapper clw =
(ClientLeaseWrapper) wrapperMap.remove(cl);
i.remove();
clw.failedRenewal(t);
newExceptionMap.put(clw, t);
}
}
// If necessary throw a LeaseMapException
if (newExceptionMap != null) {
throw new LeaseMapException(
(lme == null) ? "Expired Sets" : lme.getMessage(),
newExceptionMap);
}
return;
}