/** * Invoked when an exception was raised by an I/O thread or a * {@link ChannelHandler}. */ public void exceptionCaught( ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { ChannelPipeline pipeline = ctx.getPipeline(); ChannelHandler last = pipeline.getLast(); if (!(last instanceof ChannelUpstreamHandler) && ctx instanceof DefaultChannelPipeline) { // The names comes in the order of which they are insert when using DefaultChannelPipeline List<String> names = ctx.getPipeline().getNames(); for (int i = names.size() - 1; i >= 0; i--) { ChannelHandler handler = ctx.getPipeline().get(names.get(i)); if (handler instanceof ChannelUpstreamHandler) { // find the last handler last = handler; break; } } } if (this == last) { logger.warn( "EXCEPTION, please implement " + getClass().getName() + ".exceptionCaught() for proper handling.", e.getCause()); } ctx.sendUpstream(e); }
@Override public ProxyServer call() throws Exception { // Configure the server. bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); FiltersChangeNotifier changeNotifier = filtersChangeNotifier != null ? filtersChangeNotifier : FiltersChangeNotifier.IGNORE; CommonHttpPipeline pipelineFactory = new CommonHttpPipeline(TIMER); changeNotifier.addFiltersListener(pipelineFactory); bootstrap.setPipelineFactory(pipelineFactory); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.connectTimeoutMillis", 2000); /*bootstrap.setOption("child.writeBufferHighWaterMark", true); bootstrap.setOption("child.writeBufferLowWaterMark", true); bootstrap.setOption("child.writeSpinCount", true);*/ bootstrap.setOption("child.receiveBufferSizePredictor", new AdaptiveReceiveBufferSizePredictor()); channel = bootstrap.bind(new InetSocketAddress(port)); LOG.info("server bound to port {}", port); LOG.info("current handlers registred {}", pipelineFactory.getPipeline().getNames()); return ProxyServer.this; } });
ctx.getPipeline().remove(Socks4ClientBootstrap.HANDSHAKE); ChannelPipeline delegatePipeline = delegate.getPipeline(); for (String name : delegatePipeline.getNames()) { ctx.getPipeline().addLast(name, delegatePipeline.get(name));
ctx.getPipeline().remove(Socks4ClientBootstrap.HANDSHAKE); ChannelPipeline delegatePipeline = delegate.getPipeline(); for (String name : delegatePipeline.getNames()) { ctx.getPipeline().addLast(name, delegatePipeline.get(name));