Class NettyTransceiver

java.lang.Object
org.apache.avro.ipc.Transceiver
org.apache.avro.ipc.netty.NettyTransceiver
All Implemented Interfaces:
Closeable, AutoCloseable

public class NettyTransceiver extends org.apache.avro.ipc.Transceiver
A Netty-based Transceiver implementation.
  • Field Details

    • DEFAULT_CONNECTION_TIMEOUT_MILLIS

      public static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS
      If not specified, the default connection timeout will be used (60 sec).
      See Also:
    • NETTY_CONNECT_TIMEOUT_OPTION

      public static final String NETTY_CONNECT_TIMEOUT_OPTION
      See Also:
    • NETTY_TCP_NODELAY_OPTION

      public static final String NETTY_TCP_NODELAY_OPTION
      See Also:
    • NETTY_KEEPALIVE_OPTION

      public static final String NETTY_KEEPALIVE_OPTION
      See Also:
    • DEFAULT_TCP_NODELAY_VALUE

      public static final boolean DEFAULT_TCP_NODELAY_VALUE
      See Also:
  • Constructor Details

    • NettyTransceiver

      public NettyTransceiver(InetSocketAddress addr) throws IOException
      Creates a NettyTransceiver, and attempts to connect to the given address. DEFAULT_CONNECTION_TIMEOUT_MILLIS is used for the connection timeout.
      Parameters:
      addr - the address to connect to.
      Throws:
      IOException - if an error occurs connecting to the given address.
    • NettyTransceiver

      public NettyTransceiver(InetSocketAddress addr, Integer connectTimeoutMillis) throws IOException
      Creates a NettyTransceiver, and attempts to connect to the given address.
      Parameters:
      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.
      Throws:
      IOException - if an error occurs connecting to the given address.
    • NettyTransceiver

      public NettyTransceiver(InetSocketAddress addr, Consumer<io.netty.channel.socket.SocketChannel> initializer) throws IOException
      Creates a NettyTransceiver, and attempts to connect to the given address.
      Parameters:
      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...
      Throws:
      IOException - if an error occurs connecting to the given address.
    • NettyTransceiver

      public NettyTransceiver(InetSocketAddress addr, Integer connectTimeoutMillis, Consumer<io.netty.channel.socket.SocketChannel> initializer) throws IOException
      Creates a NettyTransceiver, and attempts to connect to the given address.
      Parameters:
      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...
      Throws:
      IOException - if an error occurs connecting to the given address.
    • NettyTransceiver

      public NettyTransceiver(InetSocketAddress addr, Integer connectTimeoutMillis, Consumer<io.netty.channel.socket.SocketChannel> initializer, Consumer<io.netty.bootstrap.Bootstrap> bootStrapInitialzier) throws IOException
      Creates a NettyTransceiver, and attempts to connect to the given address.
      Parameters:
      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...
      Throws:
      IOException - if an error occurs connecting to the given address.
  • Method Details

    • createNettyClientAvroHandler

      protected io.netty.channel.ChannelInboundHandler createNettyClientAvroHandler()
      Creates a Netty ChannelUpstreamHandler for handling events on the Netty client channel.
      Returns:
      the ChannelUpstreamHandler to use.
    • lockChannel

      public void lockChannel()
      Netty channels are thread-safe, so there is no need to acquire locks. This method is a no-op.
      Overrides:
      lockChannel in class org.apache.avro.ipc.Transceiver
    • unlockChannel

      public void unlockChannel()
      Netty channels are thread-safe, so there is no need to acquire locks. This method is a no-op.
      Overrides:
      unlockChannel in class org.apache.avro.ipc.Transceiver
    • close

      public void close()
      Closes this transceiver and disconnects from the remote peer. Cancels all pending RPCs, sends an IOException to all pending callbacks, and blocks until the close has completed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class org.apache.avro.ipc.Transceiver
    • close

      public void close(boolean awaitCompletion)
      Closes this transceiver and disconnects from the remote peer. Cancels all pending RPCs and sends an IOException to all pending callbacks.
      Parameters:
      awaitCompletion - if true, will block until the close has completed.
    • getRemoteName

      public String getRemoteName() throws IOException
      Specified by:
      getRemoteName in class org.apache.avro.ipc.Transceiver
      Throws:
      IOException
    • transceive

      public List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException
      Override as non-synchronized method because the method is thread safe.
      Overrides:
      transceive in class org.apache.avro.ipc.Transceiver
      Throws:
      IOException
    • transceive

      public void transceive(List<ByteBuffer> request, org.apache.avro.ipc.Callback<List<ByteBuffer>> callback) throws IOException
      Overrides:
      transceive in class org.apache.avro.ipc.Transceiver
      Throws:
      IOException
    • writeBuffers

      public void writeBuffers(List<ByteBuffer> buffers) throws IOException
      Specified by:
      writeBuffers in class org.apache.avro.ipc.Transceiver
      Throws:
      IOException
    • readBuffers

      public List<ByteBuffer> readBuffers() throws IOException
      Specified by:
      readBuffers in class org.apache.avro.ipc.Transceiver
      Throws:
      IOException
    • getRemote

      public org.apache.avro.Protocol getRemote()
      Overrides:
      getRemote in class org.apache.avro.ipc.Transceiver
    • isConnected

      public boolean isConnected()
      Overrides:
      isConnected in class org.apache.avro.ipc.Transceiver
    • setRemote

      public void setRemote(org.apache.avro.Protocol protocol)
      Overrides:
      setRemote in class org.apache.avro.ipc.Transceiver