Class TransportService

java.lang.Object
org.elasticsearch.common.component.AbstractLifecycleComponent
org.elasticsearch.transport.TransportService
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable, LifecycleComponent, Releasable, ReportingService<TransportInfo>, TransportConnectionListener, TransportMessageListener

public class TransportService
extends AbstractLifecycleComponent
implements ReportingService<TransportInfo>, TransportMessageListener, TransportConnectionListener
  • Field Details

    • DIRECT_RESPONSE_PROFILE

      public static final java.lang.String DIRECT_RESPONSE_PROFILE
      See Also:
      Constant Field Values
    • HANDSHAKE_ACTION_NAME

      public static final java.lang.String HANDSHAKE_ACTION_NAME
      See Also:
      Constant Field Values
    • transport

      protected final Transport transport
    • connectionManager

      protected final ConnectionManager connectionManager
    • threadPool

      protected final ThreadPool threadPool
    • clusterName

      protected final ClusterName clusterName
    • taskManager

      protected final TaskManager taskManager
    • NOOP_TRANSPORT_INTERCEPTOR

      public static final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR
    • VALID_ACTION_PREFIXES

      public static final java.util.Set<java.lang.String> VALID_ACTION_PREFIXES
      A set of all valid action prefixes.
  • Constructor Details

  • Method Details

    • getRemoteClusterService

      public RemoteClusterService getRemoteClusterService()
    • getLocalNode

      public DiscoveryNode getLocalNode()
    • getLocalNodeConnection

      public Transport.Connection getLocalNodeConnection()
    • getTaskManager

      public TaskManager getTaskManager()
    • createTaskManager

      protected TaskManager createTaskManager​(Settings settings, ThreadPool threadPool, java.util.Set<java.lang.String> taskHeaders)
    • doStart

      protected void doStart()
      Specified by:
      doStart in class AbstractLifecycleComponent
    • doStop

      protected void doStop()
      Specified by:
      doStop in class AbstractLifecycleComponent
    • doClose

      protected void doClose() throws java.io.IOException
      Specified by:
      doClose in class AbstractLifecycleComponent
      Throws:
      java.io.IOException
    • acceptIncomingRequests

      public final void acceptIncomingRequests()
      start accepting incoming requests. when the transport layer starts up it will block any incoming requests until this method is called
    • info

      public TransportInfo info()
      Specified by:
      info in interface ReportingService<TransportInfo>
    • stats

      public TransportStats stats()
    • isTransportSecure

      public boolean isTransportSecure()
    • boundAddress

      public BoundTransportAddress boundAddress()
    • getDefaultSeedAddresses

      public java.util.List<java.lang.String> getDefaultSeedAddresses()
    • nodeConnected

      public boolean nodeConnected​(DiscoveryNode node)
      Returns true iff the given node is already connected.
    • connectToNode

      public void connectToNode​(DiscoveryNode node) throws ConnectTransportException
      Connect to the specified node with the default connection profile
      Parameters:
      node - the node to connect to
      Throws:
      ConnectTransportException
    • connectToNode

      public void connectToNode​(DiscoveryNode node, ConnectionProfile connectionProfile)
      Connect to the specified node with the given connection profile
      Parameters:
      node - the node to connect to
      connectionProfile - the connection profile to use when connecting to this node
    • connectToNode

      public void connectToNode​(DiscoveryNode node, ActionListener<java.lang.Void> listener) throws ConnectTransportException
      Connect to the specified node with the given connection profile. The ActionListener will be called on the calling thread or the generic thread pool.
      Parameters:
      node - the node to connect to
      listener - the action listener to notify
      Throws:
      ConnectTransportException
    • connectToNode

      public void connectToNode​(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<java.lang.Void> listener)
      Connect to the specified node with the given connection profile. The ActionListener will be called on the calling thread or the generic thread pool.
      Parameters:
      node - the node to connect to
      connectionProfile - the connection profile to use when connecting to this node
      listener - the action listener to notify
    • connectionValidator

      public ConnectionManager.ConnectionValidator connectionValidator​(DiscoveryNode node)
    • openConnection

      public Transport.Connection openConnection​(DiscoveryNode node, ConnectionProfile connectionProfile)
      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. The ActionListener will be called on the calling thread or the generic thread pool.
      Parameters:
      node - the node to connect to
      connectionProfile - the connection profile to use
    • openConnection

      public void openConnection​(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener)
      Establishes 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. The ActionListener will be called on the calling thread or the generic thread pool.
      Parameters:
      node - the node to connect to
      connectionProfile - the connection profile to use
      listener - the action listener to notify
    • handshake

      public void handshake​(Transport.Connection connection, org.elasticsearch.common.unit.TimeValue handshakeTimeout, ActionListener<DiscoveryNode> listener)
      Executes a high-level handshake using the given connection and returns the discovery node of the node the connection was established with. The handshake will fail if the cluster name on the target node mismatches the local cluster name. The ActionListener will be called on the calling thread or the generic thread pool.
      Parameters:
      connection - the connection to a specific node
      handshakeTimeout - handshake timeout
      listener - action listener to notify
      Throws:
      ConnectTransportException - if the connection failed
      java.lang.IllegalStateException - if the handshake failed
    • handshake

      public void handshake​(Transport.Connection connection, org.elasticsearch.common.unit.TimeValue handshakeTimeout, java.util.function.Predicate<ClusterName> clusterNamePredicate, ActionListener<TransportService.HandshakeResponse> listener)
      Executes a high-level handshake using the given connection and returns the discovery node of the node the connection was established with. The handshake will fail if the cluster name on the target node doesn't match the local cluster name. The ActionListener will be called on the calling thread or the generic thread pool.
      Parameters:
      connection - the connection to a specific node
      handshakeTimeout - handshake timeout
      clusterNamePredicate - cluster name validation predicate
      listener - action listener to notify
      Throws:
      java.lang.IllegalStateException - if the handshake failed
    • getConnectionManager

      public ConnectionManager getConnectionManager()
    • disconnectFromNode

      public void disconnectFromNode​(DiscoveryNode node)
    • addMessageListener

      public void addMessageListener​(TransportMessageListener listener)
    • removeMessageListener

      public boolean removeMessageListener​(TransportMessageListener listener)
    • addConnectionListener

      public void addConnectionListener​(TransportConnectionListener listener)
    • removeConnectionListener

      public void removeConnectionListener​(TransportConnectionListener listener)
    • submitRequest

      public <T extends TransportResponse> TransportFuture<T> submitRequest​(DiscoveryNode node, java.lang.String action, TransportRequest request, TransportResponseHandler<T> handler) throws TransportException
      Throws:
      TransportException
    • submitRequest

      public <T extends TransportResponse> TransportFuture<T> submitRequest​(DiscoveryNode node, java.lang.String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) throws TransportException
      Throws:
      TransportException
    • sendRequest

      public <T extends TransportResponse> void sendRequest​(DiscoveryNode node, java.lang.String action, TransportRequest request, TransportResponseHandler<T> handler)
    • sendRequest

      public final <T extends TransportResponse> void sendRequest​(DiscoveryNode node, java.lang.String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler)
    • unwrapConnection

      public static Transport.Connection unwrapConnection​(Transport.Connection connection)
      Unwraps and returns the actual underlying connection of the given connection.
    • sendRequest

      public final <T extends TransportResponse> void sendRequest​(Transport.Connection connection, java.lang.String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler)
      Sends a request on the specified connection. If there is a failure sending the request, the specified handler is invoked.
      Type Parameters:
      T - the type of the transport response
      Parameters:
      connection - the connection to send the request on
      action - the name of the action
      request - the request
      options - the options for this request
      handler - the response handler
    • getConnection

      public Transport.Connection getConnection​(DiscoveryNode node)
      Returns either a real transport connection or a local node connection if we are using the local node optimization.
      Throws:
      NodeNotConnectedException - if the given node is not connected
    • sendChildRequest

      public final <T extends TransportResponse> void sendChildRequest​(DiscoveryNode node, java.lang.String action, TransportRequest request, Task parentTask, TransportRequestOptions options, TransportResponseHandler<T> handler)
    • sendChildRequest

      public <T extends TransportResponse> void sendChildRequest​(Transport.Connection connection, java.lang.String action, TransportRequest request, Task parentTask, TransportResponseHandler<T> handler)
    • sendChildRequest

      public <T extends TransportResponse> void sendChildRequest​(Transport.Connection connection, java.lang.String action, TransportRequest request, Task parentTask, TransportRequestOptions options, TransportResponseHandler<T> handler)
    • shouldTraceAction

      public static boolean shouldTraceAction​(java.lang.String action, java.lang.String[] include, java.lang.String[] exclude)
    • addressesFromString

      public TransportAddress[] addressesFromString​(java.lang.String address) throws java.net.UnknownHostException
      Throws:
      java.net.UnknownHostException
    • isValidActionName

      public static boolean isValidActionName​(java.lang.String actionName)
      Returns true iff the action name starts with a valid prefix.
      See Also:
      VALID_ACTION_PREFIXES
    • registerRequestHandler

      public <Request extends TransportRequest> void registerRequestHandler​(java.lang.String action, java.lang.String executor, Writeable.Reader<Request> requestReader, TransportRequestHandler<Request> handler)
      Registers a new request handler
      Parameters:
      action - The action the request handler is associated with
      requestReader - a callable to be used construct new instances for streaming
      executor - The executor the request handling will be executed on
      handler - The handler itself that implements the request handling
    • registerRequestHandler

      public <Request extends TransportRequest> void registerRequestHandler​(java.lang.String action, java.lang.String executor, boolean forceExecution, boolean canTripCircuitBreaker, Writeable.Reader<Request> requestReader, TransportRequestHandler<Request> handler)
      Registers a new request handler
      Parameters:
      action - The action the request handler is associated with
      requestReader - The request class that will be used to construct new instances for streaming
      executor - The executor the request handling will be executed on
      forceExecution - Force execution on the executor queue and never reject it
      canTripCircuitBreaker - Check the request size and raise an exception in case the limit is breached.
      handler - The handler itself that implements the request handling
    • onRequestReceived

      public void onRequestReceived​(long requestId, java.lang.String action)
      called by the Transport implementation when an incoming request arrives but before any parsing of it has happened (with the exception of the requestId and action)
      Specified by:
      onRequestReceived in interface TransportMessageListener
      Parameters:
      requestId - the internal request ID
      action - the request action
    • onRequestSent

      public void onRequestSent​(DiscoveryNode node, long requestId, java.lang.String action, TransportRequest request, TransportRequestOptions options)
      called by the Transport implementation once a request has been sent
      Specified by:
      onRequestSent in interface TransportMessageListener
      Parameters:
      node - the node the request was sent to
      requestId - the internal request id
      action - the action name
      request - the actual request
      options - the request options
    • onResponseReceived

      public void onResponseReceived​(long requestId, Transport.ResponseContext holder)
      Description copied from interface: TransportMessageListener
      Called for every response received
      Specified by:
      onResponseReceived in interface TransportMessageListener
      Parameters:
      requestId - the request id for this response
      holder - the response context or null if the context was already processed ie. due to a timeout.
    • onResponseSent

      public void onResponseSent​(long requestId, java.lang.String action, TransportResponse response)
      called by the Transport implementation once a response was sent to calling node
      Specified by:
      onResponseSent in interface TransportMessageListener
      Parameters:
      requestId - the request ID (unique per client)
      action - the request action
      response - the response send
    • onResponseSent

      public void onResponseSent​(long requestId, java.lang.String action, java.lang.Exception e)
      called by the Transport implementation after an exception was sent as a response to an incoming request
      Specified by:
      onResponseSent in interface TransportMessageListener
      Parameters:
      requestId - the request ID (unique per client)
      action - the request action
      e - the error sent back to the caller
    • getRequestHandler

      public RequestHandlerRegistry<? extends TransportRequest> getRequestHandler​(java.lang.String action)
    • onConnectionClosed

      public void onConnectionClosed​(Transport.Connection connection)
      Description copied from interface: TransportConnectionListener
      Called once a connection ws closed.
      Specified by:
      onConnectionClosed in interface TransportConnectionListener
      Parameters:
      connection - the closed connection
    • getThreadPool

      public ThreadPool getThreadPool()
      Returns the internal thread pool