From e2ebabcb3ca550165ec6cfa6c4d4f02181f6b4fc Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 13 Jan 2017 12:25:35 +0100 Subject: [PATCH] Use a set rather than a list for connected nodes --- .../action/search/RemoteClusterConnection.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/RemoteClusterConnection.java b/core/src/main/java/org/elasticsearch/action/search/RemoteClusterConnection.java index 79381cc87e4..63775c17f0f 100644 --- a/core/src/main/java/org/elasticsearch/action/search/RemoteClusterConnection.java +++ b/core/src/main/java/org/elasticsearch/action/search/RemoteClusterConnection.java @@ -55,8 +55,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; @@ -81,7 +83,7 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo private final TransportService transportService; private final ConnectionProfile remoteProfile; - private final CopyOnWriteArrayList connectedNodes = new CopyOnWriteArrayList<>(); + private final Set connectedNodes = Collections.newSetFromMap(new ConcurrentHashMap<>()); private final Supplier nodeSupplier; private final String clusterAlias; private final int maxNumRemoteConnections; @@ -410,7 +412,7 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo cancellableThreads.cancel("connect handler is closed"); running.acquire(); // acquire the semaphore to ensure all connections are closed and all thread joined running.release(); - maybeConnect(); // now go an notify pending listeners + maybeConnect(); // now go and notify pending listeners } } catch (InterruptedException e) { Thread.currentThread().interrupt();