Example usage for io.netty.channel ChannelPromiseAggregator ChannelPromiseAggregator

List of usage examples for io.netty.channel ChannelPromiseAggregator ChannelPromiseAggregator

Introduction

In this page you can find the example usage for io.netty.channel ChannelPromiseAggregator ChannelPromiseAggregator.

Prototype

public ChannelPromiseAggregator(ChannelPromise aggregatePromise) 

Source Link

Usage

From source file:org.jboss.aerogear.webpush.WebPushToHttp2ConnectionHandler.java

License:Apache License

@Override
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
    if (msg instanceof WebPushMessage) {
        final WebPushMessage message = (WebPushMessage) msg;
        final Http2ConnectionEncoder encoder = encoder();
        final int streamId = connection().local().incrementAndGetNextStreamId();
        if (message.hasData()) {
            final ChannelPromiseAggregator promiseAggregator = new ChannelPromiseAggregator(promise);
            final ChannelPromise headerPromise = ctx.newPromise();
            final ChannelPromise dataPromise = ctx.newPromise();
            promiseAggregator.add(headerPromise, dataPromise);
            encoder.writeHeaders(ctx, streamId, message.headers(), 0, false, headerPromise);
            encoder.writeData(ctx, streamId, message.payload(), 0, true, dataPromise);
        } else {/*  ww w . j  a va  2s  .  com*/
            encoder.writeHeaders(ctx, streamId, message.headers(), 0, true, promise);
        }
    } else {
        ctx.write(msg, promise);
    }
}