Exemplo n.º 1
0
  private void printServerNode(int level, String serverName) {
    printlnAtLevel(level, "[Printing list for Server = " + serverName + "]");
    String pattern = serverName + "/...";
    if (level == 0) pattern = "/" + pattern;
    printlnAtLevel(level, "[Pattern = " + pattern + "]");
    ChannelTree tr = getChannelTree(pattern);

    if (tr == null) {
      printlnAtLevel(level, "[no tree]");
      return;
    }
    Iterator i = tr.rootIterator();
    if (!i.hasNext()) {
      printlnAtLevel(level, "[empty root list]");
      return;
    }

    // the first node should be for the requested serverName
    ChannelTree.Node node = (ChannelTree.Node) i.next();
    if (!node.getType().toString().equals("Server")) {
      printlnAtLevel(level, "[unexpected non-Server node type = " + node.getType() + "]");
      return;
    }

    if (!node.getName().equals(serverName)) {
      printlnAtLevel(level, "[unexpected node name = " + node.getName() + "]");
      return;
    }

    printlnAtLevel(
        level, node.getName() + " -- " + node.getFullName() + " (" + node.getType() + ")");

    printChildren(level + 1, node);
  }
Exemplo n.º 2
0
  private void exec() {
    connect();
    ChannelTree t = getChannelTree("/...");
    Iterator i = t.rootIterator();
    int level = 0;
    if (!i.hasNext()) {
      printlnAtLevel(level, "[empty root list]");
    }

    // the first node should be for the requested serverName
    ChannelTree.Node node = (ChannelTree.Node) i.next();
    if (!node.getType().toString().equals("Server")) {
      printlnAtLevel(level, "[unexpected non-Server node type = " + node.getType() + "]");
      return;
    }

    String serverName = node.getName();

    printServerNode(level, serverName);
  }
  private void setupChannelList() {
    channelPathList = new Vector();

    if ((channelPathPattern != null) && !channelPathPattern.equals(""))
      appendChannelListFromPattern();
    if ((channelPathListString != null) && !channelPathListString.equals(""))
      appendChannelListFromString();

    Iterator channels = channelPathList.iterator();
    if (!channels.hasNext()) {
      System.out.println("DataVideoGather: No data channels to monitor.");
      this.printUsage();
      System.exit(0);
    }

    channelPathArray = new String[channelPathList.size()];
    shortNameArray = new String[channelPathList.size()];
    for (int i = 0; i < channelPathArray.length; i++) {
      ChannelTree.Node candidate = (ChannelTree.Node) channels.next();
      channelPathArray[i] = candidate.getFullName();
      shortNameArray[i] = candidate.getName();
    }
  }
  public void appendChannelListFromPattern() {
    try {
      // Create a sink and connect:
      Sink sink = new Sink();
      sink.OpenRBNBConnection(getServer(), sinkName);

      // get all the channel paths that match the pattern
      ChannelMap sMap = new ChannelMap();
      sink.RequestRegistration();
      sMap = sink.Fetch(-1, sMap);
      ChannelTree tree = ChannelTree.createFromChannelMap(sMap);

      Pattern p = Pattern.compile(channelPathPattern);
      // for each channel path, check match, collect matches...

      Iterator nodes = tree.iterator();
      while (nodes.hasNext()) {
        ChannelTree.Node n = (ChannelTree.Node) nodes.next();
        // System.out.println("Checking " + n.getFullName() + ";" + n.getName());
        if (!includeHidden && n.getFullName().startsWith("_")) continue;
        if (n.getType() != ChannelTree.CHANNEL) continue;
        String name = n.getFullName();
        Matcher m = p.matcher(name);
        if (m.matches()) {
          //					System.out.println("Matches");
          boolean isSource = false;
          ChannelTree.Node upNode = n.getParent();
          while ((!isSource) || (upNode != null)) {
            if (upNode.getType() == ChannelTree.SOURCE) isSource = true;
            upNode = upNode.getParent();
          }
          if (isSource) {
            // System.out.println("... and is a source.");
            channelPathList.add(n);
          } else {
            // System.out.println("... and is NOT a source.");
          }
        }
      }

    } catch (SAPIException se) {
      se.printStackTrace();
    }
  } // appendChannelListFromPattern
  public void appendChannelListFromString() {
    try {
      StringTokenizer st = new StringTokenizer(channelPathListString, ",");

      // Create a sink and connect:
      Sink sink = new Sink();
      sink.OpenRBNBConnection(getServer(), sinkName);

      // get all the channel paths that match the pattern
      ChannelMap sMap = new ChannelMap();
      sink.RequestRegistration();
      sMap = sink.Fetch(-1, sMap);
      ChannelTree tree = ChannelTree.createFromChannelMap(sMap);

      Pattern p = Pattern.compile(channelPathPattern);
      // for each channel path, check match, collect matches...

      while (st.hasMoreTokens()) {
        String path = st.nextToken();
        //				System.out.println("Checking " + path);

        ChannelTree.Node n = tree.findNode(path);
        if (n == null) continue;
        if (n.getType() != ChannelTree.CHANNEL) continue;
        String name = n.getFullName();
        //				System.out.println("Found it...");
        boolean isSource = false;
        ChannelTree.Node upNode = n.getParent();
        while ((!isSource) || (upNode != null)) {
          if (upNode.getType() == ChannelTree.SOURCE) isSource = true;
          upNode = upNode.getParent();
        }
        if (isSource) {
          //					System.out.println("... and is a source.");
          channelPathList.add(n);
        } else {
          //					System.out.println("... and is NOT a source.");
        }
      } // while next token
    } catch (SAPIException se) {
      se.printStackTrace();
    }
  } // appendChannelListFromString
