Esempio n. 1
0
  private void updateNodes(MemoryPoolAssignmentsRequest assignments) {
    Set<Node> activeNodes = nodeManager.getActiveNodes();
    ImmutableSet<String> activeNodeIds =
        activeNodes.stream().map(Node::getNodeIdentifier).collect(toImmutableSet());

    // Remove nodes that don't exist anymore
    // Make a copy to materialize the set difference
    Set<String> deadNodes = ImmutableSet.copyOf(difference(nodes.keySet(), activeNodeIds));
    nodes.keySet().removeAll(deadNodes);

    // Add new nodes
    for (Node node : activeNodes) {
      if (!nodes.containsKey(node.getNodeIdentifier())) {
        nodes.put(
            node.getNodeIdentifier(),
            new RemoteNodeMemory(
                httpClient,
                memoryInfoCodec,
                assignmentsRequestJsonCodec,
                locationFactory.createMemoryInfoLocation(node)));
      }
    }

    // Schedule refresh
    for (RemoteNodeMemory node : nodes.values()) {
      node.asyncRefresh(assignments);
    }
  }