Exemplo n.º 1
0
  // Node DataScopes can be the first element in a path. They must
  // find or make the corresponding HostDS and return that as the
  // preferred parent.
  @Override
  protected ResourceContext preferredParent(RSS root) {

    ServiceBroker sb = (ServiceBroker) root.getProperty("ServiceBroker");
    AgentTopologyService ats = sb.getService(this, AgentTopologyService.class, null);
    String nodename = (String) getSymbolValue(NODENAME);
    String hostname = null;
    if (ats != null) {
      hostname = ats.getNodeHost(MessageAddress.getMessageAddress(nodename));
    } else {
      // AgentTopologyService not loaded. Try a direct WP
      // call, even though it can give an inconsistent picture.
      WhitePagesService svc = sb.getService(this, WhitePagesService.class, null);
      try {
        AddressEntry entry = svc.get(nodename, TOPOLOGY, -1);
        if (entry == null) {
          if (logger.isWarnEnabled()) {
            logger.warn("Can't find host for node " + nodename);
          }
        } else {
          hostname = entry.getURI().getHost();
        }
      } catch (Exception ex) {
        // log this?
      }
    }

    String[] params = {hostname == null ? UNKNOWN_HOST_IP : hostname};
    ResourceNode node = new ResourceNode();
    node.kind = "Host";
    node.parameters = params;
    ResourceNode[] path = {node};
    ResourceContext parent = root.getPathContext(path);
    setParent(parent);
    return parent;
  }
  /** Watch for new actions & changes in the actions. */
  public void execute() {

    Iterator iter;

    // ********* Check for the servlet being added ***********
    if (servlet == null) {
      iter = servletSubscription.getAddedCollection().iterator();
      if (iter.hasNext()) {
        servlet = (ActionMonitorServlet) iter.next();
        logger.debug("**** Saw new ActionMonitorServlet");
      }
    }

    // ********* Check for actions being added ***********
    iter = actionsSubscription.getAddedCollection().iterator();
    while (iter.hasNext()) {
      Action a = (Action) iter.next();
      if (servlet != null) {
        servlet.addAction(a);
      }

      // At least temp for testing -- next 7 lines
      String target = "noTargets";
      Iterator it = null;
      Collection c = a.getTargets();
      if (c != null) {
        it = a.getTargets().iterator();
        if (it != null && it.hasNext()) {
          MessageAddress ma = (MessageAddress) it.next();
          if (ma != null) target = ma.toString();
          else target = "null msgAddr";
        } else target = "noTarget";
      }
      logger.debug(
          "[AgentId="
              + agentId
              + "]**** Saw new Action["
              + ActionUtils.getAssetID(a)
              + "], with ActionRecord = "
              + a.getValue()
              + " UID="
              + a.getUID()
              + " src="
              + a.getSource()
              + ",tgt="
              + target);
    }

    // ********* Check for changes in our modes ************
    iter = actionsSubscription.getChangedCollection().iterator();
    while (iter.hasNext()) {
      Action a = (Action) iter.next();
      if (servlet != null) {
        servlet.changedAction(a);
      }
      logger.debug(
          "[AgentId="
              + agentId
              + "]**** Saw changed Action["
              + ActionUtils.getAssetID(a)
              + "], with ActionRecord = "
              + a.getValue()
              + " UID="
              + a.getUID());
    }

    // Emit # of action wrappers on BB
    int size = actionsSubscription.getCollection().size();
    logger.debug(
        "[AgentId=" + agentId + "]**** Total # of Action objects on BB right now = " + size);
  }