X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FDefaultFcpClient.java;h=3dd0b7692ef25d5c7ba6ea9b1d7dbc6397d899ec;hb=e591c6488b692e3dfcf2efd1905d399f39c6067f;hp=8d2afc0a5a06f22aa4bfbf56e11f108100d94e90;hpb=e3f3a4323df8d53a0a59c2e4369abbcd8d60b940;p=jFCPlib.git diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java index 8d2afc0..3dd0b76 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java @@ -1,12 +1,14 @@ package net.pterodactylus.fcp.quelaton; import java.io.IOException; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import net.pterodactylus.fcp.FcpConnection; +import net.pterodactylus.fcp.Peer; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; @@ -33,11 +35,11 @@ public class DefaultFcpClient implements FcpClient { private FcpConnection connect() throws IOException { FcpConnection fcpConnection = this.fcpConnection.get(); - if (fcpConnection != null) { + if ((fcpConnection != null) && !fcpConnection.isClosed()) { return fcpConnection; } fcpConnection = createConnection(); - this.fcpConnection.compareAndSet(null, fcpConnection); + this.fcpConnection.set(fcpConnection); return fcpConnection; } @@ -70,9 +72,29 @@ public class DefaultFcpClient implements FcpClient { } @Override + public ListPeerCommand listPeer() { + return new ListPeerCommandImpl(threadPool, this::connect); + } + + @Override public ListPeersCommand listPeers() { return new ListPeersCommandImpl(threadPool, this::connect); } + @Override + public AddPeerCommand addPeer() { + return new AddPeerCommandImpl(threadPool, this::connect); + } + + @Override + public ModifyPeerCommand modifyPeer() { + return new ModifyPeerCommandImpl(threadPool, this::connect); + } + + @Override + public ListPeerNotesCommand listPeerNotes() { + return new ListPeerNotesCommandImpl(threadPool, this::connect); + } + }