From: Robert Varga Date: Tue, 31 May 2022 18:35:08 +0000 (+0200) Subject: Eliminate ReconnectingStrategyListener X-Git-Tag: v4.0.0~66 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=0cca635f76cb935c3a8d8bb62abe3e9383276a0c Eliminate ReconnectingStrategyListener Use a private method and a lambda to make the lifecycle cleared. Change-Id: Ie57025a7fe60830ca2711272748b1ed6ea84dbdf Signed-off-by: Robert Varga --- diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java index 6cb4ba59c9..6136452a3b 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java @@ -16,7 +16,6 @@ import io.netty.channel.ChannelFutureListener; import io.netty.util.concurrent.DefaultPromise; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.Promise; import java.net.InetSocketAddress; import org.checkerframework.checker.lock.qual.GuardedBy; @@ -109,32 +108,28 @@ final class NetconfSessionPromise extends DefaultPromi LOG.debug("Attempt to connect to {} failed", address, cf.cause()); final Future rf = strategy.scheduleReconnect(cf.cause()); - rf.addListener(new ReconnectingStrategyListener()); + rf.addListener(this::reconnectFutureComplete); pending = rf; } - private class ReconnectingStrategyListener implements FutureListener { - @Override - public void operationComplete(final Future sf) { - synchronized (NetconfSessionPromise.this) { - // Triggered when a connection attempt is to be made. - checkState(pending.equals(sf)); - - /* - * The promise we gave out could have been cancelled, - * which cascades to the reconnect attempt getting - * cancelled, but there is a slight race window, where - * the reconnect attempt is already enqueued, but the - * listener has not yet been notified -- if cancellation - * happens at that point, we need to catch it here. - */ - if (!isCancelled()) { - if (sf.isSuccess()) { - connect(); - } else { - setFailure(sf.cause()); - } - } + // Triggered when a connection attempt is to be made. + private synchronized void reconnectFutureComplete(final Future sf) { + LOG.debug("Promise {} strategy triggered reconnect", this); + checkState(pending.equals(sf)); + + /* + * The promise we gave out could have been cancelled, + * which cascades to the reconnect attempt getting + * cancelled, but there is a slight race window, where + * the reconnect attempt is already enqueued, but the + * listener has not yet been notified -- if cancellation + * happens at that point, we need to catch it here. + */ + if (!isCancelled()) { + if (sf.isSuccess()) { + connect(); + } else { + setFailure(sf.cause()); } } }