public RetryingProtocolConnection( AsyncFramework async, Timer timer, Logger log, RetryPolicy policy, ProtocolChannelSetup action ) { this.async = async; this.timer = timer; this.log = log; this.policy = policy; this.action = action; this.initialFuture = async.<ProtocolConnection>future(); trySetup(0); }
private AsyncFuture<ProtocolConnection> bindTCP( final Logger log, final Protocol protocol, ProtocolServer server, RetryPolicy policy ) { final ServerBootstrap b = new ServerBootstrap(); b.group(boss, worker); b.channel(NioServerSocketChannel.class); b.childHandler(server.initializer()); b.option(ChannelOption.SO_BACKLOG, 128); if (protocol.getReceiveBufferSize() != null) { b.childOption(ChannelOption.SO_RCVBUF, protocol.getReceiveBufferSize()); } b.childOption(ChannelOption.SO_KEEPALIVE, true); final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort(); final RetryingProtocolConnection connection = new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return b.bind(host, port); } @Override public String toString() { return String.format("bind tcp://%s:%d", host, port); } }); return connection.getInitialFuture(); }
private AsyncFuture<ProtocolConnection> connectTCP( Logger log, Protocol protocol, ProtocolClient client, RetryPolicy policy ) { final Bootstrap b = new Bootstrap(); b.group(worker); b.channel(NioSocketChannel.class); b.handler(client.initializer()); b.option(ChannelOption.SO_KEEPALIVE, true); final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort(); final ProtocolConnection connection = new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return b.connect(host, port); } @Override public String toString() { return String.format("connect tcp://%s:%d", host, port); } }); return async.resolved(connection); }
new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return connection.getInitialFuture();