-
- /**
- * Indicate if the initial connection succeeded.
- *
- * @return true if initial connection was established successfully, false if initial connection failed due to e.g.
- * Connection refused, Negotiation failed
- */
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private synchronized boolean isInitialConnectFinished() {
- requireNonNull(pending);
- return pending.isDone() && pending.isSuccess();
- }
-
- @Override
- public synchronized boolean cancel(final boolean mayInterruptIfRunning) {
- if (super.cancel(mayInterruptIfRunning)) {
- requireNonNull(pending);
- this.pending.cancel(mayInterruptIfRunning);
- return true;
- }
-
- return false;
- }
-
- /**
- * Channel handler that responds to channelInactive event and reconnects the session.
- * Only if the promise was not canceled.
- */
- private static final class ClosedChannelHandler extends ChannelInboundHandlerAdapter {
- private final ReconnectPromise<?, ?> promise;
-
- ClosedChannelHandler(final ReconnectPromise<?, ?> promise) {
- this.promise = promise;
- }
-
- @Override
- public void channelInactive(final ChannelHandlerContext ctx) {
- // This is the ultimate channel inactive handler, not forwarding
- if (promise.isCancelled()) {
- return;
- }
-
- if (promise.isInitialConnectFinished() == false) {
- LOG.debug("Connection to {} was dropped during negotiation, reattempting", promise.address);
- }
-
- LOG.debug("Reconnecting after connection to {} was dropped", promise.address);
- promise.connect();
- }
- }