Search in sources :

Example 1 with Unsubscribe

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) UnsubscribeRequest(io.crossbar.autobahn.wamp.requests.UnsubscribeRequest) Subscription(io.crossbar.autobahn.wamp.types.Subscription) Unsubscribe(io.crossbar.autobahn.wamp.messages.Unsubscribe)

Aggregations

Unsubscribe (io.crossbar.autobahn.wamp.messages.Unsubscribe)1 UnsubscribeRequest (io.crossbar.autobahn.wamp.requests.UnsubscribeRequest)1 Subscription (io.crossbar.autobahn.wamp.types.Subscription)1 CompletableFuture (java.util.concurrent.CompletableFuture)1