Add subscription cancelling
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / ActiveSubscriptions.java
index 241253d..43317d0 100644 (file)
@@ -23,8 +23,13 @@ import net.pterodactylus.fcp.SubscribedUSKUpdate;
  */
 public class ActiveSubscriptions {
 
+       private final Supplier<UnsubscribeUskCommand> unsubscribeUskCommandSupplier;
        private final Map<String, RemoteUskSubscription> subscriptions = Collections.synchronizedMap(new HashMap<>());
 
+       public ActiveSubscriptions(Supplier<UnsubscribeUskCommand> unsubscribeUskCommandSupplier) {
+               this.unsubscribeUskCommandSupplier = unsubscribeUskCommandSupplier;
+       }
+
        public void renew(Consumer<FcpListener> fcpEventSender, Supplier<SubscribeUskCommand> subscribeUskCommandSupplier)
        throws ExecutionException, InterruptedException {
                fcpEventSender.accept(createFcpListener());
@@ -58,7 +63,7 @@ public class ActiveSubscriptions {
                return remoteUskSubscription;
        }
 
-       private static class RemoteUskSubscription implements UskSubscription {
+       private class RemoteUskSubscription implements UskSubscription {
 
                private final String identifier;
                private final String uri;
@@ -99,6 +104,11 @@ public class ActiveSubscriptions {
                        }
                }
 
+               public void cancel() throws ExecutionException, InterruptedException {
+                       unsubscribeUskCommandSupplier.get().identifier(identifier).execute().get();
+                       subscriptions.remove(identifier);
+               }
+
        }
 
 }