RequestFuture<T> (final UUID messageId, MessageLite message, final @Nullable T responseHandler, final @Nullable RequestFuture.CancelAction<T> cancelAction) { final RequestFuture<T> requestFuture = new RequestFuture<>(responseHandler, messageId, cancelAction); myMessageHandler.registerFuture(messageId, requestFuture); final ChannelFuture connectFuture = myConnectFuture; final Channel channel = connectFuture != null? connectFuture.channel() : null; if (channel != null && channel.isActive()) { channel.writeAndFlush(message).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (!future.isSuccess()) { notifyTerminated(messageId, requestFuture, responseHandler); } } }); } else { notifyTerminated(messageId, requestFuture, responseHandler); } return requestFuture; }