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

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

Introduction

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

Prototype

public PromiseAggregator(Promise<Void> aggregatePromise) 

Source Link

Document

See PromiseAggregator#PromiseAggregator(Promise,boolean) .

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);/*  w  w  w  .j a v  a2  s .c o m*/
    }
    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 . ja va  2 s  .c  o  m*/
        };
        promiseAggregator.add(promises.toArray(new Promise[1]));
    } else {
        promise.setSuccess(null);
    }
}