List of usage examples for io.netty.handler.codec.http2 Http2Connection addListener
void addListener(Listener listener);
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
private Http2ClientConnectionHandler newHttp2ConnectionHandler(Channel ch) { final boolean validateHeaders = false; final Http2Connection conn = new DefaultHttp2Connection(false); conn.addListener(new Http2GoAwayListener(ch)); Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders); Http2FrameWriter writer = new DefaultHttp2FrameWriter(); Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final Http2ResponseDecoder listener = new Http2ResponseDecoder(ch); final Http2ClientConnectionHandler handler = new Http2ClientConnectionHandler(decoder, encoder, new Http2Settings(), listener); // Setup post build options handler.gracefulShutdownTimeoutMillis(options.idleTimeoutMillis()); return handler; }
From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java
License:Apache License
private Http2ClientConnectionHandler newHttp2ConnectionHandler(Channel ch) { final boolean validateHeaders = false; final Http2Connection conn = new DefaultHttp2Connection(false); conn.addListener(new Http2GoAwayListener(ch)); final Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders); final Http2FrameWriter writer = new DefaultHttp2FrameWriter(); final Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); final Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final Http2Settings http2Settings = http2Settings(); final Http2ResponseDecoder listener = new Http2ResponseDecoder(conn, ch, encoder); final Http2ClientConnectionHandler handler = new Http2ClientConnectionHandler(decoder, encoder, http2Settings, listener);//from w ww . j av a 2 s. c o m // Setup post build options handler.gracefulShutdownTimeoutMillis(clientFactory.idleTimeoutMillis()); return handler; }
From source file:com.linecorp.armeria.client.HttpConfigurator.java
License:Apache License
private Http2ConnectionHandler newHttp2ConnectionHandler(Channel ch) { final boolean validateHeaders = false; final Http2Connection conn = new DefaultHttp2Connection(false); conn.addListener(new Http2GoAwayListener(ch)); final InboundHttp2ToHttpAdapter listener = new InboundHttp2ToHttpAdapterBuilder(conn) .propagateSettings(true).validateHttpHeaders(validateHeaders) .maxContentLength(options.maxFrameLength()).build(); Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders); Http2FrameWriter writer = new DefaultHttp2FrameWriter(); Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final HttpToHttp2ClientConnectionHandler handler = new HttpToHttp2ClientConnectionHandler(decoder, encoder, new Http2Settings(), validateHeaders); // Setup post build options handler.gracefulShutdownTimeoutMillis(options.idleTimeoutMillis()); handler.decoder().frameListener(listener); return handler; }
From source file:com.linecorp.armeria.server.http.HttpServerPipelineConfigurator.java
License:Apache License
private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) { final Http2Connection conn = new DefaultHttp2Connection(true); conn.addListener(new Http2GoAwayListener(pipeline.channel())); Http2FrameReader reader = new DefaultHttp2FrameReader(true); Http2FrameWriter writer = new DefaultHttp2FrameWriter(); Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final Http2ConnectionHandler handler = new Http2ServerConnectionHandler(decoder, encoder, new Http2Settings()); // Setup post build options final Http2RequestDecoder listener = new Http2RequestDecoder(pipeline.channel(), handler.encoder()); handler.connection().addListener(listener); handler.decoder().frameListener(listener); handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis()); return handler; }
From source file:com.linecorp.armeria.server.HttpServerPipelineConfigurator.java
License:Apache License
private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) { final Http2Connection conn = new DefaultHttp2Connection(true); conn.addListener(new Http2GoAwayListener(pipeline.channel())); final Http2FrameReader reader = new DefaultHttp2FrameReader(true); final Http2FrameWriter writer = new DefaultHttp2FrameWriter(); final Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); final Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final Http2ConnectionHandler handler = new Http2ServerConnectionHandler(decoder, encoder, new Http2Settings()); // Setup post build options final Http2RequestDecoder listener = new Http2RequestDecoder(config, pipeline.channel(), handler.encoder()); handler.connection().addListener(listener); handler.decoder().frameListener(listener); handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis()); return handler; }
From source file:com.linecorp.armeria.server.ServerInitializer.java
License:Apache License
private Http2ConnectionHandler createHttp2ConnectionHandler(ChannelPipeline pipeline, ChannelHandler... toRemove) {/* w ww .jav a2 s . c o m*/ final boolean validateHeaders = true; final Http2Connection conn = new DefaultHttp2Connection(true); conn.addListener(new Http2GoAwayListener(pipeline.channel())); final Http2FrameListener listener = new InboundHttp2ToHttpAdapterBuilder(conn).propagateSettings(true) .validateHttpHeaders(validateHeaders).maxContentLength(config.maxFrameLength()).build(); Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders); Http2FrameWriter writer = new DefaultHttp2FrameWriter(); Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final HttpToHttp2ServerConnectionHandler handler = new HttpToHttp2ServerConnectionHandler(pipeline, decoder, encoder, new Http2Settings(), validateHeaders, toRemove); // Setup post build options handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis()); handler.decoder().frameListener(listener); return handler; }
From source file:io.grpc.netty.NettyClientHandler.java
License:Apache License
private NettyClientHandler(Http2ConnectionDecoder decoder, StreamBufferingEncoder encoder, Http2Settings settings, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, Supplier<Stopwatch> stopwatchFactory, final Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority) {/*from www . j a v a 2s .com*/ super(/* channelUnused= */ null, decoder, encoder, settings); this.lifecycleManager = lifecycleManager; this.keepAliveManager = keepAliveManager; this.stopwatchFactory = stopwatchFactory; this.transportTracer = Preconditions.checkNotNull(transportTracer); this.eagAttributes = eagAttributes; this.authority = authority; this.attributes = Attributes.newBuilder().set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, eagAttributes).build(); // Set the frame listener on the decoder. decoder().frameListener(new FrameListener()); Http2Connection connection = encoder.connection(); streamKey = connection.newKey(); connection.addListener(new Http2ConnectionAdapter() { @Override public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) { byte[] debugDataBytes = ByteBufUtil.getBytes(debugData); goingAway(statusFromGoAway(errorCode, debugDataBytes)); if (errorCode == Http2Error.ENHANCE_YOUR_CALM.code()) { String data = new String(debugDataBytes, UTF_8); logger.log(Level.WARNING, "Received GOAWAY with ENHANCE_YOUR_CALM. Debug data: {1}", data); if ("too_many_pings".equals(data)) { tooManyPingsRunnable.run(); } } } @Override public void onStreamActive(Http2Stream stream) { if (connection().numActiveStreams() == 1 && NettyClientHandler.this.keepAliveManager != null) { NettyClientHandler.this.keepAliveManager.onTransportActive(); } } @Override public void onStreamClosed(Http2Stream stream) { // Although streams with CALL_OPTIONS_RPC_OWNED_BY_BALANCER are not marked as "in-use" in // the first place, we don't propagate that option here, and it's safe to reset the in-use // state for them, which will be a cheap no-op. inUseState.updateObjectInUse(stream, false); if (connection().numActiveStreams() == 0 && NettyClientHandler.this.keepAliveManager != null) { NettyClientHandler.this.keepAliveManager.onTransportIdle(); } } }); }
From source file:io.grpc.netty.NettyServerHandler.java
License:Apache License
private NettyServerHandler(ChannelPromise channelUnused, final Http2Connection connection, ServerTransportListener transportListener, List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings settings, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, final KeepAliveEnforcer keepAliveEnforcer) { super(channelUnused, decoder, encoder, settings); final MaxConnectionIdleManager maxConnectionIdleManager; if (maxConnectionIdleInNanos == MAX_CONNECTION_IDLE_NANOS_DISABLED) { maxConnectionIdleManager = null; } else {//from ww w .j ava 2s .c om maxConnectionIdleManager = new MaxConnectionIdleManager(maxConnectionIdleInNanos) { @Override void close(ChannelHandlerContext ctx) { if (gracefulShutdown == null) { gracefulShutdown = new GracefulShutdown("max_idle", null); gracefulShutdown.start(ctx); ctx.flush(); } } }; } connection.addListener(new Http2ConnectionAdapter() { @Override public void onStreamActive(Http2Stream stream) { if (connection.numActiveStreams() == 1) { keepAliveEnforcer.onTransportActive(); if (maxConnectionIdleManager != null) { maxConnectionIdleManager.onTransportActive(); } } } @Override public void onStreamClosed(Http2Stream stream) { if (connection.numActiveStreams() == 0) { keepAliveEnforcer.onTransportIdle(); if (maxConnectionIdleManager != null) { maxConnectionIdleManager.onTransportIdle(); } } } }); checkArgument(maxMessageSize >= 0, "maxMessageSize must be >= 0"); this.maxMessageSize = maxMessageSize; this.keepAliveTimeInNanos = keepAliveTimeInNanos; this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos; this.maxConnectionIdleManager = maxConnectionIdleManager; this.maxConnectionAgeInNanos = maxConnectionAgeInNanos; this.maxConnectionAgeGraceInNanos = maxConnectionAgeGraceInNanos; this.keepAliveEnforcer = checkNotNull(keepAliveEnforcer, "keepAliveEnforcer"); streamKey = encoder.connection().newKey(); this.transportListener = checkNotNull(transportListener, "transportListener"); this.streamTracerFactories = checkNotNull(streamTracerFactories, "streamTracerFactories"); this.transportTracer = checkNotNull(transportTracer, "transportTracer"); // Set the frame listener on the decoder. decoder().frameListener(new FrameListener()); }