import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@Override
public Executable<Optional<Data>> uri(String uri) {
+ return () -> threadPool.submit(() -> execute(uri));
+ }
+
+ private Optional<Data> execute(String uri) throws InterruptedException, ExecutionException, IOException {
ClientGet clientGet = createClientGetCommand(uri);
- return () -> threadPool.submit(() -> new ClientGetReplySequence().send(clientGet).get());
+ try (ClientGetReplySequence clientGetReplySequence = new ClientGetReplySequence()) {
+ return clientGetReplySequence.send(clientGet).get();
+ }
}
private ClientGet createClientGetCommand(String uri) {
}
private ListenableFuture<FcpConnection> execute() {
- return threadPool.submit(() -> establishConnection());
+ return threadPool.submit(this::establishConnection);
}
private FcpConnection establishConnection() throws IOException {
FcpConnection connection = new FcpConnection(hostname, port);
connection.connect();
- ClientHelloReplySequence nodeHelloSequence = new ClientHelloReplySequence(connection);
ClientHello clientHello = new ClientHello(clientName.get(), "2.0");
- try {
+ try (ClientHelloReplySequence nodeHelloSequence = new ClientHelloReplySequence(connection)) {
if (nodeHelloSequence.send(clientHello).get()) {
return connection;
}
import java.nio.file.Files;
import java.util.Objects;
import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
}
private Executable<Optional<Key>> key(String uri) {
+ return () -> threadPool.submit(() -> execute(uri));
+ }
+
+ private Optional<Key> execute(String uri) throws InterruptedException, ExecutionException, IOException {
String identifier = new RandomIdentifierGenerator().generate();
ClientPut clientPut = createClientPutCommand(uri, identifier);
- return () -> threadPool.submit(() -> new ClientPutReplySequence().send(clientPut).get());
+ try (ClientPutReplySequence clientPutReplySequence = new ClientPutReplySequence()) {
+ return clientPutReplySequence.send(clientPut).get();
+ }
}
private ClientPut createClientPutCommand(String uri, String identifier) {
package net.pterodactylus.fcp.quelaton;
import java.io.IOException;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.fcp.FcpKeyPair;
@Override
public ListenableFuture<FcpKeyPair> execute() {
- return threadPool.submit(() -> new FcpKeyPairReplySequence().send(new GenerateSSK()).get());
+ return threadPool.submit(this::executeSequence);
+ }
+
+ private FcpKeyPair executeSequence() throws InterruptedException, ExecutionException, IOException {
+ try (FcpKeyPairReplySequence fcpKeyPairReplySequence = new FcpKeyPairReplySequence()) {
+ return fcpKeyPairReplySequence.send(new GenerateSSK()).get();
+ }
}
private class FcpKeyPairReplySequence extends FcpReplySequence<FcpKeyPair> {
package net.pterodactylus.fcp.quelaton;
import java.io.IOException;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@Override
public ListenableFuture<NodeData> execute() {
+ return threadPool.submit(this::executeSequence);
+ }
+
+ private NodeData executeSequence() throws InterruptedException, ExecutionException, IOException {
GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(),
includePrivate.get(), includeVolatile.get());
- return threadPool.submit(() -> new GetNodeReplySequence().send(getNode).get());
+ try (GetNodeReplySequence getNodeReplySequence = new GetNodeReplySequence()) {
+ return getNodeReplySequence.send(getNode).get();
+ }
}
private class GetNodeReplySequence extends FcpReplySequence<NodeData> {
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import net.pterodactylus.fcp.EndListPeers;
@Override
public ListenableFuture<Collection<Peer>> execute() {
+ return threadPool.submit(this::executeSequence);
+ }
+
+ private Collection<Peer> executeSequence() throws InterruptedException, ExecutionException, IOException {
String identifier = new RandomIdentifierGenerator().generate();
ListPeers listPeers = new ListPeers(identifier, includeMetadata.get(), includeVolatile.get());
- return threadPool.submit(() -> new ListPeersReplySequence().send(listPeers).get());
+ try (ListPeersReplySequence listPeersReplySequence = new ListPeersReplySequence()) {
+ return listPeersReplySequence.send(listPeers).get();
+ }
}
private class ListPeersReplySequence extends FcpReplySequence<Collection<Peer>> {