use of io.crossbar.autobahn.wamp.messages.Unsubscribe in project autobahn-java by crossbario.
the class Session method unsubscribe.
@Override
public CompletableFuture<Integer> unsubscribe(Subscription subscription) {
if (!subscription.isActive()) {
throw new IllegalStateException("Subscription is already inactive");
}
List<Subscription> subscriptions = getOrDefault(mSubscriptions, subscription.subscription, null);
if (subscriptions == null || !subscriptions.contains(subscription)) {
throw new IllegalStateException("Subscription is already inactive");
}
subscriptions.remove(subscription);
subscription.setInactive();
int remainingCount = subscriptions.size();
CompletableFuture<Integer> unsubFuture = new CompletableFuture<>();
if (remainingCount == 0) {
long requestID = mIDGenerator.next();
mUnsubscribeRequests.put(requestID, new UnsubscribeRequest(requestID, unsubFuture, subscription.subscription));
send(new Unsubscribe(requestID, subscription.subscription));
} else {
unsubFuture.complete(remainingCount);
}
return unsubFuture;
}
Aggregations