Esempio n. 1
0
 ProvisionLeaseManager(Lease lease, ProvisionManager provisioner, ServiceID serviceID) {
   super("ProvisionLeaseManager");
   this.lease = lease;
   leaseTime = lease.getExpiration() - System.currentTimeMillis();
   if (logger.isLoggable(Level.FINEST))
     logger.log(
         Level.FINEST,
         "ProvisionMonitor Lease expiration : "
             + "["
             + lease.getExpiration()
             + "]  millis, "
             + "["
             + (lease.getExpiration() / 1000)
             + "] seconds, "
             + "duration : ["
             + leaseTime
             + "] millis, "
             + "["
             + (leaseTime / 1000)
             + "], secs");
   this.provisioner = provisioner;
   this.serviceID = serviceID;
   setDaemon(true);
   start();
 }
Esempio n. 2
0
 /**
  * Attempt to reconnect to the ProvisionMonitor
  *
  * @return True if reconnected, false if not
  */
 boolean reconnect() {
   if (!keepAlive) return (false);
   this.lease = connect(provisioner);
   boolean connected = (lease != null);
   /* If we're not connected, set keepAlive flag to false */
   if (!connected) keepAlive = false;
   else this.leaseTime = lease.getExpiration() - System.currentTimeMillis();
   return (connected);
 }
Esempio n. 3
0
  /**
   * Attempt to connect to the ProvisionMonitor
   *
   * @param provisioner The provision monitor to connect to
   * @return The Lease the ProvisionMonitor has returned, or null if a valid Lease could not be
   *     obtained
   */
  synchronized Lease connect(ProvisionManager provisioner) {
    boolean connected = false;
    Lease lease = null;
    for (int i = 1; i <= provisionerRetryCount; i++) {
      try {
        EventRegistration er =
            provisioner.register(
                adapter.getInstantiator(),
                null,
                adapter.getResourceCapability(),
                getServiceDeployments(),
                serviceLimit,
                provisionerLeaseDuration);
        lease = (Lease) provisionerPreparer.prepareProxy(er.getLease());
        long leaseTime = lease.getExpiration() - System.currentTimeMillis();
        if (leaseTime > 0) {
          if (logger.isLoggable(Level.FINE))
            logger.log(Level.FINE, "Established ProvisionManager registration");
          connected = true;
          break;
        } else {
          logger.log(
              Level.WARNING,
              "Invalid Lease time ["
                  + leaseTime
                  + "] returned from "
                  + "ProvisionManager, retry count ["
                  + i
                  + "]");
          try {
            lease.cancel();
          } catch (Exception e) {
            if (logger.isLoggable(Level.FINEST))
              logger.log(Level.FINEST, "Cancelling Lease with invalid lease time", e);
          }
          try {
            Thread.sleep(provisionerRetryDelay);
          } catch (InterruptedException ie) {
            /* should not happen */
          }
        }

      } catch (SecurityException e) {
        // cancelRegistration(provisioner);
        logger.log(Level.WARNING, "ProvisionManager security exception", e);
        break;
      } catch (Exception e) {
        Throwable cause = ThrowableUtil.getRootCause(e);
        logger.warning(
            "Recovering ProvisionManager Lease attempt "
                + "retry count ["
                + i
                + "] "
                + cause.getClass().getName()
                + ": "
                + cause.getMessage());
        /* Determine if we should even try to reconnect */
        final int category = ThrowableConstants.retryable(e);
        if (category == ThrowableConstants.INDEFINITE
            || category == ThrowableConstants.UNCATEGORIZED) {
          try {
            Thread.sleep(provisionerRetryDelay);
          } catch (InterruptedException ie) {
            /* should not happen */
          }
        }
      }
    }
    /* If we're not connected, set lease to null and return */
    if (!connected) lease = null;
    return (lease);
  }