org.apache.avro.ipc.netty

## 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 Transceiver

  A Netty-based `Transceiver` implementation.

- - ### Nested Class Summary

    Nested Classes
    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.

  - ### Field Summary

    Fields
    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 Summary

    Constructors
    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.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### 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:
        Constant Field Values

    - #### NETTY_CONNECT_TIMEOUT_OPTION

          public static final String NETTY_CONNECT_TIMEOUT_OPTION

      See Also:
        Constant Field Values

    - #### NETTY_TCP_NODELAY_OPTION

          public static final String NETTY_TCP_NODELAY_OPTION

      See Also:
        Constant Field Values

    - #### NETTY_KEEPALIVE_OPTION

          public static final String NETTY_KEEPALIVE_OPTION

      See Also:
        Constant Field Values

    - #### DEFAULT_TCP_NODELAY_VALUE

          public static final boolean DEFAULT_TCP_NODELAY_VALUE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### 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 Detail

    - #### 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 `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 `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 `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `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 `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 `Transceiver`
      Throws:
        `IOException`

    - #### transceive

          public void transceive(List<ByteBuffer> request,
                                 Callback<List<ByteBuffer>> callback)
                          throws IOException

      Description copied from class: `Transceiver`
      Called by `Requestor.request(String,Object,Callback)` for two-way messages using callbacks.
      Overrides:
        `transceive` in class `Transceiver`
      Throws:
        `IOException`

    - #### writeBuffers

          public void writeBuffers(List<ByteBuffer> buffers)
                            throws IOException

      Description copied from class: `Transceiver`
      Called by `Requestor.request(String,Object)` for one-way messages.
      Specified by:
        `writeBuffers` in class `Transceiver`
      Throws:
        `IOException`

    - #### readBuffers

          public List<ByteBuffer> readBuffers()
                                       throws IOException

      Description copied from class: `Transceiver`
      Called by the default definition of `Transceiver.transceive(List)`.
      Specified by:
        `readBuffers` in class `Transceiver`
      Throws:
        `IOException`

    - #### getRemote

          public Protocol getRemote()

      Description copied from class: `Transceiver`
      Returns the protocol passed to `Transceiver.setRemote(Protocol)`. Throws IllegalStateException by default.
      Overrides:
        `getRemote` in class `Transceiver`

    - #### isConnected

          public boolean isConnected()

      Description copied from class: `Transceiver`
      True if a handshake has been completed for this connection. Used to determine whether a handshake need be completed prior to a one-way message. Requests and responses are always prefixed by handshakes, but one-way messages. If the first request sent over a connection is one-way, then a handshake-only response is returned. Subsequent one-way messages over the connection will have no response data sent. Returns false by default.
      Overrides:
        `isConnected` in class `Transceiver`

    - #### setRemote

          public void setRemote(Protocol protocol)

      Description copied from class: `Transceiver`
      Called with the remote protocol when a handshake has been completed. After this has been called and while a connection is maintained, `Transceiver.isConnected()` should return true and #getRemote() should return this protocol. Does nothing by default.
      Overrides:
        `setRemote` in class `Transceiver`

Copyright © 2009–2024 The Apache Software Foundation. All rights reserved.