public Connection getOrConnect(DiscoveryNode node) throws IOException { Connection result; try (Releasable ignore = connectionLock.acquire(node.getAddress())) { result = tempConnections.get(node.getAddress()); if (result == null) { ensureOpen(); boolean success = false; logger.trace("[{}] opening connection to [{}]", id(), node); result = transportService.openConnection(node, connectionProfile); try { transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis()); synchronized (this) { // acquire lock and check if closed, to prevent leaving an open connection after closing ensureOpen(); Connection existing = tempConnections.put(node.getAddress(), result); assert existing == null; success = true; } } finally { if (success == false) { logger.trace("[{}] closing connection to [{}] due to failure", id(), node); IOUtils.closeWhileHandlingException(result); } } } } return result; }
connectionToClose = transportService.openConnection(nodeToPing, LISTED_NODES_PROFILE); pingConnection = connectionToClose;
ArrayList<DiscoveryNode> newFilteredNodes = new ArrayList<>(); for (DiscoveryNode listedNode : listedNodes) { try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){ final PlainTransportFuture<LivenessResponse> handler = new PlainTransportFuture<>( new FutureTransportResponseHandler<LivenessResponse>() {
@Override public Transport.Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { FilteredConnection filteredConnection = new FilteredConnection(super.openConnection(node, profile)) { final AtomicBoolean closed = new AtomicBoolean(false); @Override public void close() throws IOException { try { super.close(); } finally { if (closed.compareAndSet(false, true)) { synchronized (openConnections) { List<Transport.Connection> connections = openConnections.get(node); boolean remove = connections.remove(this); assert remove; if (connections.isEmpty()) { openConnections.remove(node); } } } } } }; synchronized (openConnections) { List<Transport.Connection> connections = openConnections.computeIfAbsent(node, (n) -> new CopyOnWriteArrayList<>()); connections.add(filteredConnection); } return filteredConnection; }
IOUtils.close(service.openConnection(first, builder.build())); builder.setConnectTimeout(TimeValue.timeValueMillis(1)); final ConnectionProfile profile = builder.build(); ConnectTransportException ex = expectThrows(ConnectTransportException.class, () -> service.openConnection(second, profile)); final long now = System.nanoTime(); final long timeTaken = TimeValue.nsecToMSec(now - startTime);
public Connection getOrConnect(DiscoveryNode node) throws IOException { Connection result; try (Releasable ignore = connectionLock.acquire(node.getAddress())) { result = tempConnections.get(node.getAddress()); if (result == null) { ensureOpen(); boolean success = false; logger.trace("[{}] opening connection to [{}]", id(), node); result = transportService.openConnection(node, connectionProfile); try { transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis()); synchronized (this) { // acquire lock and check if closed, to prevent leaving an open connection after closing ensureOpen(); Connection existing = tempConnections.put(node.getAddress(), result); assert existing == null; success = true; } } finally { if (success == false) { logger.trace("[{}] closing connection to [{}] due to failure", id(), node); IOUtils.closeWhileHandlingException(result); } } } } return result; }
public Connection getOrConnect(DiscoveryNode node) throws IOException { Connection result; try (Releasable ignore = connectionLock.acquire(node.getAddress())) { result = tempConnections.get(node.getAddress()); if (result == null) { ensureOpen(); boolean success = false; logger.trace("[{}] opening connection to [{}]", id(), node); result = transportService.openConnection(node, connectionProfile); try { transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis()); synchronized (this) { // acquire lock and check if closed, to prevent leaving an open connection after closing ensureOpen(); Connection existing = tempConnections.put(node.getAddress(), result); assert existing == null; success = true; } } finally { if (success == false) { logger.trace("[{}] closing connection to [{}] due to failure", id(), node); IOUtils.closeWhileHandlingException(result); } } } } return result; }
public Connection getOrConnect(DiscoveryNode node) throws IOException { Connection result; try (Releasable ignore = connectionLock.acquire(node.getAddress())) { result = tempConnections.get(node.getAddress()); if (result == null) { ensureOpen(); boolean success = false; logger.trace("[{}] opening connection to [{}]", id(), node); result = transportService.openConnection(node, connectionProfile); try { transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis()); synchronized (this) { // acquire lock and check if closed, to prevent leaving an open connection after closing ensureOpen(); Connection existing = tempConnections.put(node.getAddress(), result); assert existing == null; success = true; } } finally { if (success == false) { logger.trace("[{}] closing connection to [{}] due to failure", id(), node); IOUtils.closeWhileHandlingException(result); } } } } return result; }
HashSet<DiscoveryNode> newFilteredNodes = new HashSet<>(); for (DiscoveryNode listedNode : listedNodes) { try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){ final PlainTransportFuture<LivenessResponse> handler = new PlainTransportFuture<>( new FutureTransportResponseHandler<LivenessResponse>() {
connectionToClose = transportService.openConnection(nodeToPing, LISTED_NODES_PROFILE); pingConnection = connectionToClose;
connectionToClose = transportService.openConnection(nodeToPing, LISTED_NODES_PROFILE); pingConnection = connectionToClose;
ArrayList<DiscoveryNode> newFilteredNodes = new ArrayList<>(); for (DiscoveryNode listedNode : listedNodes) { try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){ final PlainTransportFuture<LivenessResponse> handler = new PlainTransportFuture<>( new FutureTransportResponseHandler<LivenessResponse>() {
final DiscoveryNode seedNode = seedNodes.next(); final DiscoveryNode handshakeNode; Transport.Connection connection = transportService.openConnection(seedNode, ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG, null, null)); boolean success = false;