private static void initIfNecessary() { if (executorService == null || executorService.isShutdown()) { executorService = Executors.newScheduledThreadPool(1); } if (shaper == null) { shaper = new GlobalTrafficShapingHandler(executorService, 500); } }
private static void initIfNecessary() { if (executorService == null || executorService.isShutdown()) { executorService = Executors.newScheduledThreadPool(1); } if (shaper == null) { shaper = new GlobalTrafficShapingHandler(executorService, 500); } }
/** * Creates a new GlobalTrafficShapingHandler for this HttpProxyServer, using this proxy's proxyToServerEventLoop. * * @param transportProtocol * @param readThrottleBytesPerSecond * @param writeThrottleBytesPerSecond * * @return */ private GlobalTrafficShapingHandler createGlobalTrafficShapingHandler(TransportProtocol transportProtocol, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) { EventLoopGroup proxyToServerEventLoop = this.getProxyToServerWorkerFor(transportProtocol); return new GlobalTrafficShapingHandler(proxyToServerEventLoop, writeThrottleBytesPerSecond, readThrottleBytesPerSecond, TRAFFIC_SHAPING_CHECK_INTERVAL_MS, Long.MAX_VALUE); }
/** * Creates a new GlobalTrafficShapingHandler for this HttpProxyServer, using this proxy's proxyToServerEventLoop. * * @param transportProtocol * @param readThrottleBytesPerSecond * @param writeThrottleBytesPerSecond * * @return */ private GlobalTrafficShapingHandler createGlobalTrafficShapingHandler(TransportProtocol transportProtocol, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) { EventLoopGroup proxyToServerEventLoop = this.getProxyToServerWorkerFor(transportProtocol); return new GlobalTrafficShapingHandler(proxyToServerEventLoop, writeThrottleBytesPerSecond, readThrottleBytesPerSecond, TRAFFIC_SHAPING_CHECK_INTERVAL_MS, Long.MAX_VALUE); }
protected void initChannel(SocketChannel socketChannel) throws Exception { socketChannel.pipeline() .addLast("logging", new LoggingHandler(LogLevel.DEBUG)) .addLast(new XConnectHandler()); if (config.getReadLimit() != 0 || config.getWriteLimit() != 0) { socketChannel.pipeline().addLast( new GlobalTrafficShapingHandler(Executors.newScheduledThreadPool(1), config.getWriteLimit(), config.getReadLimit()) ); } } });
public void start() { try { Config config = ConfigXmlLoader.load(CONFIG); PacLoader.load(PAC); RemoteServerManager.init(config); bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); bootstrap = new ServerBootstrap(); trafficHandler = new GlobalTrafficShapingHandler(Executors.newScheduledThreadPool(1), 1000); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new SocksServerInitializer(trafficHandler)); logger.info("Start At Port " + config.get_localPort()); startMBean(); bootstrap.bind(config.get_localPort()).sync().channel().closeFuture().sync(); } catch (Exception e) { logger.error("start error", e); } finally { stop(); } }
public static void init() throws Exception { if (INSTANCE != null) { return; } log.info("\tLoading configuration file..."); load(); log.info("\tChecking configuration items..."); check(); if (INSTANCE.relayPort.length > 0) { log.info("\tStarting Relays..."); startupRelays(); } log.info("\tInitializing dns cache..."); DnsCache.init(INSTANCE.dnsCacheCapacity); log.info("\tInitializing global network traffic handler..."); TRAFFIC_HANDLER = new GlobalTrafficShapingHandler(Executors.newScheduledThreadPool(1), 1000); TRAFFIC_HANDLER.setWriteLimit(INSTANCE.writeLimit); TRAFFIC_HANDLER.setReadLimit(INSTANCE.readLimit); log.info("\tEnd of configuration"); }
if (limitRead) { if (globalLimit) { handler = new GlobalTrafficShapingHandler(groupForGlobal, 0, bandwidthFactor * messageSize, check); } else { handler = new ChannelTrafficShapingHandler(0, bandwidthFactor * messageSize, check); handler = new GlobalTrafficShapingHandler(groupForGlobal, bandwidthFactor * messageSize, 0, check); } else { handler = new ChannelTrafficShapingHandler(bandwidthFactor * messageSize, 0, check);