All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.yawenok.apns.http2.impl.handler.Http2SettingsHandler Maven / Gradle / Ivy

package io.github.yawenok.apns.http2.impl.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http2.Http2Settings;

import java.util.concurrent.TimeUnit;

public class Http2SettingsHandler extends SimpleChannelInboundHandler {
    private final ChannelPromise promise;

    public Http2SettingsHandler(final ChannelPromise promise) {
        this.promise = promise;
    }

    public void awaitSettings(final long timeout, final TimeUnit unit) {
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for settings");
        }
        if (!promise.isSuccess()) {
            throw new IllegalStateException(promise.cause());
        }
    }

    @Override
    protected void channelRead0(final ChannelHandlerContext ctx, final Http2Settings msg) throws Exception {
        promise.setSuccess();

        // Only care about the first settings message
        ctx.pipeline().remove(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy