private final ConnectionSupplier connectionSupplier;
private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
private final AtomicReference<Boolean> enabled = new AtomicReference<>();
+ private final AtomicReference<Boolean> allowLocalAddresses = new AtomicReference<>();
public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
}
@Override
+ public ModifyPeerCommand disable() {
+ enabled.set(false);
+ return this;
+ }
+
+ @Override
+ public ModifyPeerCommand allowLocalAddresses() {
+ allowLocalAddresses.set(true);
+ return this;
+ }
+
+ @Override
public Executable<Optional<Peer>> byName(String name) {
nodeIdentifier.set(name);
return this::execute;
}
+ @Override
+ public Executable<Optional<Peer>> byIdentity(String nodeIdentity) {
+ nodeIdentifier.set(nodeIdentity);
+ return this::execute;
+ }
+
+ @Override
+ public Executable<Optional<Peer>> byHostAndPort(String host, int port) {
+ nodeIdentifier.set(String.format("%s:%d", host, port));
+ return this::execute;
+ }
+
private ListenableFuture<Optional<Peer>> execute() {
return threadPool.submit(this::executeSequence);
}
private Optional<Peer> executeSequence() throws IOException, ExecutionException, InterruptedException {
ModifyPeer modifyPeer = new ModifyPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
Optional.ofNullable(enabled.get()).ifPresent(enabled -> modifyPeer.setEnabled(enabled));
+ Optional.ofNullable(allowLocalAddresses.get()).ifPresent(allowed -> modifyPeer.setAllowLocalAddresses(allowed));
try (ModifyPeerDialog modifyPeerDialog = new ModifyPeerDialog()) {
return modifyPeerDialog.send(modifyPeer).get();
}