示例#1
0
 @Override
 public void run() {
   StringBuilder sb = new StringBuilder("\nWaveformStartTask run:");
   try {
     waveformProviders = new WaveformModuleProvider[systems.length];
     waveformObjects = new DOFObject[systems.length];
     for (int i = 0; i < systems.length; i++) {
       SystemConfig systemConfig = nodeConfig.getSystemConfig(fdn, systems[i]);
       if (systemConfig == null)
         log.error("Invalid ccsc fdn: " + fdn + " and/or system name: " + systems[i]);
       else {
         DOFSystem system = systemConfig.getSystem();
         String creds = systemConfig.credentials.toString();
         waveformProviders[i] = new WaveformModuleProvider(serviceOids[i], creds);
         waveformObjects[i] = system.createObject(DOFObjectID.create(serviceOids[i]));
         waveformProviders[i].beginProvider(waveformObjects[i]);
       }
     }
     statusTracker.setStatus(moduleName, Status.Ok);
     node.setModuleStatus(WaveformModule.this, ModuleStatus.Started);
     log.debug(sb.toString());
   } catch (Exception e) {
     log.debug(sb.toString());
     log.error("\n" + getClass().getName() + " failed to start", e);
     node.setModuleStatus(WaveformModule.this, ModuleStatus.Failed);
   }
 }
  @Override
  public void interfaceRemoved(Query operation, DOFObjectID objectID, DOFInterfaceID interfaceID) {
    if (!objectID.equals(providerId) || !interfaceID.equals(HubRequestInterface.IID)) return;
    log.trace("Hub Request Provider Removed {}:{}", objectID, interfaceID);

    //        requestProvided.set(false);
    GracePeriodExpiredTask gracePeriodExpiredTask = new GracePeriodExpiredTask(this);
    synchronized (this) {
      if (gracePeriodFuture != null) {
        gracePeriodFuture.cancel(true);
        gracePeriodFuture = null;
      }
      gracePeriodExpiredFuture =
          hubProvideFactory.timerExecutor.schedule(
              gracePeriodExpiredTask, requestorGracePeriodMinutes.get(), TimeUnit.MINUTES);
      if (provider != null) provider.requestProvideStopped(-1);
    }
  }
