From da100c5479ba3796a52618f0dd12009bc674fc35 Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Fri, 30 Nov 2018 09:04:32 -0700 Subject: [PATCH] Remove `Lifecycle` from `ConnectionManager` (#36092) Prior to #35441 `ConnectionManager` had a `Lifecycle` object to support the ping runnable. After that commit, the connection amanger only needs the existing `AtomicBoolean` to indicate if it is running. --- .../transport/ConnectionManager.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/ConnectionManager.java b/server/src/main/java/org/elasticsearch/transport/ConnectionManager.java index 102056e8698..f113297b506 100644 --- a/server/src/main/java/org/elasticsearch/transport/ConnectionManager.java +++ b/server/src/main/java/org/elasticsearch/transport/ConnectionManager.java @@ -24,7 +24,6 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.CheckedBiConsumer; -import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; @@ -58,8 +57,7 @@ public class ConnectionManager implements Closeable { private final Transport transport; private final ThreadPool threadPool; private final ConnectionProfile defaultProfile; - private final Lifecycle lifecycle = new Lifecycle(); - private final AtomicBoolean closed = new AtomicBoolean(false); + private final AtomicBoolean isClosed = new AtomicBoolean(false); private final ReadWriteLock closeLock = new ReentrantReadWriteLock(); private final DelegatingNodeConnectionListener connectionListener = new DelegatingNodeConnectionListener(); @@ -71,7 +69,6 @@ public class ConnectionManager implements Closeable { this.transport = transport; this.threadPool = threadPool; this.defaultProfile = connectionProfile; - this.lifecycle.moveToStarted(); } public void addListener(TransportConnectionListener listener) { @@ -187,8 +184,7 @@ public class ConnectionManager implements Closeable { @Override public void close() { - if (closed.compareAndSet(false, true)) { - lifecycle.moveToStopped(); + if (isClosed.compareAndSet(false, true)) { CountDownLatch latch = new CountDownLatch(1); // TODO: Consider moving all read/write lock (in Transport and this class) to the TransportService @@ -213,14 +209,10 @@ public class ConnectionManager implements Closeable { }); try { - try { - latch.await(30, TimeUnit.SECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - // ignore - } - } finally { - lifecycle.moveToClosed(); + latch.await(30, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + // ignore } } } @@ -239,7 +231,7 @@ public class ConnectionManager implements Closeable { } private void ensureOpen() { - if (lifecycle.started() == false) { + if (isClosed.get()) { throw new IllegalStateException("connection manager is closed"); } }