@Override public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { return new FilteredConnection(transport.openConnection(node, profile)) { @Override public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { DelegateTransport.this.sendRequest(connection, requestId, action, request, options); } }; }
private Transport.Connection internalOpenConnection(DiscoveryNode node, ConnectionProfile connectionProfile) { PlainActionFuture<Transport.Connection> future = PlainActionFuture.newFuture(); Releasable pendingConnection = transport.openConnection(node, connectionProfile, future); Transport.Connection connection; try { connection = future.actionGet(); } catch (IllegalStateException e) { // If the future was interrupted we must cancel the pending connection to avoid channels leaking if (e.getCause() instanceof InterruptedException) { pendingConnection.close(); } throw e; } try { connectionListener.onConnectionOpened(connection); } finally { connection.addCloseListener(ActionListener.wrap(() -> connectionListener.onConnectionClosed(connection))); } if (connection.isClosed()) { throw new ConnectTransportException(node, "a channel closed while connecting"); } return connection; }
@Override public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { return getTransport(node).openConnection(node, profile); } }
/** * Establishes and returns a new connection to the given node. The connection is NOT maintained by this service, it's the callers * responsibility to close the connection once it goes out of scope. * @param node the node to connect to * @param profile the connection profile to use */ public Transport.Connection openConnection(final DiscoveryNode node, ConnectionProfile profile) throws IOException { if (isLocalNode(node)) { return localNodeConnection; } else { return transport.openConnection(node, profile); } }
@Override public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { TimeValue delay = getDelay(); if (delay.millis() <= 0) { return original.openConnection(node, profile); } // TODO: Replace with proper setting TimeValue connectingTimeout = TcpTransport.TCP_CONNECT_TIMEOUT.getDefault(Settings.EMPTY); try { if (delay.millis() < connectingTimeout.millis()) { Thread.sleep(delay.millis()); return original.openConnection(node, profile); } else { Thread.sleep(connectingTimeout.millis()); throw new ConnectTransportException(node, "UNRESPONSIVE: simulated"); } } catch (InterruptedException e) { throw new ConnectTransportException(node, "UNRESPONSIVE: simulated"); } }
private Transport.Connection internalOpenConnection(DiscoveryNode node, ConnectionProfile connectionProfile) { Transport.Connection connection = transport.openConnection(node, connectionProfile); try { connectionListener.onConnectionOpened(connection); } finally { connection.addCloseListener(ActionListener.wrap(() -> connectionListener.onConnectionClosed(connection))); } if (connection.isClosed()) { throw new ConnectTransportException(node, "a channel closed while connecting"); } return connection; }
private Transport.Connection internalOpenConnection(DiscoveryNode node, ConnectionProfile connectionProfile) { Transport.Connection connection = transport.openConnection(node, connectionProfile); try { connectionListener.onConnectionOpened(connection); } finally { connection.addCloseListener(ActionListener.wrap(() -> connectionListener.onConnectionClosed(connection))); } if (connection.isClosed()) { throw new ConnectTransportException(node, "a channel closed while connecting"); } return connection; }