Exemplo n.º 1
0
  // Vehicle controller
  @Override
  public void setRouteIndex(ResourceUser user, int index) {
    Objects.requireNonNull(user, "user is null");
    if (index < 0) {
      throw new IllegalArgumentException("index < 0: " + index);
    }

    // Update deadlock predictor.
    if (routesByUser.containsKey(user)) {
      Route route = routesByUser.get(user);
      List<Step> steps = route.getSteps();
      List<Step> remainingClaimRoute = steps.subList(index + 1, steps.size());
      List<Set<TCSResource<?>>> remainingClaimResourceSequence = new ArrayList<>();
      Set<TCSResource<?>> stepSet;
      for (Step step : remainingClaimRoute) {
        stepSet = new HashSet<>();
        stepSet.add(step.getDestinationPoint());
        stepSet.add(step.getPath());
        remainingClaimResourceSequence.add(stepSet);
      }
      Set<TCSResource<?>> allocatedResources = allocatedResources(user);
      deadlockPredictor.configureSystemData(
          user, allocatedResources, remainingClaimResourceSequence);
    }
  }
Exemplo n.º 2
0
  // Dispatcher
  @Override
  public void setRoute(ResourceUser user, Route route) {
    Objects.requireNonNull(user, "user is null");
    Objects.requireNonNull(route, "route is null");

    // Update deadlock predictor.
    List<Step> steps = route.getSteps();
    List<Set<TCSResource<?>>> resourceSequence = new ArrayList<>();
    for (Step step : steps) {
      Set<TCSResource<?>> stepSet = new HashSet<>();
      stepSet.add(step.getDestinationPoint());
      stepSet.add(step.getPath());
      resourceSequence.add(stepSet);
    }
    deadlockPredictor.setRoute(user, resourceSequence);
    routesByUser.put(user, route);
    Set<TCSResource<?>> allocatedResources = allocatedResources(user);
    deadlockPredictor.configureSystemData(user, allocatedResources, resourceSequence);
  }