Example usage for io.netty.util.concurrent Promise setSuccess

List of usage examples for io.netty.util.concurrent Promise setSuccess

Introduction

In this page you can find the example usage for io.netty.util.concurrent Promise setSuccess.

Prototype

Promise<V> setSuccess(V result);

Source Link

Document

Marks this future as a success and notifies all listeners.

Usage

From source file:org.thingsboard.mqtt.MqttClientImpl.java

License:Apache License

private void checkSubscribtions(String topic, Promise<Void> promise) {
    if (!(this.subscriptions.containsKey(topic) && this.subscriptions.get(topic).size() != 0)
            && this.serverSubscriptions.contains(topic)) {
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBSCRIBE, false,
                MqttQoS.AT_LEAST_ONCE, false, 0);
        MqttMessageIdVariableHeader variableHeader = getNewMessageId();
        MqttUnsubscribePayload payload = new MqttUnsubscribePayload(Collections.singletonList(topic));
        MqttUnsubscribeMessage message = new MqttUnsubscribeMessage(fixedHeader, variableHeader, payload);

        MqttPendingUnsubscription pendingUnsubscription = new MqttPendingUnsubscription(promise, topic,
                message);/*  w  w  w.  j a v  a2 s .  com*/
        this.pendingServerUnsubscribes.put(variableHeader.messageId(), pendingUnsubscription);
        pendingUnsubscription.startRetransmissionTimer(this.eventLoop.next(), this::sendAndFlushPacket);

        this.sendAndFlushPacket(message);
    } else {
        promise.setSuccess(null);
    }
}