code: public void setNodes(final @Nonnull Collection<? extends Node> nodes) throws IOException {
          Queue.withLock(new Runnable() {
              @Override
              public void run() {
                  Set<String> toRemove = new HashSet<>(Nodes.this.nodes.keySet());
                  for (Node n : nodes) {
                      final String name = n.getNodeName();
                      toRemove.remove(name);
                      Nodes.this.nodes.put(name, n);
                  }
                  Nodes.this.nodes.keySet().removeAll(toRemove); // directory clean up will be handled by save
                  jenkins.updateComputerList();
                  jenkins.trimLabels();
              }
          });
          save();
      }
docs: Sets the list of nodes.
  
  @param nodes the new list of nodes.
  @throws IOException if the new list of nodes could not be persisted.