Example usage for io.netty.util.concurrent PromiseAggregator add

List of usage examples for io.netty.util.concurrent PromiseAggregator add

Introduction

In this page you can find the example usage for io.netty.util.concurrent PromiseAggregator add.

Prototype

@SafeVarargs
public final PromiseAggregator<V, F> add(Promise<V>... promises) 

Source Link

Document

Add the given Promise s to the aggregator.

Usage

From source file:com.github.milenkovicm.kafka.KafkaProducer.java

License:Apache License

public Future<Void> disconnect() {
    this.shutdown = true;

    List<Future<?>> futures = new ArrayList<>();
    if (control != null) {
        final ChannelFuture disconnectControl = control.channel().disconnect();
        futures.add(disconnectControl);/*from   w ww.j a va2 s . c  om*/
    }
    for (DataKafkaBroker data : brokers.values()) {
        final Future<?> disconnectData = data.disconnect();
        futures.add(disconnectData);
    }
    brokers.clear();
    control = null;

    if (futures.size() > 0) {
        final PromiseAggregator<Void, ChannelFuture> promiseAggregator = new PromiseAggregator<Void, ChannelFuture>(
                disconnectPromise);
        promiseAggregator.add(futures.toArray(new Promise[1]));
    } else {
        disconnectPromise.setSuccess(null);
    }
    this.workerGroup.shutdownGracefully();
    this.eventExecutor.shutdownGracefully();
    return disconnectPromise;
}

From source file:com.github.milenkovicm.kafka.KafkaProducer.java

License:Apache License

void completePromise(final Promise<Void> promise, List<ChannelFuture> promises) {
    if (promises.size() > 0) {
        final PromiseAggregator<Void, ChannelFuture> promiseAggregator = new PromiseAggregator<Void, ChannelFuture>(
                promise) {/* w w  w  . j  av  a  2  s .  co m*/
        };
        promiseAggregator.add(promises.toArray(new Promise[1]));
    } else {
        promise.setSuccess(null);
    }
}