Class TransportService

    • Field Detail

      • 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
      • threadPool

        protected final ThreadPool threadPool
      • VALID_ACTION_PREFIXES

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

      • createTaskManager

        protected TaskManager createTaskManager​(Settings settings,
                                                ThreadPool threadPool,
                                                java.util.Set<java.lang.String> taskHeaders)
      • 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
      • getLocalAddresses

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

        public boolean nodeConnected​(DiscoveryNode node)
        Returns true iff the given node is already connected.
      • 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
      • openConnection

        public Transport.Connection openConnection​(DiscoveryNode node,
                                                   ConnectionProfile connectionProfile)
                                            throws java.io.IOException
        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.
        Parameters:
        node - the node to connect to
        connectionProfile - the connection profile to use
        Throws:
        java.io.IOException
      • handshake

        public DiscoveryNode handshake​(Transport.Connection connection,
                                       long handshakeTimeout)
                                throws ConnectTransportException
        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.
        Parameters:
        connection - the connection to a specific node
        handshakeTimeout - handshake timeout
        Returns:
        the connected node
        Throws:
        ConnectTransportException - if the connection failed
        java.lang.IllegalStateException - if the handshake failed
      • handshake

        public TransportService.HandshakeResponse handshake​(Transport.Connection connection,
                                                            long handshakeTimeout,
                                                            java.util.function.Predicate<ClusterName> clusterNamePredicate)
        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.
        Parameters:
        connection - the connection to a specific node
        handshakeTimeout - handshake timeout
        clusterNamePredicate - cluster name validation predicate
        Returns:
        the handshake response
        Throws:
        java.lang.IllegalStateException - if the handshake failed
      • disconnectFromNode

        public void disconnectFromNode​(DiscoveryNode node)
      • addressesFromString

        public TransportAddress[] addressesFromString​(java.lang.String address,
                                                      int perAddressLimit)
                                               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.util.function.Supplier<Request> requestFactory,
                                                                              java.lang.String executor,
                                                                              TransportRequestHandler<Request> handler)
        Registers a new request handler
        Parameters:
        action - The action the request handler is associated with
        requestFactory - 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,
                                                                              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.util.function.Supplier<Request> request,
                                                                              java.lang.String executor,
                                                                              boolean forceExecution,
                                                                              boolean canTripCircuitBreaker,
                                                                              TransportRequestHandler<Request> handler)
        Registers a new request handler
        Parameters:
        action - The action the request handler is associated with
        request - 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
      • 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
      • traceEnabled

        protected boolean traceEnabled()
      • 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
      • traceResponseSent

        protected void traceResponseSent​(long requestId,
                                         java.lang.String action,
                                         java.lang.Exception e)
      • 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
      • traceReceivedRequest

        protected void traceReceivedRequest​(long requestId,
                                            java.lang.String action)
      • traceResponseSent

        protected void traceResponseSent​(long requestId,
                                         java.lang.String action)
      • traceReceivedResponse

        protected void traceReceivedResponse​(long requestId,
                                             DiscoveryNode sourceNode,
                                             java.lang.String action)
      • traceUnresolvedResponse

        protected void traceUnresolvedResponse​(long requestId)
      • getThreadPool

        public ThreadPool getThreadPool()
        Returns the internal thread pool