示例#3
0
  /* *************************************************************************
   * Module implementation
   **************************************************************************/
  @Override
  public void init(Configuration config) throws Exception {
    String msg = "ok";
    try {
      nodeConfig = (NodeConfig) config;
      nodeConfig.tabLevel.set(3);
      nodeConfig.sb.append("\n");
      nodeConfig.toSb(getClass().getName(), " init:");
      nodeConfig.tabLevel.incrementAndGet();

      List<Entry<String, String>> list =
          NodeConfiguration.getPropertiesForBaseKey(PropertyFileNameKey, nodeConfig.properties);
      Entry<String, String> entry = list.get(index);
      String value = entry.getValue();
      nodeConfig.toSb(entry.getKey(), "=", value);
      NodeConfiguration.loadProperties(nodeConfig, value);

      fdn = nodeConfig.properties.getProperty(NodeConfiguration.FdnKey);
      nodeConfig.toSb(NodeConfiguration.FdnKey, "=", fdn);

      String systemNames = nodeConfig.properties.getProperty(SystemNameKey);
      nodeConfig.toSb(SystemNameKey, "=", systemNames);
      systems = systemNames.split(" ");

      String services = nodeConfig.properties.getProperty(ServiceIdKey);
      nodeConfig.toSb(ServiceIdKey, "=", services);
      String[] serviceIds = services.split(" ");
      serviceOids = new DOFObjectID[serviceIds.length];
      int i = 0;
      for (String sid : serviceIds) {
        msg = "invalid service oid: " + sid;
        serviceOids[i++] = DOFObjectID.create(sid);
      }

      nodeConfig.properties.remove(PropertyFileNameKey);
      nodeConfig.properties.remove(ServiceIdKey);
      nodeConfig.properties.remove(SystemNameKey);
      nodeConfig.properties.remove(NodeConfiguration.FdnKey);
    } catch (Exception e) {
      nodeConfig.toSb(msg);
      log.error(nodeConfig.sb.toString(), e);
      throw e;
    }
  }
 /**
  * ************************************************************************
  * DOFSystem.QueryOperationListener implementation
  * ************************************************************************
  */
 @Override
 public void interfaceAdded(Query operation, DOFObjectID objectId, DOFInterfaceID interfaceId) {
   if (!objectId.equals(providerId) || !interfaceId.equals(HubRequestInterface.IID)) return;
   //        if (gracePeriodExpired.get())
   //            return;
   //        requestProvided.set(true);
   log.trace("Hub Request Provider Added {}:{}", objectId, interfaceId);
   synchronized (this) {
     if (gracePeriodExpiredFuture != null) {
       gracePeriodExpiredFuture.cancel(true);
       gracePeriodExpiredFuture = null;
       provider.requestProvideStarted();
     }
     if (provider != null) return; // existing state is fine, we are done here.
     // first time, or first time after a hubProvideFactory.remove(monitor)
     gracePeriodFuture =
         hubProvideFactory.executor.submit(new GetGracePeriodTask(this, objectId, interfaceId));
   }
 }
  void getSystemAndStartQuery() {
    try {
      Authentication groupId = DOFObjectID.Authentication.create(providerId.getBase());
      DOFObjectID.Attribute attr = providerId.getAttribute(DOFObjectID.Attribute.GROUP);
      Domain domainId = DOFObjectID.Domain.create(attr.getValueObjectID());
      DOFCredentials domainCredentials =
          DOFCredentials.create(hubProvideFactory.coreCredentials, domainId);
      //
      // @formatter:off
      DOFSystem.Config domainSystemConfig =
          new DOFSystem.Config.Builder()
              .setName(groupId.getDataString() + "." + domainId.getDataString() + "-DOFSystem")
              .setCredentials(domainCredentials)
              .setPermissionsExtendAllowed(true)
              .setTunnelDomains(true)
              .build();
      // @formatter:on

      DOFDomain.Config domainConfig = new DOFDomain.Config.Builder(domainCredentials).build();
      DOFDomain serviceDomain = hubProvideFactory.dof.createDomain(domainConfig);
      serviceDomain.addStateListener(this);
      long t0 = System.currentTimeMillis();
      long to = hubProvideFactory.commTimeout;
      synchronized (domainFound) {
        while (!domainFound.get()) {
          try {
            domainFound.wait(to);
            if (domainFound.get()) break;
            long delta = System.currentTimeMillis() - t0;
            if (delta >= hubProvideFactory.commTimeout)
              throw new TimeoutException(
                  "timed out: " + to + " waiting for Domain listener to report completed");
            to =
                hubProvideFactory.commTimeout
                    - delta; // spurious wakeup, or wait(to) slightly off System.currentTimeMillis
          } finally {
            serviceDomain.removeStateListener(this);
          }
        }
      }
      DOFSystem system =
          hubProvideFactory.dof.createSystem(domainSystemConfig, hubProvideFactory.commTimeout);
      systemData = new CreateSystemTask.SystemData(groupId, domainId, domainCredentials, system);
    } catch (InterruptedException e) {
      hubProvideFactory.removeHubRequestMonitor(providerId);
      log.debug("Create system task interrupted.");
      return;
    } catch (Exception e) {
      hubProvideFactory.removeHubRequestMonitor(providerId);
      log.debug("Create system failed {} - " + e.getCause(), providerId);
      return;
    }

    synchronized (this) {
      if (activateInterestOperation == null || activateInterestOperation.isComplete())
        activateInterestOperation =
            systemData.system.beginInterest(
                systemData.groupId,
                HubRequestInterface.IID,
                DOFInterestLevel.ACTIVATE,
                DOF.TIMEOUT_NEVER,
                null,
                null);

      if (queryOperation == null || queryOperation.isComplete()) {
        DOFQuery query =
            new DOFQuery.Builder()
                .addFilter(providerId)
                .addRestriction(HubRequestInterface.IID)
                .build();
        queryOperation = systemData.system.beginQuery(query, DOF.TIMEOUT_NEVER, this, null);
      }
      createSystemFuture = null;
      log.debug(
          "HubManager dof: "
              + hubProvideFactory.dof.getState().getName()
              + " beginQuery for: "
              + providerId.toStandardString()
              + ":"
              + HubRequestInterface.IID);
    }
  }