public class NettyTransceiver extends Transceiver
Transceiver
implementation.Modifier and Type | Class and Description |
---|---|
protected class |
NettyTransceiver.NettyClientAvroHandler
Avro client handler for the Netty transport
|
protected static class |
NettyTransceiver.NettyTransceiverThreadFactory
Creates threads with unique names based on a specified name prefix.
|
protected static class |
NettyTransceiver.WriteFutureListener
A ChannelFutureListener for channel write operations that notifies a
Callback if an error occurs while writing to the channel. |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT_MILLIS
If not specified, the default connection timeout will be used (60 sec).
|
static boolean |
DEFAULT_TCP_NODELAY_VALUE |
static String |
NETTY_CONNECT_TIMEOUT_OPTION |
static String |
NETTY_KEEPALIVE_OPTION |
static String |
NETTY_TCP_NODELAY_OPTION |
Constructor and Description |
---|
NettyTransceiver(InetSocketAddress addr)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
Consumer<io.netty.channel.socket.SocketChannel> initializer)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
Integer connectTimeoutMillis)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
Integer connectTimeoutMillis,
Consumer<io.netty.channel.socket.SocketChannel> initializer)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
Integer connectTimeoutMillis,
Consumer<io.netty.channel.socket.SocketChannel> initializer,
Consumer<io.netty.bootstrap.Bootstrap> bootStrapInitialzier)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this transceiver and disconnects from the remote peer.
|
void |
close(boolean awaitCompletion)
Closes this transceiver and disconnects from the remote peer.
|
protected io.netty.channel.ChannelInboundHandler |
createNettyClientAvroHandler()
Creates a Netty ChannelUpstreamHandler for handling events on the Netty
client channel.
|
Protocol |
getRemote()
Returns the protocol passed to
Transceiver.setRemote(Protocol) . |
String |
getRemoteName() |
boolean |
isConnected()
True if a handshake has been completed for this connection.
|
void |
lockChannel()
Netty channels are thread-safe, so there is no need to acquire locks.
|
List<ByteBuffer> |
readBuffers()
Called by the default definition of
Transceiver.transceive(List) . |
void |
setRemote(Protocol protocol)
Called with the remote protocol when a handshake has been completed.
|
List<ByteBuffer> |
transceive(List<ByteBuffer> request)
Override as non-synchronized method because the method is thread safe.
|
void |
transceive(List<ByteBuffer> request,
Callback<List<ByteBuffer>> callback)
Called by
Requestor.request(String,Object,Callback) for two-way
messages using callbacks. |
void |
unlockChannel()
Netty channels are thread-safe, so there is no need to acquire locks.
|
void |
writeBuffers(List<ByteBuffer> buffers)
Called by
Requestor.request(String,Object) for one-way messages. |
public static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS
public static final String NETTY_CONNECT_TIMEOUT_OPTION
public static final String NETTY_TCP_NODELAY_OPTION
public static final String NETTY_KEEPALIVE_OPTION
public static final boolean DEFAULT_TCP_NODELAY_VALUE
public NettyTransceiver(InetSocketAddress addr) throws IOException
DEFAULT_CONNECTION_TIMEOUT_MILLIS
is used for the connection
timeout.addr
- the address to connect to.IOException
- if an error occurs connecting to the given address.public NettyTransceiver(InetSocketAddress addr, Integer connectTimeoutMillis) throws IOException
addr
- the address to connect to.connectTimeoutMillis
- maximum amount of time to wait for connection
establishment in milliseconds, or null to use
DEFAULT_CONNECTION_TIMEOUT_MILLIS
.IOException
- if an error occurs connecting to the given address.public NettyTransceiver(InetSocketAddress addr, Consumer<io.netty.channel.socket.SocketChannel> initializer) throws IOException
addr
- the address to connect to.initializer
- Consumer function to apply initial setup to the
SocketChannel. Useablet to set things like SSL
requirements, compression, etc...IOException
- if an error occurs connecting to the given address.public NettyTransceiver(InetSocketAddress addr, Integer connectTimeoutMillis, Consumer<io.netty.channel.socket.SocketChannel> initializer) throws IOException
addr
- the address to connect to.connectTimeoutMillis
- maximum amount of time to wait for connection
establishment in milliseconds, or null to use
DEFAULT_CONNECTION_TIMEOUT_MILLIS
.initializer
- Consumer function to apply initial setup to the
SocketChannel. Usable to set things like SSL
requirements, compression, etc...IOException
- if an error occurs connecting to the given address.public NettyTransceiver(InetSocketAddress addr, Integer connectTimeoutMillis, Consumer<io.netty.channel.socket.SocketChannel> initializer, Consumer<io.netty.bootstrap.Bootstrap> bootStrapInitialzier) throws IOException
addr
- the address to connect to.connectTimeoutMillis
- maximum amount of time to wait for connection
establishment in milliseconds, or null to use
DEFAULT_CONNECTION_TIMEOUT_MILLIS
.initializer
- Consumer function to apply initial setup to the
SocketChannel. Usable to set things like SSL
requirements, compression, etc...bootStrapInitialzier
- Consumer function to apply initial setup to the
Bootstrap. Usable to set things like tcp
connection properties, nagle algorithm, etc...IOException
- if an error occurs connecting to the given address.protected io.netty.channel.ChannelInboundHandler createNettyClientAvroHandler()
public void lockChannel()
lockChannel
in class Transceiver
public void unlockChannel()
unlockChannel
in class Transceiver
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class Transceiver
public void close(boolean awaitCompletion)
awaitCompletion
- if true, will block until the close has completed.public String getRemoteName() throws IOException
getRemoteName
in class Transceiver
IOException
public List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException
transceive
in class Transceiver
IOException
public void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback) throws IOException
Transceiver
Requestor.request(String,Object,Callback)
for two-way
messages using callbacks.transceive
in class Transceiver
IOException
public void writeBuffers(List<ByteBuffer> buffers) throws IOException
Transceiver
Requestor.request(String,Object)
for one-way messages.writeBuffers
in class Transceiver
IOException
public List<ByteBuffer> readBuffers() throws IOException
Transceiver
Transceiver.transceive(List)
.readBuffers
in class Transceiver
IOException
public Protocol getRemote()
Transceiver
Transceiver.setRemote(Protocol)
. Throws
IllegalStateException by default.getRemote
in class Transceiver
public boolean isConnected()
Transceiver
isConnected
in class Transceiver
public void setRemote(Protocol protocol)
Transceiver
Transceiver.isConnected()
should return true and #getRemote() should return this
protocol. Does nothing by default.setRemote
in class Transceiver
Copyright © 2009–2022 The Apache Software Foundation. All rights reserved.