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.
This commit is contained in:
Tim Brooks 2018-11-30 09:04:32 -07:00 committed by GitHub
parent 370472b6d1
commit da100c5479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 15 deletions

View File

@ -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");
}
}