Class TcpTransport
java.lang.Object
org.apache.qpid.protonj2.client.transport.netty5.TcpTransport
- All Implemented Interfaces:
Transport
- Direct Known Subclasses:
WebSocketTransport
TCP based transport that uses Netty as the underlying IO layer.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
protected class
-
Field Summary
Modifier and TypeFieldDescriptionprotected final io.netty5.bootstrap.Bootstrap
protected io.netty5.channel.Channel
protected final AtomicBoolean
protected final AtomicBoolean
protected final CountDownLatch
protected IOException
protected String
protected TransportListener
protected Netty5ProtonBufferAllocator
protected final TransportOptions
protected int
protected final SslOptions
-
Constructor Summary
ConstructorDescriptionTcpTransport
(io.netty5.bootstrap.Bootstrap bootstrap, TransportOptions options, SslOptions sslOptions) Create a newTcpTransport
instance with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAdditionalHandlers
(io.netty5.channel.ChannelPipeline pipeline) void
Waits interruptibly for theTransport
to connect to the remote that was indicated in theTransport.connect(String, int, TransportListener)
call.protected final void
void
close()
Close the Transport, no additional send operations are accepted.connect
(String host, int port, TransportListener listener) Performs the connect operation for the implemented Transport type such as a TCP socket connection, SSL/TLS handshake etc.protected io.netty5.channel.ChannelHandler
flush()
Request a flush of all pending writes to the underlying connection.Gets a buffer allocator that can produceProtonBuffer
instance that may be optimized for use with the underlying transport implementation.getHost()
int
getPort()
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.protected String
Gets the currently set TransportListener instanceprotected void
handleConnected
(io.netty5.channel.Channel connectedChannel) protected void
handleTransportFailure
(io.netty5.channel.Channel failedChannel, Throwable cause) boolean
boolean
isSecure()
write
(ProtonBuffer output) Writes a chunk of data over the Transport connection without performing an explicit flush on the transport.write
(ProtonBuffer output, Runnable onComplete) Writes a chunk of data over the Transport connection without performing an explicit flush on the transport.writeAndFlush
(ProtonBuffer output) Writes a chunk of data over the Transport connection and requests a flush of all pending queued write operationswriteAndFlush
(ProtonBuffer output, Runnable onComplete) Writes a chunk of data over the Transport connection and requests a flush of all pending queued write operations
-
Field Details
-
connected
-
closed
-
connectedLatch
-
options
-
sslOptions
-
bootstrap
protected final io.netty5.bootstrap.Bootstrap bootstrap -
channel
protected io.netty5.channel.Channel channel -
failureCause
-
host
-
port
protected int port -
listener
-
nettyAllocator
-
-
Constructor Details
-
TcpTransport
public TcpTransport(io.netty5.bootstrap.Bootstrap bootstrap, TransportOptions options, SslOptions sslOptions) Create a newTcpTransport
instance with the given configuration.- Parameters:
bootstrap
- the NettyBootstrap
that this transport's IO layer is bound to.options
- theTransportOptions
used to configure the socket connection.sslOptions
- theSslOptions
to use if the options indicate SSL is enabled.
-
-
Method Details
-
connect
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 pointTransportListener.transportError(Throwable)
. If the users wishes to perform a block on connect outcome theTransport.awaitConnect()
method will wait for and or throw an error based on the connect outcome.- Specified by:
connect
in interfaceTransport
- Parameters:
host
- The remote host that thisTransport
should attempt to connect to.port
- The port on the remote host that thisTransport
should attempt to bind to.listener
- TheTransportListener
that will handleTransport
events.- Returns:
- this
Transport
instance. - Throws:
IOException
- if an error occurs while attempting the connect.
-
awaitConnect
Description copied from interface:Transport
Waits interruptibly for theTransport
to connect to the remote that was indicated in theTransport.connect(String, int, TransportListener)
call.- Specified by:
awaitConnect
in interfaceTransport
- Throws:
InterruptedException
- If the wait mechanism was interrupted while waiting for a successful connect.IOException
- If theTransport
failed to connect or was closed before connected.
-
isConnected
public boolean isConnected()- Specified by:
isConnected
in interfaceTransport
- Returns:
- true if transport is connected or false if the connection is down.
-
isSecure
public boolean isSecure() -
getHost
-
getPort
public int getPort() -
close
Description copied from interface:Transport
Close the Transport, no additional send operations are accepted.- Specified by:
close
in interfaceTransport
- Throws:
IOException
- if an error occurs while closing the connection.
-
getBufferAllocator
Description copied from interface:Transport
Gets a buffer allocator that can produceProtonBuffer
instance that may be optimized for use with the underlying transport implementation.- Specified by:
getBufferAllocator
in interfaceTransport
- Returns:
- a
ProtonBufferAllocator
that creates transport friendly buffers.
-
write
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 interfaceTransport
- 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
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 interfaceTransport
- Parameters:
output
- The buffer of data that is to be transmitted.onComplete
- ARunnable
that is invoked when the IO operation completes successfully.- Returns:
- this
Transport
instance. - Throws:
IOException
- if an error occurs during the write operation.
-
writeAndFlush
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 interfaceTransport
- 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
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 interfaceTransport
- Parameters:
output
- The buffer of data that is to be transmitted.onComplete
- ARunnable
that is invoked when the IO operation completes successfully.- Returns:
- this
Transport
instance. - Throws:
IOException
- if an error occurs during the write operation.
-
flush
Description copied from interface:Transport
Request a flush of all pending writes to the underlying connection.- Specified by:
flush
in interfaceTransport
- Returns:
- this
Transport
instance. - Throws:
IOException
- if an error occurs during the flush operation.
-
getTransportListener
Description copied from interface:Transport
Gets the currently set TransportListener instance- Specified by:
getTransportListener
in interfaceTransport
- Returns:
- the current TransportListener or null if none set.
-
getTransportOptions
- Specified by:
getTransportOptions
in interfaceTransport
- Returns:
- a
TransportOptions
instance copied from the immutable options given at create time..
-
getSslOptions
- Specified by:
getSslOptions
in interfaceTransport
- Returns:
- a
SslOptions
instance copied from the immutable options given at create time..
-
getLocalPrincipal
- Specified by:
getLocalPrincipal
in interfaceTransport
- 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
- Throws:
Exception
-
handleTransportFailure
-
checkConnected
- Throws:
IOException
-
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 theTransport.connect(String, int, TransportListener)
method this method returnsnull
.- Specified by:
getRemoteURI
in interfaceTransport
- Returns:
- a URI that reflects a meaningful view of the
Transport
remote connection details.
-
getScheme
-