List of usage examples for io.netty.channel ChannelHandlerContext fireChannelActive
@Override ChannelHandlerContext fireChannelActive();
From source file:com.github.liyp.netty.HandlerChainApp.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup boss = new NioEventLoopGroup(); EventLoopGroup worker = new NioEventLoopGroup(); try {// w w w .j av a 2s.c om ServerBootstrap b = new ServerBootstrap(); b.group(boss, worker).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { logger.info("1"); ctx.fireChannelActive(); } }).addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { logger.info("2"); ctx.fireChannelActive(); } }).addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { logger.info("3"); ctx.fireChannelActive(); } }); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); ChannelFuture f = b.bind(PORT).sync(); logger.info("9999"); f.channel().closeFuture().sync(); } finally { worker.shutdownGracefully(); boss.shutdownGracefully(); } }
From source file:com.github.nettybook.ch0.LoggingHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "ACTIVE")); }// w w w .j a v a 2s . c om ctx.fireChannelActive(); }
From source file:com.lambdaworks.redis.PlainChannelInitializer.java
License:Apache License
static void pingBeforeActivate(AsyncCommand<?, ?, ?> cmd, CompletableFuture<Boolean> initializedFuture, ChannelHandlerContext ctx, ClientResources clientResources, long timeout, TimeUnit timeUnit) throws Exception { ctx.channel().writeAndFlush(cmd);/*from w ww . j a v a2s. c o m*/ Runnable timeoutGuard = () -> { if (cmd.isDone() || initializedFuture.isDone()) { return; } initializedFuture.completeExceptionally(new RedisCommandTimeoutException(String .format("Cannot initialize channel (PING before activate) within %d %s", timeout, timeUnit))); }; Timeout timeoutHandle = clientResources.timer().newTimeout(t -> { if (clientResources.eventExecutorGroup().isShuttingDown()) { timeoutGuard.run(); return; } clientResources.eventExecutorGroup().submit(timeoutGuard); }, timeout, timeUnit); cmd.whenComplete((o, throwable) -> { timeoutHandle.cancel(); if (throwable == null) { ctx.fireChannelActive(); initializedFuture.complete(true); } else { initializedFuture.completeExceptionally(throwable); } }); }
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
private void configureAsHttp(Channel ch) { final ChannelPipeline pipeline = ch.pipeline(); final boolean attemptUpgrade; switch (httpPreference) { case HTTP1_REQUIRED: attemptUpgrade = false;//from www . j av a2 s . c o m break; case HTTP2_PREFERRED: attemptUpgrade = !SessionProtocolNegotiationCache.isUnsupported(remoteAddress, H2C); break; case HTTP2_REQUIRED: attemptUpgrade = true; break; default: // Should never reach here. throw new Error(); } if (attemptUpgrade) { final Http2ClientConnectionHandler http2Handler = newHttp2ConnectionHandler(ch); if (options.useHttp2Preface()) { pipeline.addLast(new DowngradeHandler()); pipeline.addLast(http2Handler); } else { Http1ClientCodec http1Codec = newHttp1Codec(); Http2ClientUpgradeCodec http2ClientUpgradeCodec = new Http2ClientUpgradeCodec(http2Handler); HttpClientUpgradeHandler http2UpgradeHandler = new HttpClientUpgradeHandler(http1Codec, http2ClientUpgradeCodec, (int) Math.min(Integer.MAX_VALUE, UPGRADE_RESPONSE_MAX_LENGTH)); pipeline.addLast(http1Codec); pipeline.addLast(new WorkaroundHandler()); pipeline.addLast(http2UpgradeHandler); pipeline.addLast(new UpgradeRequestHandler(http2Handler.responseDecoder())); } } else { pipeline.addLast(newHttp1Codec()); // NB: We do not call finishSuccessfully() immediately here // because it assumes HttpSessionHandler to be in the pipeline, // which is only true after the connection attempt is successful. pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().remove(this); finishSuccessfully(pipeline, H1C); ctx.fireChannelActive(); } }); } }
From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java
License:Apache License
private void configureAsHttp(Channel ch) { final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(TrafficLoggingHandler.CLIENT); final boolean attemptUpgrade; switch (httpPreference) { case HTTP1_REQUIRED: attemptUpgrade = false;// w w w .j a v a 2s . c o m break; case HTTP2_PREFERRED: assert remoteAddress != null; attemptUpgrade = !SessionProtocolNegotiationCache.isUnsupported(remoteAddress, H2C); break; case HTTP2_REQUIRED: attemptUpgrade = true; break; default: // Should never reach here. throw new Error(); } if (attemptUpgrade) { final Http2ClientConnectionHandler http2Handler = newHttp2ConnectionHandler(ch); if (clientFactory.useHttp2Preface()) { pipeline.addLast(new DowngradeHandler()); pipeline.addLast(http2Handler); } else { final Http1ClientCodec http1Codec = newHttp1Codec(clientFactory.maxHttp1InitialLineLength(), clientFactory.maxHttp1HeaderSize(), clientFactory.maxHttp1ChunkSize()); final Http2ClientUpgradeCodec http2ClientUpgradeCodec = new Http2ClientUpgradeCodec(http2Handler); final HttpClientUpgradeHandler http2UpgradeHandler = new HttpClientUpgradeHandler(http1Codec, http2ClientUpgradeCodec, (int) Math.min(Integer.MAX_VALUE, UPGRADE_RESPONSE_MAX_LENGTH)); pipeline.addLast(http1Codec); pipeline.addLast(new WorkaroundHandler()); pipeline.addLast(http2UpgradeHandler); pipeline.addLast(new UpgradeRequestHandler(http2Handler.responseDecoder())); } } else { pipeline.addLast(newHttp1Codec(clientFactory.maxHttp1InitialLineLength(), clientFactory.maxHttp1HeaderSize(), clientFactory.maxHttp1ChunkSize())); // NB: We do not call finishSuccessfully() immediately here // because it assumes HttpSessionHandler to be in the pipeline, // which is only true after the connection attempt is successful. pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().remove(this); finishSuccessfully(pipeline, H1C); ctx.fireChannelActive(); } }); } }
From source file:com.linecorp.armeria.client.HttpConfigurator.java
License:Apache License
private void configureAsHttp(Channel ch) { final ChannelPipeline pipeline = ch.pipeline(); final boolean attemptUpgrade; switch (httpPreference) { case HTTP1_REQUIRED: attemptUpgrade = false;// ww w .j a va2 s .com break; case HTTP2_PREFERRED: attemptUpgrade = !SessionProtocolNegotiationCache.isUnsupported(remoteAddress, H2C); break; case HTTP2_REQUIRED: attemptUpgrade = true; break; default: // Should never reach here. throw new Error(); } if (attemptUpgrade) { if (options.useHttp2Preface()) { pipeline.addLast(new DowngradeHandler()); pipeline.addLast(newHttp2ConnectionHandler(ch)); } else { Http1ClientCodec http1Codec = newHttp1Codec(); Http2ClientUpgradeCodec http2ClientUpgradeCodec = new Http2ClientUpgradeCodec( newHttp2ConnectionHandler(ch)); HttpClientUpgradeHandler http2UpgradeHandler = new HttpClientUpgradeHandler(http1Codec, http2ClientUpgradeCodec, options.maxFrameLength()); pipeline.addLast(http1Codec); pipeline.addLast(new WorkaroundHandler()); pipeline.addLast(http2UpgradeHandler); pipeline.addLast(new UpgradeRequestHandler()); } } else { pipeline.addLast(newHttp1Codec()); // NB: We do not call finishSuccessfully() immediately here // because it assumes HttpSessionHandler to be in the pipeline, // which is only true after the connection attempt is successful. pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().remove(this); finishSuccessfully(pipeline, H1C); ctx.fireChannelActive(); } }); } }
From source file:com.mastfrog.scamper.codec.MessageCodec.java
License:Open Source License
/** * Called when the channel becomes active * * @param ctx The context/*from www. j av a 2 s .com*/ */ public void onChannelActive(ChannelHandlerContext ctx) { ctx.fireChannelActive(); }
From source file:com.netty.fileTest.file.FileReaderClientHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel();//from w ww . j a va2s . c o m ctx.fireChannelActive(); }
From source file:com.qc.you.socket.server.netty.handler.SomethingServerHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { Assert.notNull(this.channelRepository, "[Assertion failed] - ChannelRepository is required; it must not be null"); ctx.fireChannelActive(); logger.debug(ctx.channel().remoteAddress()); String channelKey = ctx.channel().remoteAddress().toString(); channelRepository.put(channelKey, ctx.channel()); ctx.writeAndFlush("Your channel key is " + channelKey + "\n\r"); logger.debug("Binded Channel Count is " + this.channelRepository.size()); }
From source file:com.soho.framework.server.netty.http.HttpServletHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { log.debug("Opening new channel: {}", ctx.channel().id()); ServletWebApp.get().getSharedChannelGroup().add(ctx.channel()); ctx.fireChannelActive(); }