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 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 long |
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,
org.jboss.netty.channel.ChannelFactory channelFactory)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
org.jboss.netty.channel.ChannelFactory channelFactory,
Long connectTimeoutMillis)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
org.jboss.netty.channel.ChannelFactory channelFactory,
Map<String,Object> nettyClientBootstrapOptions)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
NettyTransceiver(InetSocketAddress addr,
Long connectTimeoutMillis)
Creates a NettyTransceiver, and attempts to connect to the given address.
|
Modifier and Type | Method and Description |
---|---|
protected static Map<String,Object> |
buildDefaultBootstrapOptions(Long connectTimeoutMillis)
Creates the default options map for the Netty ClientBootstrap.
|
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 org.jboss.netty.channel.ChannelUpstreamHandler |
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 long 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, Long 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, org.jboss.netty.channel.ChannelFactory channelFactory) throws IOException
DEFAULT_CONNECTION_TIMEOUT_MILLIS
is used for the connection
timeout.addr
- the address to connect to.channelFactory
- the factory to use to create a new Netty Channel.IOException
- if an error occurs connecting to the given address.public NettyTransceiver(InetSocketAddress addr, org.jboss.netty.channel.ChannelFactory channelFactory, Long connectTimeoutMillis) throws IOException
addr
- the address to connect to.channelFactory
- the factory to use to create a new Netty Channel.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, org.jboss.netty.channel.ChannelFactory channelFactory, Map<String,Object> nettyClientBootstrapOptions) throws IOException
NETTY_CONNECT_TIMEOUT_OPTION
option be set to a reasonable timeout value (a Long value in milliseconds)
to prevent connect/disconnect attempts from hanging indefinitely. It is
also recommended that the NETTY_TCP_NODELAY_OPTION
option be set
to true to minimize RPC latency.addr
- the address to connect to.channelFactory
- the factory to use to create a new Netty Channel.nettyClientBootstrapOptions
- map of Netty ClientBootstrap options
to use.IOException
- if an error occurs connecting to the given address.protected org.jboss.netty.channel.ChannelUpstreamHandler createNettyClientAvroHandler()
protected static Map<String,Object> buildDefaultBootstrapOptions(Long connectTimeoutMillis)
connectTimeoutMillis
- connection timeout in milliseconds, or null
if no timeout is desired.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–2017 The Apache Software Foundation. All rights reserved.