Search in sources :

Example 1 with Promise

use of org.fusesource.mqtt.client.Promise in project camel by apache.

the class MQTTEndpoint method doStop.

@Override
protected void doStop() throws Exception {
    super.doStop();
    if (connection != null && connected) {
        final Promise<Void> promise = new Promise<>();
        connection.getDispatchQueue().execute(new Task() {

            @Override
            public void run() {
                connection.disconnect(new Callback<Void>() {

                    public void onSuccess(Void value) {
                        connected = false;
                        promise.onSuccess(value);
                    }

                    public void onFailure(Throwable value) {
                        promise.onFailure(value);
                    }
                });
            }
        });
        promise.await(configuration.getDisconnectWaitInSeconds(), TimeUnit.SECONDS);
    }
}
Also used : Promise(org.fusesource.mqtt.client.Promise) Task(org.fusesource.hawtdispatch.Task) Callback(org.fusesource.mqtt.client.Callback)

Aggregations

Task (org.fusesource.hawtdispatch.Task)1 Callback (org.fusesource.mqtt.client.Callback)1 Promise (org.fusesource.mqtt.client.Promise)1