/** * Returns a connection for the given node if the node is connected. * Connections returned from this method must not be closed. The lifecycle of this connection is * maintained by this connection manager * * @throws NodeNotConnectedException if the node is not connected * @see #connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer) */ public Transport.Connection getConnection(DiscoveryNode node) { Transport.Connection connection = connectedNodes.get(node); if (connection == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return connection; }
@Override public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { if (isClosing.get()) { throw new NodeNotConnectedException(node, "connection already closed"); } TcpChannel channel = channel(options.type()); sendRequestToChannel(this.node, channel, requestId, action, request, options, getVersion(), compress, (byte) 0); } }
throw new NodeNotConnectedException(node, "connection concurrently closed");
@Override public NodeChannels getConnection(DiscoveryNode node) { NodeChannels nodeChannels = connectedNodes.get(node); if (nodeChannels == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return nodeChannels; }
throw new NodeNotConnectedException(node, " got disconnected");
/** * Returns a connection for the given node if the node is connected. * Connections returned from this method must not be closed. The lifecycle of this connection is * maintained by this connection manager * * @throws NodeNotConnectedException if the node is not connected * @see #connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer) */ public Transport.Connection getConnection(DiscoveryNode node) { Transport.Connection connection = connectedNodes.get(node); if (connection == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return connection; }
/** * Returns a connection for the given node if the node is connected. * Connections returned from this method must not be closed. The lifecycle of this connection is * maintained by this connection manager * * @throws NodeNotConnectedException if the node is not connected * @see #connectToNode(DiscoveryNode, ConnectionProfile, CheckedBiConsumer) */ public Transport.Connection getConnection(DiscoveryNode node) { Transport.Connection connection = connectedNodes.get(node); if (connection == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return connection; }
@Override public Connection getConnection(DiscoveryNode node) { final LocalTransport targetTransport = connectedNodes.get(node); if (targetTransport == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return getConnectionForTransport(targetTransport, node, true); }
protected Channel nodeChannel(DiscoveryNode node, TransportRequestOptions options) throws ConnectTransportException { NodeChannels nodeChannels = connectedNodes.get(node); if (nodeChannels == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return nodeChannels.channel(options.type()); }
private Channel nodeChannel(DiscoveryNode node, TransportRequestOptions options) throws ConnectTransportException { NodeChannels nodeChannels = connectedNodes.get(node); if (nodeChannels == null) { throw new NodeNotConnectedException(node, "Node not connected"); } return nodeChannels.channel(options.type()); }
@Override public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { if (transports.get(node.getAddress()) != targetTransport) { // we double check that we are still connected since due to the nature of local transport we won't get any errors // when we send to a closed / disconnected transport. Yet, if the target transport is closed concurrently before // the transport service registers the client handler local transport will simply ignore the request which can cause // requests to hang. By checking again here we guarantee to throw an exception which causes the client handler to run // in such a situation, if the client handler is not registered yet when the connections is obtained. throw new NodeNotConnectedException(node, " got disconnected"); } LocalTransport.this.sendRequest(targetTransport, node, requestId, action, request, options); }
@Override public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { if (isClosing.get()) { throw new NodeNotConnectedException(node, "connection already closed"); } TcpChannel channel = channel(options.type()); sendRequestToChannel(this.node, channel, requestId, action, request, options, getVersion(), (byte) 0); } }
@Override public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { if (closed.get()) { throw new NodeNotConnectedException(node, "connection already closed"); } TcpChannel channel = channel(options.type()); sendRequestToChannel(this.node, channel, requestId, action, request, options, getVersion(), (byte) 0); }
throw new NodeNotConnectedException(node, "connection concurrently closed");
throw new NodeNotConnectedException(node, "connection concurrently closed");
@Override public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { final Version version = Version.smallest(node.version(), this.version); try (BytesStreamOutput stream = new BytesStreamOutput()) { stream.setVersion(version); stream.writeLong(requestId); byte status = 0; status = TransportStatus.setRequest(status); stream.writeByte(status); // 0 for request, 1 for response. stream.writeString(action); request.writeTo(stream); stream.close(); final LocalTransport targetTransport = connectedNodes.get(node); if (targetTransport == null) { throw new NodeNotConnectedException(node, "Node not connected"); } final byte[] data = stream.bytes().toBytes(); transportServiceAdapter.sent(data.length); transportServiceAdapter.onRequestSent(node, requestId, action, request, options); targetTransport.workers().execute(new Runnable() { @Override public void run() { targetTransport.messageReceived(data, action, LocalTransport.this, version, requestId); } }); } }