Add command that modifies the note of a peer
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / DefaultFcpClient.java
index 0693e1c..1fc03bb 100644 (file)
@@ -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;
        }
 
@@ -50,6 +52,11 @@ public class DefaultFcpClient implements FcpClient {
        }
 
        @Override
+       public GetNodeCommand getNode() {
+               return new GetNodeCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
        public GenerateKeypairCommand generateKeypair() {
                return new GenerateKeypairCommandImpl(threadPool, this::connect);
        }
@@ -65,9 +72,39 @@ 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 RemovePeerCommand removePeer() {
+               return new RemovePeerCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public ListPeerNotesCommand listPeerNotes() {
+               return new ListPeerNotesCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public ModifyPeerNoteCommand modifyPeerNote() {
+               return new ModifyPeerNoteCommandImpl(threadPool, this::connect);
+       }
+
 }