Exemplo n.º 6
0
  private void printChildren(int level, ChannelTree.Node node) {
    // iterate through children of hirarchy
    List l = node.getChildren();
    Iterator i = l.iterator();

    while (i.hasNext()) {
      node = (ChannelTree.Node) i.next();

      printlnAtLevel(
          level, node.getName() + " -- " + node.getFullName() + " (" + node.getType() + ")");

      if (node.getType().toString().equals("Server")) printServerNode(level + 1, node.getName());
      else {
        printChildren(level + 1, node);
      }
    }
  }
Exemplo n.º 7
0
  /**
   * Get the metadata channel tree for the given <code>path</code>. This will populate the channel
   * map with channel objects derived from the metadata. This will recursively make requests for
   * child servers and plugins up to the maximum request depth of {@value #MAX_REQUEST_DEPTH}.
   *
   * @param sink sink the sink connection to the RBNB server
   * @param path the path for the desired metadata
   * @param channels the map to populate with channel objects
   * @param depth the depth of the request
   * @return the metadata channel tree for the given path
   * @throws SAPIException if a server error occurs
   * @see #MAX_REQUEST_DEPTH
   */
  private ChannelTree getChannelTree(
      Sink sink, String path, Map<String, Channel> channels, int depth) throws SAPIException {
    depth++;

    ChannelTree ctree = ChannelTree.EMPTY_TREE;

    ChannelMap markerChannelMap = new ChannelMap();

    ChannelMap cmap = new ChannelMap();

    if (path == null) {
      path = "";
      cmap.Add("...");
    } else {
      cmap.Add(path + "/...");
    }

    sink.RequestRegistration(cmap);

    cmap = sink.Fetch(FETCH_TIMEOUT, cmap);

    if (cmap.GetIfFetchTimedOut()) {
      log.error("Failed to get metadata.  Fetch timed out.");
      return ctree;
    }

    ctree = ChannelTree.createFromChannelMap(cmap);

    // store user metadata in channel objects
    String[] channelList = cmap.GetChannelList();
    for (int i = 0; i < channelList.length; i++) {
      int channelIndex = cmap.GetIndex(channelList[i]);
      if (channelIndex != -1) {
        ChannelTree.Node node = ctree.findNode(channelList[i]);
        String userMetadata = cmap.GetUserInfo(channelIndex);
        Channel channel = new RBNBChannel(node, userMetadata);
        channels.put(channelList[i], channel);

        // look for marker channels
        String mimeType = channel.getMetadata("mime");
        if (mimeType != null && mimeType.compareToIgnoreCase(EventMarker.MIME_TYPE) == 0) {
          markerChannelMap.Add(node.getFullName());
        }
      }
    }

    Iterator<?> it = ctree.iterator();
    while (it.hasNext()) {
      ChannelTree.Node node = (ChannelTree.Node) it.next();
      NodeTypeEnum type = node.getType();

      // look for child servers or plugins and get their channels
      if ((type == ChannelTree.SERVER || type == ChannelTree.PLUGIN)
          && !path.startsWith(node.getFullName())
          && depth < MAX_REQUEST_DEPTH) {
        ChannelTree childChannelTree = getChannelTree(sink, node.getFullName(), channels, depth);
        ctree = childChannelTree.merge(ctree);
      }
    }

    if (markerChannelMap.NumberOfChannels() > 0) {
      double markersDuration = System.currentTimeMillis() / 1000d;

      // request from start of marker channels to now
      sink.Request(markerChannelMap, 0, markersDuration, "absolute");

      markerChannelMap = sink.Fetch(FETCH_TIMEOUT, markerChannelMap);
      if (!markerChannelMap.GetIfFetchTimedOut()) {
        // notify marker listeners
        fireMarkersUpdated(markerChannelMap);
      } else {
        log.error("Failed to get event markers. Fetched timed out.");
      }
    }

    return ctree;
  }