コード例 #1
0
  /**
   * Breadth first traversal of the topology DAG
   *
   * @param topologies
   * @param td
   * @param spouts
   * @return A partial ordering of components
   */
  private Queue<Component> bfs(Topologies topologies, TopologyDetails td, List<Component> spouts) {
    // Since queue is a interface
    Queue<Component> ordered__Component_list = new LinkedList<Component>();
    HashMap<String, Component> visited = new HashMap<String, Component>();

    /* start from each spout that is not visited, each does a breadth-first traverse */
    for (Component spout : spouts) {
      if (!visited.containsKey(spout.id)) {
        Queue<Component> queue = new LinkedList<Component>();
        queue.offer(spout);
        while (!queue.isEmpty()) {
          Component comp = queue.poll();
          visited.put(comp.id, comp);
          ordered__Component_list.add(comp);
          List<String> neighbors = new ArrayList<String>();
          neighbors.addAll(comp.children);
          neighbors.addAll(comp.parents);
          for (String nbID : neighbors) {
            if (!visited.containsKey(nbID)) {
              Component child = topologies.getAllComponents().get(td.getId()).get(nbID);
              queue.offer(child);
            }
          }
        }
      }
    }
    return ordered__Component_list;
  }
コード例 #2
0
 private List<Component> getSpouts(Topologies topologies, TopologyDetails td) {
   List<Component> spouts = new ArrayList<Component>();
   for (Component c : topologies.getAllComponents().get(td.getId()).values()) {
     if (c.type == Component.ComponentType.SPOUT) {
       spouts.add(c);
     }
   }
   return spouts;
 }