public NetworkFailuresProxy(int localPort, String remoteHost, int remotePort) { // Configure the bootstrap. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(executor, executor)); // Set up the event pipeline factory. ClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(executor, executor); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // synchronized for a race between blocking and creating new handlers synchronized (networkFailureHandlers) { NetworkFailureHandler failureHandler = new NetworkFailureHandler( blocked, networkFailureHandler -> networkFailureHandlers.remove(networkFailureHandler), channelFactory, remoteHost, remotePort); networkFailureHandlers.add(failureHandler); pipeline.addLast(NETWORK_FAILURE_HANDLER_NAME, failureHandler); } return pipeline; } }); channel = serverBootstrap.bind(new InetSocketAddress(localPort)); LOG.info("Proxying [*:{}] to [{}:{}]", getLocalPort(), remoteHost, remotePort); }
public NetworkFailuresProxy(int localPort, String remoteHost, int remotePort) { // Configure the bootstrap. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(executor, executor)); // Set up the event pipeline factory. ClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(executor, executor); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // synchronized for a race between blocking and creating new handlers synchronized (networkFailureHandlers) { NetworkFailureHandler failureHandler = new NetworkFailureHandler( blocked, networkFailureHandler -> networkFailureHandlers.remove(networkFailureHandler), channelFactory, remoteHost, remotePort); networkFailureHandlers.add(failureHandler); pipeline.addLast(NETWORK_FAILURE_HANDLER_NAME, failureHandler); } return pipeline; } }); channel = serverBootstrap.bind(new InetSocketAddress(localPort)); LOG.info("Proxying [*:{}] to [{}:{}]", getLocalPort(), remoteHost, remotePort); }
public NetworkFailuresProxy(int localPort, String remoteHost, int remotePort) { // Configure the bootstrap. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(executor, executor)); // Set up the event pipeline factory. ClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(executor, executor); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // synchronized for a race between blocking and creating new handlers synchronized (networkFailureHandlers) { NetworkFailureHandler failureHandler = new NetworkFailureHandler( blocked, networkFailureHandler -> networkFailureHandlers.remove(networkFailureHandler), channelFactory, remoteHost, remotePort); networkFailureHandlers.add(failureHandler); pipeline.addLast(NETWORK_FAILURE_HANDLER_NAME, failureHandler); } return pipeline; } }); channel = serverBootstrap.bind(new InetSocketAddress(localPort)); LOG.info("Proxying [*:{}] to [{}:{}]", getLocalPort(), remoteHost, remotePort); }
public NetworkFailuresProxy(int localPort, String remoteHost, int remotePort) { // Configure the bootstrap. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(executor, executor)); // Set up the event pipeline factory. ClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(executor, executor); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // synchronized for a race between blocking and creating new handlers synchronized (networkFailureHandlers) { NetworkFailureHandler failureHandler = new NetworkFailureHandler( blocked, networkFailureHandler -> networkFailureHandlers.remove(networkFailureHandler), channelFactory, remoteHost, remotePort); networkFailureHandlers.add(failureHandler); pipeline.addLast(NETWORK_FAILURE_HANDLER_NAME, failureHandler); } return pipeline; } }); channel = serverBootstrap.bind(new InetSocketAddress(localPort)); LOG.info("Proxying [*:{}] to [{}:{}]", getLocalPort(), remoteHost, remotePort); }