public Entry(Lease lease, long expiration, long renewDuration, long renewalRTT, LeaseListener listener) { this.endTime = lease.getExpiration(); this.lease = lease; this.expiration = expiration; this.renewDuration = renewDuration; this.listener = listener; this.renewalRTT = renewalRTT; id = cnt++; }
/** Requests the cancellation of the lease on the * <code>ServiceRegistration</code> that is referenced in the * <code>proxyReg</code> data structure. */ @Override public void run() { logger.finest("JoinManager --> DiscardProxyTask started"); Lease svcLease = proxyReg != null ? proxyReg.serviceLease : null; if( svcLease != null ) { try { svcLease.cancel(); } catch (Exception e) { /*ignore*/ } }//endif logger.finest("JoinManager - DiscardProxyTask completed"); }//end run
/** * Simple constructor * @param clientLease lease from client that is to be renewed * @param UID ID number for this wrapper unique for all wrappers in a given * server * @param renewedList list that wrapper should go on after renewing their * client lease is renewed * @param leaseSet the <code>LeaseSet</code> this lease is in * @param membershipDuration * initial membership duration for this lease * @param renewDuration * initial membership expiration for the lease * @param now the current time */ ClientLeaseWrapper(Lease clientLease, long UID, List renewedList, LeaseSet leaseSet, long membershipDuration, long renewDuration, long now) throws IOException { this.renewedList = renewedList; this.UID = UID; this.clientLease = clientLease; set = leaseSet; clientLeaseExpiration = clientLease.getExpiration(); clientLease.setSerialFormat(Lease.ABSOLUTE); marshalledClientLease = new AtomicMarshalledInstance(clientLease); this.renewDuration = renewDuration; membershipExpiration = calcMembershipExpiration(membershipDuration, now); }
/** Create a LeaseMap for batch renewal */ private static LeaseMap createBatchLeaseMap(List bList, long now) { Iterator iter = bList.iterator(); Entry e = (Entry) iter.next(); LeaseMap batchLeaseMap = e.lease.createLeaseMap(e.getRenewDuration(now)); if (e.lease instanceof RemoteMethodControl && batchLeaseMap instanceof RemoteMethodControl) { batchLeaseMap = (LeaseMap) ((RemoteMethodControl) batchLeaseMap).setConstraints( ConstrainableProxyUtil.translateConstraints( ((RemoteMethodControl) e.lease).getConstraints(), leaseToLeaseMapMethods)); } while (iter.hasNext()) { e = (Entry) iter.next(); batchLeaseMap.put(e.lease, Long.valueOf(e.getRenewDuration(now))); } return batchLeaseMap; }
!e.renewalsDone() && sameConstraints(lease, e.lease) && lease.canBatch(e.lease) && (renewDuration == Lease.ANY || renew - e.renew <= renewalRTT / 2 ||
Entry e = (Entry) bList.get(0); logger.log(Level.FINE, "Renewing lease {0}", e.lease); e.lease.renew(e.getRenewDuration(now)); } else { LeaseMap batchLeaseMap = createBatchLeaseMap(bList, now);
/** * Return the client lease in marshalled form. If possible * marshal using the Lease.DURATION serialization format. * <p> * Assumes that no one else will be serializing the lease * during this call. */ MarshalledInstance getMarshalledClientLease() { final Lease cl = getClientLease(); if (cl == null) { // We are deformed, best we can do is return the (possibly // stale) pre-marshalled lease we already have return marshalledClientLease; } else { try { cl.setSerialFormat(Lease.DURATION); return new MarshalledInstance(cl); } catch (IOException e) { // Can't create a new MarshalledInstance, return the old one return marshalledClientLease; } finally { cl.setSerialFormat(Lease.ABSOLUTE); } } }
/** * Create a LeaseMap for batch renewal */ private static LeaseMap createBatchLeaseMap(List<Entry> bList, long now) { Iterator<Entry> iter = bList.iterator(); Entry e = iter.next(); LeaseMap batchLeaseMap = e.lease.createLeaseMap(e.getRenewDuration(now)); if (e.lease instanceof RemoteMethodControl && batchLeaseMap instanceof RemoteMethodControl) { batchLeaseMap = (LeaseMap) ((RemoteMethodControl) batchLeaseMap).setConstraints( ConstrainableProxyUtil.translateConstraints( ((RemoteMethodControl) e.lease).getConstraints(), leaseToLeaseMapMethods)); } while (iter.hasNext()) { e = iter.next(); batchLeaseMap.put(e.lease, new Long(e.getRenewDuration(now))); } return batchLeaseMap; }
!e.renewalsDone() && sameConstraints(lease, e.lease) && lease.canBatch(e.lease) && (renewDuration == Lease.ANY || renew - e.renew <= renewalRTT / 2 ||
Entry e = bList.get(0); logger.log(Level.FINE, "Renewing lease {0}", e.lease); e.lease.renew(e.getRenewDuration(now)); } else { LeaseMap batchLeaseMap = createBatchLeaseMap(bList, now);
rslt.setSerialFormat(Lease.DURATION); return rslt;
public Entry(Lease lease, long expiration, long renewDuration, LeaseListener listener, long renewalRTT) { this.endTime = lease.getExpiration(); this.lease = lease; this.expiration = expiration; this.renewDuration = renewDuration; this.listener = listener; this.renewalRTT = renewalRTT; id = cnt++; }
/** * Requests the cancellation of the lease on the <code>ServiceRegistration</code> that is * referenced in the <code>proxyReg</code> data structure. */ @Override protected void internalRun() { log(Level.FINEST, "JoinManager --> DiscardProxyTask started"); if (proxyReg != null) { try { proxyReg.registeredLatch.await(10, TimeUnit.SECONDS); } catch (InterruptedException ie) { //ignore } if (proxyReg.serviceLease != null) { try { proxyReg.serviceLease.cancel(); } catch (Exception e) { /*ignore*/ } } }//endif log(Level.FINEST, "JoinManager - DiscardProxyTask completed"); }//end run
/** * Create a ClientLeaseMapWrapper object that will hold * the specified client Lease. * @param wrapper a wrapper for the lease that wants to be renewed * @param duration the duration to associate with wrapper * @throws IllegalArgumentException if wrapper is deformed */ ClientLeaseMapWrapper(ClientLeaseWrapper wrapper, long duration) { final Lease clientLease = wrapper.getClientLease(); if (clientLease == null) { throw new IllegalArgumentException("Wrapper cannot be deformed"); } LeaseMap leaseMap = clientLease.createLeaseMap(duration); if (clientLease instanceof RemoteMethodControl && leaseMap instanceof RemoteMethodControl) { leaseMap = (LeaseMap) ((RemoteMethodControl) leaseMap).setConstraints( ConstrainableProxyUtil.translateConstraints( ((RemoteMethodControl) clientLease).getConstraints(), leaseToLeaseMapMethods)); } clientLeaseMap = leaseMap; wrapperMap.put(clientLease, wrapper); example = wrapper; }
/** * 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. */ public boolean canBatch(Lease lease) { if (!(lease instanceof ClientLeaseWrapper)) return false; final ClientLeaseWrapper clw = (ClientLeaseWrapper) lease; if (set.isolateSets() && !set.equals(clw.set)) return false; if (isDeformed() || clw.isDeformed()) return false; Lease clientLease = getClientLease(); Lease otherClientLease = clw.getClientLease(); return sameConstraints(clientLease, otherClientLease) && clientLease.canBatch(otherClientLease); }
clientLease.renew(duration); } catch (LeaseDeniedException e) { failedRenewal(e);
public long getExpiration() { final Lease cl = getClientLease(); if (cl == null) { // $$$ Why is this synchronized? synchronized (this) { return clientLeaseExpiration; } } else { return cl.getExpiration(); } }
/** * Removes a given lease from the managed set, and cancels it. <p> Note that even if an * exception is thrown as a result of the cancel operation, the lease will still have been * removed from the set of leases managed by this class. Additionally, any exception thrown by * the <code>cancel</code> method of the lease object itself may also be thrown by this method. * * @param lease the lease to remove and cancel * @throws UnknownLeaseException if the lease passed to this method is not in the set of managed * leases * @throws RemoteException typically, this exception occurs when there is a communication * failure between the client and the server. When this exception * does occur, the lease may or may not have been successfully * cancelled, (but the lease is guaranteed to have been removed * from the managed set). * @see Lease#cancel * @see UnknownLeaseException */ public void cancel(Lease lease) throws UnknownLeaseException, RemoteException { remove(lease); lease.cancel(); }
/** * Called by the LeaseRenewalManager when it cannot renew a lease that it is managing, and the * lease's desired expiration time has not yet been reached. * * @param leaseManagerEvent Instance of LeaseRenewalEvent containing information about the lease * that the <code>LeaseRenewalManager</code> was unable to renew. **/ public void notify(LeaseRenewalEvent leaseManagerEvent) { if (_logger.isLoggable(Level.FINE)) { Throwable error = leaseManagerEvent.getException(); _logger.fine("LeaseRenewalManager cannot renew this lease <" + leaseManagerEvent.getLease().getExpiration() + ">" + (error != null ? " - " + error.toString() : "")); } }
/** * Removes a given lease from the managed set, and cancels it. * <p> * Note that even if an exception is thrown as a result of the * cancel operation, the lease will still have been removed from the * set of leases managed by this class. Additionally, any exception * thrown by the <code>cancel</code> method of the lease object * itself may also be thrown by this method. * * @param lease the lease to remove and cancel * @throws UnknownLeaseException if the lease passed to this method * is not in the set of managed leases * @throws RemoteException typically, this exception occurs when * there is a communication failure between the client and * the server. When this exception does occur, the lease may * or may not have been successfully cancelled, (but the * lease is guaranteed to have been removed from the managed * set). * @see Lease#cancel * @see UnknownLeaseException */ public void cancel(Lease lease) throws UnknownLeaseException, RemoteException { remove(lease); lease.cancel(); }