Esempio n. 1
0
 void drop(boolean removed) {
   if (!removed) {
     try {
       lease.cancel();
     } catch (AccessControlException e) {
       logger.log(
           Level.WARNING, "Permissions porblen dropping lease", ThrowableUtil.getRootCause(e));
     } catch (Exception e) {
       if (logger.isLoggable(Level.FINER))
         logger.finer("ProvisionLeaseManager: could not " + "drop lease, already cancelled");
     }
   }
   lease = null;
   keepAlive = false;
   interrupt();
 }
Esempio n. 2
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);
  }