Class TcpTransport

    • Field Detail

      • TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX

        public static final java.lang.String TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX
        See Also:
        Constant Field Values
      • TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX

        public static final java.lang.String TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX
        See Also:
        Constant Field Values
      • HOST

        public static final Setting<java.util.List<java.lang.String>> HOST
      • BIND_HOST

        public static final Setting<java.util.List<java.lang.String>> BIND_HOST
      • PUBLISH_HOST

        public static final Setting<java.util.List<java.lang.String>> PUBLISH_HOST
      • PORT

        public static final Setting<java.lang.String> PORT
      • PUBLISH_PORT

        public static final Setting<java.lang.Integer> PUBLISH_PORT
      • TCP_NO_DELAY

        public static final Setting<java.lang.Boolean> TCP_NO_DELAY
      • TCP_KEEP_ALIVE

        public static final Setting<java.lang.Boolean> TCP_KEEP_ALIVE
      • TCP_REUSE_ADDRESS

        public static final Setting<java.lang.Boolean> TCP_REUSE_ADDRESS
      • TCP_NO_DELAY_PROFILE

        public static final Setting.AffixSetting<java.lang.Boolean> TCP_NO_DELAY_PROFILE
      • TCP_KEEP_ALIVE_PROFILE

        public static final Setting.AffixSetting<java.lang.Boolean> TCP_KEEP_ALIVE_PROFILE
      • TCP_REUSE_ADDRESS_PROFILE

        public static final Setting.AffixSetting<java.lang.Boolean> TCP_REUSE_ADDRESS_PROFILE
      • BIND_HOST_PROFILE

        public static final Setting.AffixSetting<java.util.List<java.lang.String>> BIND_HOST_PROFILE
      • PUBLISH_HOST_PROFILE

        public static final Setting.AffixSetting<java.util.List<java.lang.String>> PUBLISH_HOST_PROFILE
      • PUBLISH_PORT_PROFILE

        public static final Setting.AffixSetting<java.lang.Integer> PUBLISH_PORT_PROFILE
      • DEFAULT_FEATURES_SETTING

        public static final Setting<Settings> DEFAULT_FEATURES_SETTING
      • threadPool

        protected final ThreadPool threadPool
      • compress

        protected final boolean compress
    • Method Detail

      • getCurrentVersion

        protected Version getCurrentVersion()
      • profileBoundAddresses

        public java.util.Map<java.lang.String,​BoundTransportAddress> profileBoundAddresses()
        Description copied from interface: Transport
        Further profile bound addresses
        Specified by:
        profileBoundAddresses in interface Transport
        Returns:
        null iff profiles are unsupported, otherwise a map with name of profile and its bound transport address
      • getLocalAddresses

        public java.util.List<java.lang.String> getLocalAddresses()
        Description copied from interface: Transport
        Returns a list of all local adresses for this transport
        Specified by:
        getLocalAddresses in interface Transport
      • bindToPort

        protected java.net.InetSocketAddress bindToPort​(java.lang.String name,
                                                        java.net.InetAddress hostAddress,
                                                        java.lang.String port)
      • resolvePublishPort

        public static int resolvePublishPort​(TcpTransport.ProfileSettings profileSettings,
                                             java.util.List<java.net.InetSocketAddress> boundAddresses,
                                             java.net.InetAddress publishInetAddress)
      • addressesFromString

        public TransportAddress[] addressesFromString​(java.lang.String address,
                                                      int perAddressLimit)
                                               throws java.net.UnknownHostException
        Description copied from interface: Transport
        Returns an address from its string representation.
        Specified by:
        addressesFromString in interface Transport
        Throws:
        java.net.UnknownHostException
      • onException

        protected void onException​(TcpChannel channel,
                                   java.lang.Exception e)
      • serverAcceptedChannel

        protected void serverAcceptedChannel​(TcpChannel channel)
      • bind

        protected abstract TcpChannel bind​(java.lang.String name,
                                           java.net.InetSocketAddress address)
                                    throws java.io.IOException
        Binds to the given InetSocketAddress
        Parameters:
        name - the profile name
        address - the address to bind to
        Throws:
        java.io.IOException
      • initiateChannel

        protected abstract TcpChannel initiateChannel​(DiscoveryNode node,
                                                      ActionListener<java.lang.Void> connectListener)
                                               throws java.io.IOException
        Initiate a single tcp socket channel.
        Parameters:
        node - for the initiated connection
        connectListener - listener to be called when connection complete
        Returns:
        the pending connection
        Throws:
        java.io.IOException - if an I/O exception occurs while opening the channel
      • stopInternal

        protected void stopInternal()
        Called to tear down internal resources
      • sendErrorResponse

        public void sendErrorResponse​(Version nodeVersion,
                                      java.util.Set<java.lang.String> features,
                                      TcpChannel channel,
                                      java.lang.Exception error,
                                      long requestId,
                                      java.lang.String action)
                               throws java.io.IOException
        Sends back an error response to the caller via the given channel
        Parameters:
        nodeVersion - the caller node version
        features - the caller features
        channel - the channel to send the response to
        error - the error to return
        requestId - the request ID this response replies to
        action - the action this response replies to
        Throws:
        java.io.IOException
      • validateMessageHeader

        public static boolean validateMessageHeader​(BytesReference buffer)
                                             throws java.io.IOException
        Validates the first N bytes of the message header and returns false if the message is a ping message and has no payload ie. isn't a real user level message.
        Throws:
        java.lang.IllegalStateException - if the message is too short, less than the header or less that the header plus the message size
        TcpTransport.HttpOnTransportException - if the message has no valid header and appears to be an HTTP message
        java.lang.IllegalArgumentException - if the message is greater that the maximum allowed frame size. This is dependent on the available memory.
        java.io.IOException
      • messageReceived

        public final void messageReceived​(BytesReference reference,
                                          TcpChannel channel,
                                          java.lang.String profileName,
                                          java.net.InetSocketAddress remoteAddress,
                                          int messageLengthBytes)
                                   throws java.io.IOException
        This method handles the message receive part for both request and responses
        Throws:
        java.io.IOException
      • handleRequest

        protected java.lang.String handleRequest​(TcpChannel channel,
                                                 java.lang.String profileName,
                                                 StreamInput stream,
                                                 long requestId,
                                                 int messageLengthBytes,
                                                 Version version,
                                                 java.net.InetSocketAddress remoteAddress,
                                                 byte status)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • validateRequest

        protected void validateRequest​(StreamInput stream,
                                       long requestId,
                                       java.lang.String action)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • executeHandshake

        public Version executeHandshake​(DiscoveryNode node,
                                        TcpChannel channel,
                                        TimeValue timeout)
                                 throws java.io.IOException,
                                        java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • ensureOpen

        protected final void ensureOpen()
        Ensures this transport is still started / open
        Throws:
        java.lang.IllegalStateException - if the transport is not started / open
      • getProfileSettings

        public static java.util.Set<TcpTransport.ProfileSettings> getProfileSettings​(Settings settings)
        Returns all profile settings for the given settings object
      • getRequestHandler

        public final RequestHandlerRegistry getRequestHandler​(java.lang.String action)
        Description copied from interface: Transport
        Returns the registered request handler registry for the given action or null if it's not registered
        Specified by:
        getRequestHandler in interface Transport
        Parameters:
        action - the action to look up