Implement notification on USK update
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / DefaultFcpClient.java
index 6cefb46..53e3640 100644 (file)
@@ -23,6 +23,7 @@ public class DefaultFcpClient implements FcpClient {
        private final int port;
        private final AtomicReference<FcpConnection> fcpConnection = new AtomicReference<>();
        private final Supplier<String> clientName;
+       private final ActiveSubscriptions activeSubscriptions = new ActiveSubscriptions();
 
        public DefaultFcpClient(ExecutorService threadPool, String hostname, int port, Supplier<String> clientName) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -38,6 +39,11 @@ public class DefaultFcpClient implements FcpClient {
                }
                fcpConnection = createConnection();
                this.fcpConnection.set(fcpConnection);
+               try {
+                       activeSubscriptions.renew(fcpConnection::addFcpListener, this::subscribeUsk);
+               } catch (InterruptedException | ExecutionException e) {
+                       throw new IOException(e);
+               }
                return fcpConnection;
        }
 
@@ -55,6 +61,16 @@ public class DefaultFcpClient implements FcpClient {
        }
 
        @Override
+       public GetConfigCommand getConfig() {
+               return new GetConfigCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public ModifyConfigCommand modifyConfig() {
+               return new ModifyConfigCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
        public GenerateKeypairCommand generateKeypair() {
                return new GenerateKeypairCommandImpl(threadPool, this::connect);
        }
@@ -79,5 +95,55 @@ public class DefaultFcpClient implements FcpClient {
                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);
+       }
+
+       @Override
+       public LoadPluginCommand loadPlugin() {
+               return new LoadPluginCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public ReloadPluginCommand reloadPlugin() {
+               return new ReloadPluginCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public RemovePluginCommand removePlugin() {
+               return new RemovePluginCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public GetPluginInfoCommand getPluginInfo() {
+               return new GetPluginInfoCommandImpl(threadPool, this::connect);
+       }
+
+       @Override
+       public SubscribeUskCommand subscribeUsk() {
+               return new SubscribeUskCommandImpl(threadPool, this::connect, activeSubscriptions);
+       }
+
 }