/** * Creates a client. * * @param address remote address * @param connectStrategy Reconnection strategy to be used when initial connection fails * * @return Future representing the connection process. Its result represents the combined success of TCP connection * as well as session negotiation. */ protected Future<S> createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final PipelineInitializer<S> initializer) { final Bootstrap b = new Bootstrap(); final ProtocolSessionPromise<S> p = new ProtocolSessionPromise<>(executor, address, strategy, b); b.option(ChannelOption.SO_KEEPALIVE, true).handler( new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) { initializer.initializeChannel(ch, p); } }); customizeBootstrap(b); setWorkerGroup(b); setChannelFactory(b); p.connect(); LOG.debug("Client created."); return p; }
/** * Creates a reconnecting client. * * @param address remote address * @param connectStrategyFactory Factory for creating reconnection strategy for every reconnect attempt * * @return Future representing the reconnection task. It will report completion based on reestablishStrategy, e.g. * success is never reported, only failure when it runs out of reconnection attempts. */ protected Future<Void> createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory connectStrategyFactory, final PipelineInitializer<S> initializer) { final Bootstrap b = new Bootstrap(); final ReconnectPromise<S, L> p = new ReconnectPromise<>(GlobalEventExecutor.INSTANCE, this, address, connectStrategyFactory, b, initializer); b.option(ChannelOption.SO_KEEPALIVE, true); customizeBootstrap(b); setWorkerGroup(b); setChannelFactory(b); p.connect(); return p; }