List of usage examples for io.netty.channel Channel read
@Override
Channel read();
From source file:NettyHttpTransportSourceHandler.java
License:Apache License
/** * activating registered handler to accept events. * * @param ctx/* w ww .ja v a 2 s. com*/ * @throws Exception */ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { final Channel inboundChannel = ctx.channel(); Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()); b.handler(new NettyTargetHandlerInitilizer(inboundChannel)).option(ChannelOption.AUTO_READ, false); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000); b.option(ChannelOption.SO_SNDBUF, 1048576); b.option(ChannelOption.SO_RCVBUF, 1048576); ChannelFuture f = b.connect(NettyHttpListner.HOST, NettyHttpListner.HOST_PORT); outboundChannel = f.channel(); f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.flysoloing.learning.network.netty.proxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();//from w w w . java 2 s .c o m f.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.gxkj.demo.netty.proxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();/*from w w w . java 2s .co m*/ f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.hop.hhxx.example.proxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new io.netty.example.proxy.HexDumpProxyBackendHandler(inboundChannel)) .option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();//from www. j a va2s .c o m f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.hxr.javatone.concurrency.netty.official.proxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();//from w ww . j av a 2 s . c o m f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); // ??/*from w w w.j ava 2 s . co m*/ Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new GrpcProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); for (int i = 0; i < remoteHosts.length; i++) { final ChannelFuture f = b.connect(remoteHosts[i], remotePorts[i]); outboundChannels[i] = f.channel(); f.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); // System.out.println(f.channel().remoteAddress() + ", " + f.channel().localAddress()); } else { // Close the connection if the connection attempt has failed. // System.out.println("channelActive close" + inboundChannel.remoteAddress() + ", " + inboundChannel.localAddress()); inboundChannel.close(); } } }); } }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyFrontendHandler.java
License:Apache License
private void forwardThisFrame(final ChannelHandlerContext ctx, final ByteBuf copy, int streamId, final int type) { if (selectedChannel == null) { int select = (counter.getAndIncrement()) % remoteHosts.length; selectedChannel = outboundChannels[select]; }/*w w w.j a v a 2 s .co m*/ //int select = 0; // System.out.println("---------------------------------select:" + select + "," + ByteBufUtil.hexDump(copy)); final Channel inboundChannel = ctx.channel(); selectedChannel.writeAndFlush(copy).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // System.out.println("forward success ------------------------------------------type=" + type); inboundChannel.read(); } else { // System.out.println("forward failure------------------------------------------"); inboundChannel.close(); } } }); }
From source file:com.repo.netty.proxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();/*from ww w. j av a2 s . co m*/ f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.sangupta.swift.netty.proxy.ProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext channelHandlerContext) { final Channel inboundChannel = channelHandlerContext.channel(); // Start the connection attempt. Bootstrap bootstrap = new Bootstrap(); bootstrap.group(inboundChannel.eventLoop()).channel(channelHandlerContext.channel().getClass()) .handler(new ProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture channelFuture = bootstrap.connect(remoteHost, remotePort); outboundChannel = channelFuture.channel(); channelFuture.addListener(new ChannelFutureListener() { @Override/*from w w w .ja v a 2 s . c om*/ public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:com.tc.websocket.server.handler.ProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); this.handler = new ProxyBackendHandler(inboundChannel); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()).handler(this.handler) .option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();/*from w ww . j a v a 2s. c om*/ f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }