Ejemplo n.º 1
0
 @Override
 public void removeTrackedResources(Key intentKey, Collection<NetworkResource> resources) {
   for (NetworkResource resource : resources) {
     if (resource instanceof Link) {
       intentsByLink.remove(linkKey((Link) resource), intentKey);
     } else if (resource instanceof ElementId) {
       intentsByDevice.remove((ElementId) resource, intentKey);
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Removes a leaf node from the network. If this removal made the network degenerate, it will
   * return <code>true</code>.
   *
   * @param networkingNode Definition of the leaf node position and connecting sides.
   * @return <code>true</code> if the network after the removal is degenerated or empty (no longer
   *     valid).
   */
  public boolean removeLeafNode(NetworkNode networkingNode) {
    // Removal of a leaf node cannot split the network, so it's just safe to remove it
    // We just need to check, if after removal of the node, network becomes degenerated, if so - we
    // need
    // to signal that the network is no longer valid and should be removed.
    final boolean changed = leafNodes.remove(networkingNode.location, networkingNode);
    if (!changed)
      throw new IllegalStateException("Tried to remove a node that is not in the network");

    distanceCache.clear();

    return isDegeneratedNetwork() || isEmptyNetwork();
  }
Ejemplo n.º 3
0
  /**
   * For each node in the graph, we want to find the longest path from the node to the root. The
   * length of the longest path is the depth at which the node should be drawn in the visualization
   * of the graph.
   */
  @VisibleForTesting
  static SetMultimap<Integer, String> calculateModuleDepths(
      String root, Map<String, List<String>> graph) {

    // To determine the longest path for each node, progressively descend
    // down the inverted dependency tree. Keep track of each module found at
    // that depth and record the deepest point at which the module was seen.
    SetMultimap<Integer, String> modulesAtDepth = HashMultimap.create();
    modulesAtDepth.put(0, root);
    Map<String, Integer> moduleToDepth = Maps.newHashMap();
    moduleToDepth.put(root, 0);

    int depth = 0;
    while (true) {
      Set<String> modules = modulesAtDepth.get(depth);
      if (modules.isEmpty()) {
        break;
      }
      int newDepth = ++depth;

      // For each module at the current depth, collect of its descendants so
      // they can be inserted in modulesAtDepth at their new depth.
      Set<String> atNewDepth = Sets.newHashSet();
      for (String module : modules) {
        List<String> descendants = graph.get(module);
        for (String descendant : descendants) {
          atNewDepth.add(descendant);
        }
      }

      // A module in atNewDepth may already be in the modulesAtDepth multimap.
      // If so, then the key with which it is associated in the multimap must
      // be changed. The moduleToDepth map is used to keep track of where each
      // module is in the multimap for quick lookup, so moduleToDepth must be
      // kept up to date, as well.
      for (String module : atNewDepth) {
        if (moduleToDepth.containsKey(module)) {
          int oldDepth = moduleToDepth.remove(module);
          modulesAtDepth.remove(oldDepth, module);
        }
        moduleToDepth.put(module, newDepth);
        modulesAtDepth.put(newDepth, module);
      }
    }

    return modulesAtDepth;
  }
 public void add(ClassName className, Collection<ClassName> referencedClasses) {
   _classToReferencedClassesMap.putAll(className, referencedClasses);
   _classToReferencedClassesMap.remove(className, className);
 }
Ejemplo n.º 5
0
 public void removeNetworkingNode(NetworkNode networkNode) {
   if (!networkingNodes.remove(networkNode.location, networkNode))
     throw new IllegalStateException("Tried to remove a node that is not in the network");
   distanceCache.clear();
 }
Ejemplo n.º 6
0
  private synchronized void updateTaskInfo(TaskInfo newValue, List<TaskSource> sources) {
    if (newValue.getState().isDone()) {
      // splits can be huge so clear the list
      pendingSplits.clear();
      fireSplitCountChanged(-pendingSourceSplitCount);
      pendingSourceSplitCount = 0;
    }

    int oldPartitionedSplitCount = getPartitionedSplitCount();

    // change to new value if old value is not changed and new value has a newer version
    AtomicBoolean workerRestarted = new AtomicBoolean();
    boolean updated =
        taskInfo.setIf(
            newValue,
            oldValue -> {
              // did the worker restart
              if (oldValue.getNodeInstanceId().isPresent()
                  && !oldValue.getNodeInstanceId().equals(newValue.getNodeInstanceId())) {
                workerRestarted.set(true);
                return false;
              }

              if (oldValue.getState().isDone()) {
                // never update if the task has reached a terminal state
                return false;
              }
              if (newValue.getVersion() < oldValue.getVersion()) {
                // don't update to an older version (same version is ok)
                return false;
              }
              return true;
            });

    if (workerRestarted.get()) {
      PrestoException exception =
          new PrestoException(
              WORKER_RESTARTED, format("%s (%s)", WORKER_RESTARTED_ERROR, newValue.getSelf()));
      failTask(exception);
      abort();
    }

    // remove acknowledged splits, which frees memory
    for (TaskSource source : sources) {
      PlanNodeId planNodeId = source.getPlanNodeId();
      int removed = 0;
      for (ScheduledSplit split : source.getSplits()) {
        if (pendingSplits.remove(planNodeId, split)) {
          removed++;
        }
      }
      if (planNodeId.equals(planFragment.getPartitionedSource())) {
        pendingSourceSplitCount -= removed;
      }
    }

    if (updated) {
      if (getTaskInfo().getState().isDone()) {
        fireSplitCountChanged(-oldPartitionedSplitCount);
      } else {
        fireSplitCountChanged(getPartitionedSplitCount() - oldPartitionedSplitCount);
      }
    }
  }
 /**
  * Unsubscribes the given producer.
  *
  * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
  */
 public boolean unsubscribe(Entity producer, SubscriptionHandle handle) {
   synchronized (subscriptions) {
     subscriptions.remove(producer, handle);
   }
   return context.unsubscribe(handle);
 }