private Set<Reaction<T>> initCandidates(final Reaction<T> newReaction, final Context c) { if (c.equals(Context.GLOBAL)) { return hndlrs.keySet(); } final Set<Reaction<T>> list = new LinkedHashSet<>(); addNeighborhoodReactions(list, newReaction); if (c.equals(Context.LOCAL)) { addLocalReactions(list, newReaction); } else { addExtendedNeighborhoodReactions(list, newReaction); } return list; }
private boolean mayInfluence(final Reaction<T> source, final Reaction<T> target) { final Context in = target.getInputContext(); final Context out = source.getOutputContext(); if (// Same node target.getNode().equals(source.getNode()) // If reaction writes something globally || out.equals(Context.GLOBAL) // If reaction reads something globally || in.equals(Context.GLOBAL)) { return true; } return influenceNeighborCheck(env, source, target, in, out); }
private void updateNeighborhood(final Node<T> n) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.NEIGHBORHOOD)) { updateReaction(handlers.get(r)); } } }
private void updateDependenciesForOperationOnNode(final Neighborhood<T> oldNeighborhood) { /* * A reaction in the neighborhood may have changed due to the content of * this new node. Must check. */ for (final Node<T> n : oldNeighborhood) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.NEIGHBORHOOD)) { updateReaction(handlers.get(r)); } } } /* * It is possible that some global reaction is changed due to the * creation of a new node. Checking. */ for (final Node<T> n : env) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.GLOBAL)) { updateReaction(handlers.get(r)); } } } }
/** * This method checks if there may be a dependency considering the * neighborhoods */ private static <T> boolean influenceNeighborCheck(final Environment<T> env, final Reaction<T> source, final Reaction<T> target, final Context in, final Context out) { final Neighborhood<T> sn = env.getNeighborhood(source.getNode()); final boolean scn = in.equals(Context.NEIGHBORHOOD); // If source reads from neighborhood and target is within if (scn && sn.contains(target.getNode())) { return true; } // If target writes in neighborhood and source is within final Neighborhood<T> tn = env.getNeighborhood(target.getNode()); final boolean tcn = out.equals(Context.NEIGHBORHOOD); if (tcn && tn.contains(source.getNode())) { return true; } // If source writes on the neighborhood, target reads on its // neighborhood and there is at least one common node return scn && tcn && commonNeighbor(env, sn, target.getNode()); }