public class NettyTransceiver extends Transceiver
Transceiver implementation.| 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_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 |
|---|---|
void |
close() |
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 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.public void lockChannel()
lockChannel in class Transceiverpublic void unlockChannel()
unlockChannel in class Transceiverpublic void close()
close in interface Closeableclose in interface AutoCloseableclose in class Transceiverpublic String getRemoteName() throws IOException
getRemoteName in class TransceiverIOExceptionpublic List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException
transceive in class TransceiverIOExceptionpublic void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback) throws IOException
TransceiverRequestor.request(String,Object,Callback) for two-way messages using callbacks.transceive in class TransceiverIOExceptionpublic void writeBuffers(List<ByteBuffer> buffers) throws IOException
TransceiverRequestor.request(String,Object) for one-way messages.writeBuffers in class TransceiverIOExceptionpublic List<ByteBuffer> readBuffers() throws IOException
TransceiverTransceiver.transceive(List).readBuffers in class TransceiverIOExceptionpublic Protocol getRemote()
TransceiverTransceiver.setRemote(Protocol). Throws
IllegalStateException by default.getRemote in class Transceiverpublic boolean isConnected()
TransceiverisConnected in class Transceiverpublic void setRemote(Protocol protocol)
TransceiverTransceiver.isConnected() should return true and #getRemote() should return this
protocol. Does nothing by default.setRemote in class TransceiverCopyright © 2009-2012 The Apache Software Foundation. All Rights Reserved.