Add subscription cancelling
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / DefaultFcpClient.java
index 2f0cc35..d0bf14a 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(this::unsubscribeUsk);
 
        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;
        }
 
@@ -124,5 +130,24 @@ public class DefaultFcpClient implements FcpClient {
                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);
+       }
+
+       private UnsubscribeUskCommand unsubscribeUsk() {
+               return new UnsubscribeUskCommandImpl(threadPool, this::connect);
+       }
+
 }