예제 #1
0
  /**
   * Construct a ServiceConsumer
   *
   * @param adapter The CybernodeAdapter
   * @param serviceLimit The maximum number of services the Cybernode has been configured to
   *     instantiate
   * @param config The Configuration object used to obtain operational values
   * @throws ConfigurationException if errors occur accessing the configuration
   */
  ServiceConsumer(CybernodeAdapter adapter, int serviceLimit, Configuration config)
      throws ConfigurationException {
    if (adapter == null) throw new NullPointerException("CybernodeAdapter is null");
    if (config == null) throw new NullPointerException("config is null");
    this.adapter = adapter;
    this.config = config;
    /* Establish the lease duration */
    long ONE_MINUTE = 1000 * 60;
    long DEFAULT_LEASE_TIME = ONE_MINUTE * 30; /* 30 minutes */
    long MIN_LEASE_TIME = 10 * 1000; /* 10 seconds */
    provisionerLeaseDuration =
        Config.getLongEntry(
            config,
            CybernodeImpl.CONFIG_COMPONENT,
            "provisionerLeaseDuration",
            DEFAULT_LEASE_TIME,
            MIN_LEASE_TIME,
            Long.MAX_VALUE);
    /* Get the retry count if we disconnect from a provisioner */
    int DEFAULT_RETRY_COUNT = 3;
    int MIN_RETRY_COUNT = 0;
    provisionerRetryCount =
        Config.getIntEntry(
            config,
            CybernodeImpl.CONFIG_COMPONENT,
            "provisionerRetryCount",
            DEFAULT_RETRY_COUNT,
            MIN_RETRY_COUNT,
            Integer.MAX_VALUE);
    /* Get the amount of time to wait between retries */
    long DEFAULT_RETRY_DELAY = 1000; /* 1 second */
    long MIN_RETRY_DELAY = 0;
    provisionerRetryDelay =
        Config.getLongEntry(
            config,
            CybernodeImpl.CONFIG_COMPONENT,
            "provisionerRetryDelay",
            DEFAULT_RETRY_DELAY,
            MIN_RETRY_DELAY,
            Long.MAX_VALUE);
    if (logger.isLoggable(Level.FINEST))
      logger.log(
          Level.FINEST,
          "LeaseDuration={0}, RetryCount={1}, RetryDelay={2}",
          new Object[] {provisionerLeaseDuration, provisionerRetryCount, provisionerRetryDelay});

    /* Get the ProxyPreparer for discovered ProvisionMonitor instances */
    provisionerPreparer =
        (ProxyPreparer)
            config.getEntry(
                CybernodeImpl.CONFIG_COMPONENT,
                "provisionerPreparer",
                ProxyPreparer.class,
                new BasicProxyPreparer());
    if (logger.isLoggable(Level.FINEST))
      logger.log(Level.FINEST, "ProxyPreparer={0}", provisionerPreparer);
    leaseTable = new Hashtable<Object, ProvisionLeaseManager>();
    this.serviceLimit = serviceLimit;
    computeResourceObserver = new ComputeResourceObserver(adapter.getComputeResource());
  }
예제 #2
0
 /** Destroy the ServiceConsumer */
 void destroy() {
   try {
     adapter.getComputeResource().deleteObserver(computeResourceObserver);
     lCache.removeListener(this);
     cancelRegistrations();
     synchronized (provisioners) {
       provisioners.clear();
     }
   } finally {
     destroyed = true;
   }
 }