Class NettyTcpTransport
java.lang.Object
org.apache.qpid.jms.transports.netty.NettyTcpTransport
- All Implemented Interfaces:
Transport
- Direct Known Subclasses:
NettyWsTransport
TCP based transport that uses Netty as the underlying IO layer.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected io.netty.channel.Channelstatic final intprotected EventLoopGroupRefprotected ThreadFactoryprotected TransportListenerprotected int -
Constructor Summary
ConstructorsConstructorDescriptionNettyTcpTransport(URI remoteLocation, TransportOptions options, boolean secure) Create a new transport instanceNettyTcpTransport(TransportListener listener, URI remoteLocation, TransportOptions options, boolean secure) Create a new transport instance -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAdditionalHandlers(io.netty.channel.ChannelPipeline pipeline) io.netty.buffer.ByteBufallocateSendBuffer(int size) Request that the Transport provide an output buffer sized for the given value.protected final voidvoidclose()Close the Transport, no additional send operations are accepted.connect(Runnable initRoutine, SSLContext sslContextOverride) Performs the connect operation for the implemented Transport type such as a TCP socket connection, SSL/TLS handshake etc.protected io.netty.channel.ChannelInboundHandlerAdaptervoidflush()Request a flush of all pending writes to the underlying connection.intReturns the currently configured maximum frame size setting.protected Stringprotected intGets the currently set TransportListener instanceprotected voidhandleChannelInactive(io.netty.channel.Channel channel) protected voidhandleConnected(io.netty.channel.Channel channel) protected voidhandleException(io.netty.channel.Channel channel, Throwable cause) booleanbooleanisSecure()voidsetMaxFrameSize(int maxFrameSize) Sets the Maximum Frame Size the transport should accept from the remote.voidsetThreadFactory(ThreadFactory factory) Sets theThreadFactorythat the Transport should use when creating the Transport IO thread for processing.voidsetTransportListener(TransportListener listener) Sets the Transport Listener instance that will be notified of incoming data or error events.voidwrite(io.netty.buffer.ByteBuf output) Writes a chunk of data over the Transport connection without performing an explicit flush on the transport.voidwriteAndFlush(io.netty.buffer.ByteBuf output) Writes a chunk of data over the Transport connection and requests a flush of all pending queued write operations
-
Field Details
-
DEFAULT_MAX_FRAME_SIZE
public static final int DEFAULT_MAX_FRAME_SIZE- See Also:
-
groupRef
-
channel
protected io.netty.channel.Channel channel -
listener
-
ioThreadfactory
-
maxFrameSize
protected int maxFrameSize
-
-
Constructor Details
-
NettyTcpTransport
Create a new transport instance- Parameters:
remoteLocation- the URI that defines the remote resource to connect to.options- the transport options used to configure the socket connection.secure- should the transport enable an SSL layer.
-
NettyTcpTransport
public NettyTcpTransport(TransportListener listener, URI remoteLocation, TransportOptions options, boolean secure) Create a new transport instance- Parameters:
listener- the TransportListener that will receive events from this Transport.remoteLocation- the URI that defines the remote resource to connect to.options- the transport options used to configure the socket connection.secure- should the transport enable an SSL layer.
-
-
Method Details
-
connect
public ScheduledExecutorService connect(Runnable initRoutine, SSLContext sslContextOverride) throws IOException Description copied from interface:TransportPerforms the connect operation for the implemented Transport type such as a TCP socket connection, SSL/TLS handshake etc.- Specified by:
connectin interfaceTransport- Parameters:
initRoutine- a runnable initialization method that is executed in the context of the transport's IO thread to allow thread safe setup of resources that will be run from the transport executor service.sslContextOverride- a user-provided SSLContext to use if establishing a secure connection, overrides applicable URI configuration- Returns:
- A ScheduledThreadPoolExecutor that can run work on the Transport IO thread.
- Throws:
IOException- if an error occurs while attempting the connect.
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceTransport- Returns:
- true if transport is connected or false if the connection is down.
-
isSecure
public boolean isSecure() -
close
Description copied from interface:TransportClose the Transport, no additional send operations are accepted.- Specified by:
closein interfaceTransport- Throws:
IOException- if an error occurs while closing the connection.
-
allocateSendBuffer
Description copied from interface:TransportRequest that the Transport provide an output buffer sized for the given value.- Specified by:
allocateSendBufferin interfaceTransport- Parameters:
size- the size necessary to hold the outgoing bytes.- Returns:
- a new ByteBuf allocated for sends operations.
- Throws:
IOException- if an error occurs while allocating the send buffer.
-
write
Description copied from interface:TransportWrites a chunk of data over the Transport connection without performing an explicit flush on the transport.- Specified by:
writein interfaceTransport- Parameters:
output- The buffer of data that is to be transmitted.- Throws:
IOException- if an error occurs during the write operation.
-
writeAndFlush
Description copied from interface:TransportWrites a chunk of data over the Transport connection and requests a flush of all pending queued write operations- Specified by:
writeAndFlushin interfaceTransport- Parameters:
output- The buffer of data that is to be transmitted.- Throws:
IOException- if an error occurs during the write operation.
-
flush
Description copied from interface:TransportRequest a flush of all pending writes to the underlying connection.- Specified by:
flushin interfaceTransport- Throws:
IOException- if an error occurs during the flush operation.
-
getTransportListener
Description copied from interface:TransportGets the currently set TransportListener instance- Specified by:
getTransportListenerin interfaceTransport- Returns:
- the current TransportListener or null if none set.
-
setTransportListener
Description copied from interface:TransportSets the Transport Listener instance that will be notified of incoming data or error events.- Specified by:
setTransportListenerin interfaceTransport- Parameters:
listener- The new TransportListener instance to use (cannot be null).
-
getTransportOptions
- Specified by:
getTransportOptionsin interfaceTransport- Returns:
- the TransportOptions instance that holds the configuration for this Transport.
-
getRemoteLocation
- Specified by:
getRemoteLocationin interfaceTransport- Returns:
- the URI of the remote peer that this Transport connects to.
-
getLocalPrincipal
- Specified by:
getLocalPrincipalin interfaceTransport- Returns:
- the local principal for a Transport that is using a secure connection.
-
setMaxFrameSize
public void setMaxFrameSize(int maxFrameSize) Description copied from interface:TransportSets the Maximum Frame Size the transport should accept from the remote. This option is not applicable to all transport types, those that support validating the incoming frame size should apply the configured value.- Specified by:
setMaxFrameSizein interfaceTransport- Parameters:
maxFrameSize- The maximum frame size to accept from the remote.
-
getMaxFrameSize
public int getMaxFrameSize()Description copied from interface:TransportReturns the currently configured maximum frame size setting.- Specified by:
getMaxFrameSizein interfaceTransport- Returns:
- the current max frame size setting for this transport.
-
getThreadFactory
- Specified by:
getThreadFactoryin interfaceTransport- Returns:
- the
ThreadFactoryused to create the IO thread for this Transport
-
setThreadFactory
Description copied from interface:TransportSets theThreadFactorythat the Transport should use when creating the Transport IO thread for processing.- Specified by:
setThreadFactoryin interfaceTransport- Parameters:
factory- TheThreadFactory
-
getRemoteHost
-
getRemotePort
protected int getRemotePort() -
addAdditionalHandlers
protected void addAdditionalHandlers(io.netty.channel.ChannelPipeline pipeline) -
createChannelHandler
protected io.netty.channel.ChannelInboundHandlerAdapter createChannelHandler() -
handleConnected
- Throws:
Exception
-
handleChannelInactive
- Throws:
Exception
-
handleException
-
checkConnected
- Throws:
IOException
-