コード例 #1
0
  private void dfs(Queue<Map<String, String>> queue, AtomicBoolean flag, PossibleState state)
      throws IOException {
    if (flag.get()) {
      return;
    }

    TransitionTarget nextState = state.nextState;

    // reached end of chart, valid assignment found
    if (nextState.getId().equalsIgnoreCase("end")) {
      queue.add(state.variables);

      if (queue.size() > 10000) {
        log.info("Queue size " + queue.size() + ", waiting");
        try {
          Thread.sleep(500);
        } catch (InterruptedException ex) {
          log.info("Interrupted ", ex);
        }
      }

      return;
    }

    // run every action in series
    List<Map<String, String>> product = new LinkedList<>();
    product.add(new HashMap<>(state.variables));

    OnEntry entry = nextState.getOnEntry();
    List<Action> actions = entry.getActions();

    for (Action action : actions) {
      for (CustomTagExtension tagExtension : tagExtensionList) {
        if (tagExtension.getTagActionClass().isInstance(action)) {
          product = tagExtension.pipelinePossibleStates(action, product);
        }
      }
    }

    // go through every transition and see which of the products are valid, recursive searching on
    // them
    List<Transition> transitions = nextState.getTransitionsList();

    for (Transition transition : transitions) {
      String condition = transition.getCond();
      TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0);

      for (Map<String, String> p : product) {
        Boolean pass;

        if (condition == null) {
          pass = true;
        } else {
          // scrub the context clean so we may use it to evaluate transition conditional
          Context context = this.getRootContext();
          context.reset();

          // set up new context
          for (Map.Entry<String, String> e : p.entrySet()) {
            context.set(e.getKey(), e.getValue());
          }

          // evaluate condition
          try {
            pass = (Boolean) this.getEvaluator().eval(context, condition);
          } catch (SCXMLExpressionException ex) {
            pass = false;
          }
        }

        // transition condition satisfied, continue search recursively
        if (pass) {
          PossibleState result = new PossibleState(target, p);
          dfs(queue, flag, result);
        }
      }
    }
  }
コード例 #2
0
  private DataPipe dfs(
      SingleThreadedProcessing singleThreadedProcessing, AtomicBoolean flag, PossibleState state)
      throws IOException {

    /*if (flag.get()) {     // Updates and comments by Shraddha Patel
        return;
    }*/

    TransitionTarget nextState = state.nextState;

    // run every action in series
    List<Map<String, String>> product = new LinkedList<>();
    product.add(new HashMap<String, String>(state.variables));

    OnEntry entry = nextState.getOnEntry();
    List<Action> actions = entry.getActions();

    for (Action action : actions) {
      for (CustomTagExtension tagExtension : tagExtensionList) {
        if (tagExtension.getTagActionClass().isInstance(action)) {
          product = tagExtension.pipelinePossibleStates(action, product);
        }
      }
    }

    // go through every transition and see which of the products are valid, recursive searching on
    // them
    List<Transition> transitions = nextState.getTransitionsList();

    for (Transition transition : transitions) {
      String condition = transition.getCond();
      TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0);

      for (Map<String, String> p : product) {
        Boolean pass;

        if (condition == null) {
          pass = true;
        } else {
          // scrub the context clean so we may use it to evaluate transition conditional
          Context context = this.getRootContext();
          context.reset();

          // set up new context
          for (Map.Entry<String, String> e : p.entrySet()) {
            context.set(e.getKey(), e.getValue());
          }

          // evaluate condition
          try {
            pass = (Boolean) this.getEvaluator().eval(context, condition);
          } catch (SCXMLExpressionException ex) {
            pass = false;
          }
        }

        // transition condition satisfied, continue search recursively
        if (pass) {
          PossibleState result = new PossibleState(target, p);
          dfs(singleThreadedProcessing, flag, result);
        }
      }
    }

    if (nextState.getId().equalsIgnoreCase("end")) {

      System.out.println("State Variables: " + state.variables);

      dataPipe =
          singleThreadedProcessing.processOutput(state.variables, flag); // Commented this line
    }
    return dataPipe;
  }