Class TcpTransport

    • Constructor Detail

      • TcpTransport

        public TcpTransport​(io.netty.bootstrap.Bootstrap bootstrap,
                            TransportOptions options,
                            SslOptions sslOptions)
        Create a new TcpTransport instance with the given configuration.
        Parameters:
        bootstrap - the Netty Bootstrap that this transport's IO layer is bound to.
        options - the TransportOptions used to configure the socket connection.
        sslOptions - the SslOptions to use if the options indicate SSL is enabled.
    • Method Detail

      • connect

        public TcpTransport connect​(String host,
                                    int port,
                                    TransportListener listener)
                             throws IOException
        Description copied from interface: Transport
        Performs the connect operation for the implemented Transport type such as a TCP socket connection, SSL/TLS handshake etc. The connection operation itself will be performed as an asynchronous operation with the success or failure being communicated to the event point TransportListener.transportError(Throwable). If the users wishes to perform a block on connect outcome the Transport.awaitConnect() method will wait for and or throw an error based on the connect outcome.
        Specified by:
        connect in interface Transport
        Parameters:
        host - The remote host that this Transport should attempt to connect to.
        port - The port on the remote host that this Transport should attempt to bind to.
        listener - The TransportListener that will handle Transport events.
        Returns:
        this Transport instance.
        Throws:
        IOException - if an error occurs while attempting the connect.
      • isConnected

        public boolean isConnected()
        Specified by:
        isConnected in interface Transport
        Returns:
        true if transport is connected or false if the connection is down.
      • isSecure

        public boolean isSecure()
        Specified by:
        isSecure in interface Transport
        Returns:
        true if transport is connected using a secured channel (SSL).
      • getHost

        public String getHost()
        Specified by:
        getHost in interface Transport
        Returns:
        the host name or IP address that the transport connects to.
      • getPort

        public int getPort()
        Specified by:
        getPort in interface Transport
        Returns:
        the port that the transport connects to.
      • close

        public void close()
                   throws IOException
        Description copied from interface: Transport
        Close the Transport, no additional send operations are accepted.
        Specified by:
        close in interface Transport
        Throws:
        IOException - if an error occurs while closing the connection.
      • write

        public TcpTransport write​(ProtonBuffer output)
                           throws IOException
        Description copied from interface: Transport
        Writes a chunk of data over the Transport connection without performing an explicit flush on the transport.
        Specified by:
        write in interface Transport
        Parameters:
        output - The buffer of data that is to be transmitted.
        Returns:
        this Transport instance.
        Throws:
        IOException - if an error occurs during the write operation.
      • write

        public TcpTransport write​(ProtonBuffer output,
                                  Runnable onComplete)
                           throws IOException
        Description copied from interface: Transport
        Writes a chunk of data over the Transport connection without performing an explicit flush on the transport. This method allows for a completion callback that is signaled when the actual low level IO operation is completed which could be after this method has returned.
        Specified by:
        write in interface Transport
        Parameters:
        output - The buffer of data that is to be transmitted.
        onComplete - A Runnable that is invoked when the IO operation completes successfully.
        Returns:
        this Transport instance.
        Throws:
        IOException - if an error occurs during the write operation.
      • writeAndFlush

        public TcpTransport writeAndFlush​(ProtonBuffer output)
                                   throws IOException
        Description copied from interface: Transport
        Writes a chunk of data over the Transport connection and requests a flush of all pending queued write operations
        Specified by:
        writeAndFlush in interface Transport
        Parameters:
        output - The buffer of data that is to be transmitted.
        Returns:
        this Transport instance.
        Throws:
        IOException - if an error occurs during the write operation.
      • writeAndFlush

        public TcpTransport writeAndFlush​(ProtonBuffer output,
                                          Runnable onComplete)
                                   throws IOException
        Description copied from interface: Transport
        Writes a chunk of data over the Transport connection and requests a flush of all pending queued write operations
        Specified by:
        writeAndFlush in interface Transport
        Parameters:
        output - The buffer of data that is to be transmitted.
        onComplete - A Runnable that is invoked when the IO operation completes successfully.
        Returns:
        this Transport instance.
        Throws:
        IOException - if an error occurs during the write operation.
      • getTransportListener

        public TransportListener getTransportListener()
        Description copied from interface: Transport
        Gets the currently set TransportListener instance
        Specified by:
        getTransportListener in interface Transport
        Returns:
        the current TransportListener or null if none set.
      • getLocalPrincipal

        public Principal getLocalPrincipal()
        Specified by:
        getLocalPrincipal in interface Transport
        Returns:
        the local principal for a Transport that is using a secure connection.
      • addAdditionalHandlers

        protected void addAdditionalHandlers​(io.netty.channel.ChannelPipeline pipeline)
      • createChannelHandler

        protected io.netty.channel.ChannelInboundHandlerAdapter createChannelHandler()
      • handleConnected

        protected void handleConnected​(io.netty.channel.Channel connectedChannel)
                                throws Exception
        Throws:
        Exception
      • handleTransportFailure

        protected void handleTransportFailure​(io.netty.channel.Channel failedChannel,
                                              Throwable cause)
      • getRemoteURI

        public URI getRemoteURI()
        Description copied from interface: Transport
        Returns a URI that contains some meaningful information about the remote connection such as a scheme that reflects the transport type and the remote host and port that the connection was instructed to connect to. If called before the Transport.connect(String, int, TransportListener) method this method returns null.
        Specified by:
        getRemoteURI in interface Transport
        Returns:
        a URI that reflects a meaningful view of the Transport remote connection details.
      • getScheme

        protected String getScheme()