Interface TcpChannel

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable, Releasable

    public interface TcpChannel
    extends Releasable
    This is a tcp channel representing a single channel connection to another node. It is the base channel abstraction used by the TcpTransport and TransportService. All tcp transport implementations must return channels that adhere to the required method contracts.
    • Method Detail

      • close

        void close()
        Closes the channel. This might be an asynchronous process. There is notguarantee that the channel will be closed when this method returns. Use the addCloseListener(ActionListener) method to implement logic that depends on knowing when the channel is closed.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface Releasable
      • addCloseListener

        void addCloseListener​(ActionListener<java.lang.Void> listener)
        Adds a listener that will be executed when the channel is closed. If the channel is still open when this listener is added, the listener will be executed by the thread that eventually closes the channel. If the channel is already closed when the listener is added the listener will immediately be executed by the thread that is attempting to add the listener.
        Parameters:
        listener - to be executed
      • setSoLinger

        void setSoLinger​(int value)
                  throws java.io.IOException
        This sets the low level socket option StandardSocketOptions SO_LINGER on a channel.
        Parameters:
        value - to set for SO_LINGER
        Throws:
        java.io.IOException - that can be throw by the low level socket implementation
      • isOpen

        boolean isOpen()
        Indicates whether a channel is currently open
        Returns:
        boolean indicating if channel is open
      • getLocalAddress

        java.net.InetSocketAddress getLocalAddress()
        Returns the local address for this channel.
        Returns:
        the local address of this channel.
      • sendMessage

        void sendMessage​(BytesReference reference,
                         ActionListener<java.lang.Void> listener)
        Sends a tcp message to the channel. The listener will be executed once the send process has been completed.
        Parameters:
        reference - to send to channel
        listener - to execute upon send completion
      • closeChannel

        static <C extends TcpChannel> void closeChannel​(C channel,
                                                        boolean blocking)
        Closes the channel.
        Parameters:
        channel - to close
        blocking - indicates if we should block on channel close
      • closeChannels

        static <C extends TcpChannel> void closeChannels​(java.util.List<C> channels,
                                                         boolean blocking)
        Closes the channels.
        Parameters:
        channels - to close
        blocking - indicates if we should block on channel close
      • awaitConnected

        static void awaitConnected​(DiscoveryNode discoveryNode,
                                   java.util.List<ActionFuture<java.lang.Void>> connectionFutures,
                                   TimeValue connectTimeout)
                            throws ConnectTransportException
        Awaits for all of the pending connections to complete. Will throw an exception if at least one of the connections fails.
        Parameters:
        discoveryNode - the node for the pending connections
        connectionFutures - representing the pending connections
        connectTimeout - to wait for a connection
        Throws:
        ConnectTransportException - if one of the connections fails
      • blockOnFutures

        static void blockOnFutures​(java.util.List<ActionFuture<java.lang.Void>> futures)