import java.io.InputStream;
import java.util.Optional;
-import java.util.concurrent.Future;
import net.pterodactylus.fcp.Priority;
+import com.google.common.util.concurrent.ListenableFuture;
+
/**
* Command that retrieves data from Freenet.
*
ClientGetCommand realTime();
ClientGetCommand global();
- Future<Optional<Data>> uri(String uri);
+ ListenableFuture<Optional<Data>> uri(String uri);
interface Data {
import java.io.InputStream;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.fcp.Priority;
import net.pterodactylus.fcp.ReturnType;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
/**
* Implementation of the {@link ClientGetCommand}.
*
*/
class ClientGetCommandImpl implements ClientGetCommand {
- private final ExecutorService threadPool;
+ private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
private boolean ignoreDataStore;
private boolean global;
public ClientGetCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
- this.threadPool = threadPool;
+ this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
}
}
@Override
- public Future<Optional<Data>> uri(String uri) {
+ public ListenableFuture<Optional<Data>> uri(String uri) {
ClientGet clientGet = createClientGetCommand(uri);
return threadPool.submit(() -> new ClientGetReplySequence().send(clientGet).get());
}
}
@Override
- public Future<Optional<Data>> send(FcpMessage fcpMessage) throws IOException {
+ public ListenableFuture<Optional<Data>> send(FcpMessage fcpMessage) throws IOException {
identifier.set(fcpMessage.getField("Identifier"));
return super.send(fcpMessage);
}
import net.pterodactylus.fcp.FcpConnection;
import net.pterodactylus.fcp.NodeHello;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
/**
* Default {@link FcpClient} implementation.
*
*/
public class DefaultFcpClient implements FcpClient {
- private final ExecutorService threadPool;
+ private final ListeningExecutorService threadPool;
private final String hostname;
private final int port;
private final AtomicReference<FcpConnection> fcpConnection = new AtomicReference<>();
public DefaultFcpClient(ExecutorService threadPool, String hostname, int port, Supplier<String> clientName,
Supplier<String> expectedVersion) {
- this.threadPool = threadPool;
+ this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.hostname = hostname;
this.port = port;
this.clientName = clientName;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
import java.util.function.Consumer;
import net.pterodactylus.fcp.AllData;
import net.pterodactylus.fcp.UnknownNodeIdentifier;
import net.pterodactylus.fcp.UnknownPeerNoteType;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
/**
* An FCP reply sequence enables you to conveniently wait for a specific set of FCP replies.
*
public abstract class FcpReplySequence<R> implements AutoCloseable, FcpListener {
private final Object syncObject = new Object();
- private final ExecutorService executorService;
+ private final ListeningExecutorService executorService;
private final FcpConnection fcpConnection;
public FcpReplySequence(ExecutorService executorService, FcpConnection fcpConnection) {
- this.executorService = executorService;
+ this.executorService = MoreExecutors.listeningDecorator(executorService);
this.fcpConnection = fcpConnection;
}
protected abstract boolean isFinished();
- public Future<R> send(FcpMessage fcpMessage) throws IOException {
+ public ListenableFuture<R> send(FcpMessage fcpMessage) throws IOException {
try {
fcpConnection.addFcpListener(this);