public static List<IndexCreator> sort(List<? extends IndexCreator> creators)
      throws IllegalArgumentException {
    try {
      final HashMap<String, IndexCreator> creatorsById =
          new HashMap<String, IndexCreator>(creators.size());

      DAG dag = new DAG();

      for (IndexCreator creator : creators) {
        creatorsById.put(creator.getId(), creator);

        dag.addVertex(creator.getId());

        for (String depId : creator.getCreatorDependencies()) {
          dag.addEdge(creator.getId(), depId);
        }
      }

      List<String> sortedIds = TopologicalSorter.sort(dag);

      final ArrayList<IndexCreator> sortedCreators = new ArrayList<IndexCreator>(creators.size());

      for (String id : sortedIds) {
        final IndexCreator creator = creatorsById.get(id);

        if (creator != null) {
          sortedCreators.add(creator);
        } else {
          throw new IllegalArgumentException(
              String.format(
                  "IndexCreator with ID=\"%s\" does not exists, the present creator ID=\"%s\" depends on it!",
                  id, dag.getParentLabels(id)));
        }
      }

      return sortedCreators;
    } catch (CycleDetectedException e) {
      throw new IllegalArgumentException("Supplied IndexCreator inter-dependencies", e);
    }
  }
Пример #2
0
  /**
   * Determine the Flow (PAR or SEQ) for exertions that have the Flow set to AUTO
   *
   * @param topXrt
   * @param sortedSubXrt
   * @return
   */
  private Strategy.Flow setFlow(Exertion topXrt, List<Mogram> sortedSubXrt) {
    List<String> sortedSubsetIds = addSubExertions(sortedSubXrt);

    int edges = 0;
    for (Mogram xrt : topXrt.getMograms()) {
      for (String depId : dag.getParentLabels(xrt.getId().toString())) {
        if (sortedSubsetIds.contains(depId)) {
          edges++;
          logger.debug("Edge: " + xrt.getName() + " parent: " + depId);
        }
      }
      for (String depId : dag.getChildLabels(xrt.getId().toString())) {
        if (sortedSubsetIds.contains(depId)) {
          edges++;
          logger.debug("Edge: " + xrt.getName() + " child: " + depId);
        }
      }
    }
    if (topXrt.getMograms().size() > 0)
      logger.debug("XRT " + topXrt.getName() + " has edges: " + edges);
    if (edges == 0) return Strategy.Flow.PAR;
    else return Strategy.Flow.SEQ;
  }