List of usage examples for io.netty.channel ChannelOption AUTO_READ
ChannelOption AUTO_READ
To view the source code for io.netty.channel ChannelOption AUTO_READ.
Click Source Link
From source file:com.proxy.ProxyServer.java
License:Apache License
public void start(final String remoteHost, final int remotePort) throws InterruptedException { System.err.println("Proxying *:" + LOCAL_PORT + " to " + REMOTE_HOST + ':' + REMOTE_PORT + " ..."); // Configure the bootstrap. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from w w w. j a v a 2 s .c o m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ProxyChannelInit(remoteHost, remotePort)) .childOption(ChannelOption.AUTO_READ, false).bind(LOCAL_PORT).sync().channel().closeFuture() .sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
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();//ww w . jav 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(); } } }); }
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 ww w . ja va2 s . c o m 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.ReverseProxyServer.java
License:Apache License
public ReverseProxyServer(SwiftServer server) { this.bossGroup = new NioEventLoopGroup(1); this.workerGroup = new NioEventLoopGroup(); try {// ww w . j a va 2s .c o m this.serverBootstrap = new ServerBootstrap(); this.serverBootstrap.group(this.bossGroup, this.workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ProxyInitializer(server.getProxyHost(), server.getProxyPort())) .childOption(ChannelOption.AUTO_READ, false); this.channel = this.serverBootstrap.bind(server.getListenPort()).sync().channel(); System.out.println("Listening on port " + server.getListenPort()); this.channel.closeFuture().sync(); } catch (InterruptedException e) { // TODO: think what we can do with this e.printStackTrace(); } finally { this.shutdownGracefully(); } }
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();// w w w . j a v a 2 s . com 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.tesora.dve.parlb.MysqlClientHandler.java
License:Open Source 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(NioSocketChannel.class) .handler(new LoadBalancerServerHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(peServerAddress); outboundChannel = f.channel();//from w w w. ja va2s.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.tesora.dve.standalone.LoadBalancer.java
License:Open Source License
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(0, new DefaultThreadFactory("lb-boss")); EventLoopGroup workerGroup = new NioEventLoopGroup(0, new DefaultThreadFactory("lb-worker")); ServerBootstrap b = new ServerBootstrap(); try {/*from ww w. j a va 2s . c om*/ b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(proxyInitializer) .childOption(ChannelOption.AUTO_READ, false).bind(lbPort).sync().channel().closeFuture().sync(); } catch (Throwable e) { throw new Exception("Failed to start load balancer on port " + lbPort, e); } finally { // b.shutdown(); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); proxyInitializer.close(); } }
From source file:com.TestWebServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the bootstrap. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//w w w.j a va 2 s .c o m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ch.pipeline().addLast(new StringEncoder(), new HttpServerCodec(), new HttpObjectAggregator(512 * 1024 * 1024), new WebHandler()); } }).childOption(ChannelOption.AUTO_READ, false).bind(LOCAL_PORT).sync().channel().closeFuture() .sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.xx_dev.apn.proxy.ApnProxyRelayHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { LoggerUtil.debug(logger, ctx.channel().attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), tag, "channel active"); if (!ctx.channel().config().getOption(ChannelOption.AUTO_READ)) { ctx.read();/*from w w w .j a v a 2s.co m*/ } }
From source file:com.xx_dev.apn.proxy.ApnProxyRelayHandler.java
License:Apache License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { LoggerUtil.debug(logger, ctx.channel().attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), tag, msg); if (relayChannel.isActive()) { relayChannel.writeAndFlush(msg).addListener(new ChannelFutureListener() { @Override// w w w.j av a2s. co m public void operationComplete(ChannelFuture future) throws Exception { if (!ctx.channel().config().getOption(ChannelOption.AUTO_READ)) { ctx.read(); } } }); } else { ReferenceCountUtil.release(msg); } }