public class NettyTcpTransport extends Object implements Transport
Modifier and Type | Field and Description |
---|---|
protected io.netty.bootstrap.Bootstrap |
bootstrap |
protected io.netty.channel.Channel |
channel |
protected io.netty.channel.EventLoopGroup |
group |
protected TransportListener |
listener |
protected TransportOptions |
options |
protected URI |
remote |
Constructor and Description |
---|
NettyTcpTransport(TransportListener listener,
URI remoteLocation,
TransportOptions options)
Create a new transport instance
|
NettyTcpTransport(URI remoteLocation,
TransportOptions options)
Create a new transport instance
|
Modifier and Type | Method and Description |
---|---|
io.netty.buffer.ByteBuf |
allocateSendBuffer(int size)
Request that the Transport provide an output buffer sized for the given
value.
|
void |
close()
Close the Transport, no additional send operations are accepted.
|
protected void |
configureChannel(io.netty.channel.Channel channel) |
protected void |
configureNetty(io.netty.bootstrap.Bootstrap bootstrap,
TransportOptions options) |
void |
connect()
Performs the protocol connect operation for the implemented Transport type
such as a TCP socket connection etc.
|
protected void |
connectionEstablished(io.netty.channel.Channel connectedChannel)
Called when the transport has successfully connected and is ready for use.
|
protected void |
connectionFailed(io.netty.channel.Channel failedChannel,
IOException cause)
Called when the transport connection failed and an error should be returned.
|
protected String |
getRemoteHost() |
URI |
getRemoteLocation() |
protected int |
getRemotePort() |
TransportListener |
getTransportListener()
Gets the currently set TransportListener instance
|
TransportOptions |
getTransportOptions() |
protected void |
handleConnected(io.netty.channel.Channel channel) |
boolean |
isConnected() |
void |
send(io.netty.buffer.ByteBuf output)
Sends a chunk of data over the Transport connection.
|
void |
setTransportListener(TransportListener listener)
Sets the Transport Listener instance that will be notified of incoming data or
error events.
|
protected io.netty.bootstrap.Bootstrap bootstrap
protected io.netty.channel.EventLoopGroup group
protected io.netty.channel.Channel channel
protected TransportListener listener
protected TransportOptions options
protected final URI remote
public NettyTcpTransport(URI remoteLocation, TransportOptions options)
remoteLocation
- the URI that defines the remote resource to connect to.options
- the transport options used to configure the socket connection.public NettyTcpTransport(TransportListener listener, URI remoteLocation, TransportOptions options)
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.public void connect() throws IOException
Transport
connect
in interface Transport
IOException
- if an error occurs while attempting the connect.public boolean isConnected()
isConnected
in interface Transport
public void close() throws IOException
Transport
close
in interface Transport
IOException
- if an error occurs while closing the connection.public io.netty.buffer.ByteBuf allocateSendBuffer(int size) throws IOException
Transport
allocateSendBuffer
in interface Transport
size
- the size necessary to hold the outgoing bytes.IOException
- if an error occurs while allocating the send buffer.public void send(io.netty.buffer.ByteBuf output) throws IOException
Transport
send
in interface Transport
output
- The buffer of data that is to be transmitted.IOException
- if an error occurs during the send operation.public TransportListener getTransportListener()
Transport
getTransportListener
in interface Transport
public void setTransportListener(TransportListener listener)
Transport
setTransportListener
in interface Transport
listener
- The new TransportListener instance to use (cannot be null).public TransportOptions getTransportOptions()
getTransportOptions
in interface Transport
public URI getRemoteLocation()
getRemoteLocation
in interface Transport
protected String getRemoteHost()
protected int getRemotePort()
protected void configureNetty(io.netty.bootstrap.Bootstrap bootstrap, TransportOptions options)
protected void configureChannel(io.netty.channel.Channel channel) throws Exception
Exception
protected void handleConnected(io.netty.channel.Channel channel) throws Exception
Exception
protected void connectionEstablished(io.netty.channel.Channel connectedChannel)
protected void connectionFailed(io.netty.channel.Channel failedChannel, IOException cause)
failedChannel
- The Channel instance that failed.cause
- An IOException that describes the cause of the failed connection.Copyright © 2013–2016 The Apache Software Foundation. All rights reserved.