java.lang.Object
org.apache.qpid.protonj2.client.transport.netty5.TcpTransport
All Implemented Interfaces:
Transport
Direct Known Subclasses:
WebSocketTransport

public class TcpTransport extends Object implements Transport
TCP based transport that uses Netty as the underlying IO layer.
  • Field Details

  • Constructor Details

    • TcpTransport

      public TcpTransport(io.netty5.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 Details

    • 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.
    • awaitConnect

      public void awaitConnect() throws InterruptedException, IOException
      Description copied from interface: Transport
      Waits interruptibly for the Transport to connect to the remote that was indicated in the Transport.connect(String, int, TransportListener) call.
      Specified by:
      awaitConnect in interface Transport
      Throws:
      InterruptedException - If the wait mechanism was interrupted while waiting for a successful connect.
      IOException - If the Transport failed to connect or was closed before connected.
    • 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.
    • getBufferAllocator

      public ProtonBufferAllocator getBufferAllocator()
      Description copied from interface: Transport
      Gets a buffer allocator that can produce ProtonBuffer instance that may be optimized for use with the underlying transport implementation.
      Specified by:
      getBufferAllocator in interface Transport
      Returns:
      a ProtonBufferAllocator that creates transport friendly buffers.
    • 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.
    • flush

      public TcpTransport flush() throws IOException
      Description copied from interface: Transport
      Request a flush of all pending writes to the underlying connection.
      Specified by:
      flush in interface Transport
      Returns:
      this Transport instance.
      Throws:
      IOException - if an error occurs during the flush 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.
    • getTransportOptions

      public TransportOptions getTransportOptions()
      Specified by:
      getTransportOptions in interface Transport
      Returns:
      a TransportOptions instance copied from the immutable options given at create time..
    • getSslOptions

      public SslOptions getSslOptions()
      Specified by:
      getSslOptions in interface Transport
      Returns:
      a SslOptions instance copied from the immutable options given at create time..
    • 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.netty5.channel.ChannelPipeline pipeline)
    • createChannelHandler

      protected io.netty5.channel.ChannelHandler createChannelHandler()
    • handleConnected

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

      protected void handleTransportFailure(io.netty5.channel.Channel failedChannel, Throwable cause)
    • checkConnected

      protected final void checkConnected() throws IOException
      Throws:
      IOException
    • 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()