List of usage examples for io.netty.channel ChannelPipeline channel
Channel channel();
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) { if (protocol == H1 || protocol == H1C) { addBeforeSessionHandler(pipeline, new Http1ResponseDecoder(pipeline.channel())); }//from w w w.j a v a2 s . co m final long idleTimeoutMillis = options.idleTimeoutMillis(); if (idleTimeoutMillis > 0) { pipeline.addFirst(new HttpClientIdleTimeoutHandler(idleTimeoutMillis)); } pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol)); }
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
void finishWithNegotiationFailure(ChannelHandlerContext ctx, SessionProtocol expected, SessionProtocol actual, String reason) {//from w w w.j ava 2 s . com final ChannelPipeline pipeline = ctx.pipeline(); pipeline.channel().eventLoop().execute(() -> pipeline .fireUserEventTriggered(new SessionProtocolNegotiationException(expected, actual, reason))); ctx.close(); }
From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java
License:Apache License
void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) { if (protocol == H1 || protocol == H1C) { addBeforeSessionHandler(pipeline, new Http1ResponseDecoder(pipeline.channel())); } else if (protocol == H2 || protocol == H2C) { final int initialWindow = clientFactory.initialHttp2ConnectionWindowSize(); if (initialWindow > DEFAULT_WINDOW_SIZE) { incrementLocalWindowSize(pipeline, initialWindow - DEFAULT_WINDOW_SIZE); }// www .ja va 2s .c o m } final long idleTimeoutMillis = clientFactory.idleTimeoutMillis(); if (idleTimeoutMillis > 0) { pipeline.addFirst(new HttpClientIdleTimeoutHandler(idleTimeoutMillis)); } pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol)); }
From source file:com.linecorp.armeria.client.HttpConfigurator.java
License:Apache License
void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) { switch (protocol) { case H1://from w w w.j a v a 2s . co m case H1C: addBeforeSessionHandler(pipeline, new HttpObjectAggregator(options.maxFrameLength())); break; case H2: case H2C: // HTTP/2 does not require the aggregator because // InboundHttp2ToHttpAdapter always creates a FullHttpRequest. break; default: // Should never reach here. throw new Error(); } final long idleTimeoutMillis = options.idleTimeoutMillis(); if (idleTimeoutMillis > 0) { final HttpClientIdleTimeoutHandler timeoutHandler; if (protocol == H2 || protocol == H2C) { timeoutHandler = new Http2ClientIdleTimeoutHandler(idleTimeoutMillis); } else { // Note: We should not use Http2ClientIdleTimeoutHandler for HTTP/1 connections, // because we cannot tell if the headers defined in ExtensionHeaderNames such as // 'x-http2-stream-id' have been set by us or a malicious server. timeoutHandler = new HttpClientIdleTimeoutHandler(idleTimeoutMillis); } addBeforeSessionHandler(pipeline, timeoutHandler); } pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol)); }
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 . ja v a 2s .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:com.tc.websocket.server.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { IConfig cfg = Config.getInstance();/*from w w w .ja va2 s . c o m*/ //if we need to check for ByteBuf leaks. if (cfg.isLeakDetector()) { ResourceLeakDetector.setLevel(Level.ADVANCED); } //so we get enough data to build our pipeline ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(1024)); ChannelPipeline pipeline = ch.pipeline(); int incomingPort = ch.localAddress().getPort(); //if users are coming in on a different port than the proxy port we need to redirect them. if (cfg.isProxy() && cfg.getPort() != incomingPort) { redirectBuilder.apply(pipeline); return; } if (cfg.isEncrypted()) { SslContext sslContext = factory.createSslContext(Config.getInstance()); SSLEngine engine = sslContext.newEngine(ch.alloc()); engine.setUseClientMode(false); engine.setNeedClientAuth(cfg.isCertAuth()); ch.pipeline().addFirst("ssl", new SslHandler(engine)); } if (cfg.isProxy()) { pipeline.channel().config().setAutoRead(false); pipeline.addLast( guicer.inject(new ProxyFrontendHandler(cfg.getProxyBackendHost(), cfg.getProxyBackendPort()))); } else { websocketBuilder.apply(pipeline); } }
From source file:com.tesora.dve.db.mysql.portal.protocol.StreamValve.java
License:Open Source License
public void pause(ChannelPipeline pipeline) { validateInLoopAndPipeline(pipeline); if (!paused) { logger.info("{} flow paused", this); this.paused = true; pipeline.channel().config().setAutoRead(false); }//w ww . j av a2s. co m }
From source file:io.crate.mqtt.netty.Netty4MqttServerTransport.java
@Override protected void doStart() { if (isEnterprise == false || isEnabled == false) { return;/*from w w w. ja v a 2 s. c om*/ } mqttIngestService.initialize(); serverBootstrap = CrateChannelBootstrapFactory.newChannelBootstrap("mqtt", settings); serverBootstrap.childHandler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); final MqttProcessor processor = new MqttProcessor(mqttIngestService); final MqttNettyHandler handler = new MqttNettyHandler(processor); final MqttNettyIdleTimeoutHandler timeoutHandler = new MqttNettyIdleTimeoutHandler(); final IdleStateHandler defaultIdleHandler = new IdleStateHandler(0L, 0L, defaultIdleTimeout.seconds(), TimeUnit.SECONDS); pipeline.addFirst("idleStateHandler", defaultIdleHandler) .addAfter("idleStateHandler", "idleEventHandler", timeoutHandler) .addLast("decoder", new MqttDecoder()).addLast("encoder", MqttEncoder.INSTANCE) .addLast("messageLogger", mqttMessageLogger).addLast("handler", handler); if (isMQTTSslEnabled(settings)) { SslHandler sslHandler = sslContextProvider.get().newHandler(pipeline.channel().alloc()); pipeline.addFirst(sslHandler); } } }); serverBootstrap.validate(); boolean success = false; try { boundAddress = resolveBindAddress(); logger.info("{}", boundAddress); success = true; } finally { if (!success) { doStop(); // stop boss/worker threads to avoid leaks } } }