org.apache.avro.ipc

## Class Transceiver

- java.lang.Object
- - org.apache.avro.ipc.Transceiver

- All Implemented Interfaces:
    Closeable, AutoCloseable
  Direct Known Subclasses:
    DatagramTransceiver, HttpTransceiver, LocalTransceiver, NettyTransceiver, SaslSocketTransceiver, SocketTransceiver

      public abstract class Transceiver
      extends Object
      implements Closeable

  Base transport class used by `Requestor`.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Transceiver()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `Protocol` | `getRemote()` Returns the protocol passed to `setRemote(Protocol)`.
    `abstract String` | `getRemoteName()`
    `boolean` | `isConnected()` True if a handshake has been completed for this connection.
    `void` | `lockChannel()` Acquires an exclusive lock on the transceiver's channel.
    `abstract List<ByteBuffer>` | `readBuffers()` Called by the default definition of `transceive(List)`.
    `void` | `setRemote(Protocol protocol)` Called with the remote protocol when a handshake has been completed.
    `List<ByteBuffer>` | `transceive(List<ByteBuffer> request)` Called by `Requestor.request(String,Object)` for two-way messages.
    `void` | `transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback)` Called by `Requestor.request(String,Object,Callback)` for two-way messages using callbacks.
    `void` | `unlockChannel()` Releases the lock on the transceiver's channel if held by the calling thread.
    `abstract 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`

- - ### Constructor Detail

    - #### Transceiver

          public Transceiver()

  - ### Method Detail

    - #### getRemoteName

          public abstract String getRemoteName()
                                        throws IOException

      Throws:
        `IOException`

    - #### lockChannel

          public void lockChannel()

      Acquires an exclusive lock on the transceiver's channel.

    - #### unlockChannel

          public void unlockChannel()

      Releases the lock on the transceiver's channel if held by the calling thread.

    - #### transceive

          public List<ByteBuffer> transceive(List<ByteBuffer> request)
                                      throws IOException

      Called by `Requestor.request(String,Object)` for two-way messages. By default calls `writeBuffers(List)` followed by `readBuffers()`.
      Throws:
        `IOException`

    - #### transceive

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

      Called by `Requestor.request(String,Object,Callback)` for two-way messages using callbacks.
      Throws:
        `IOException`

    - #### readBuffers

          public abstract List<ByteBuffer> readBuffers()
                                                throws IOException

      Called by the default definition of `transceive(List)`.
      Throws:
        `IOException`

    - #### writeBuffers

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

      Called by `Requestor.request(String,Object)` for one-way messages.
      Throws:
        `IOException`

    - #### isConnected

          public boolean isConnected()

      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.

    - #### setRemote

          public void setRemote(Protocol protocol)

      Called with the remote protocol when a handshake has been completed. After this has been called and while a connection is maintained, `isConnected()` should return true and #getRemote() should return this protocol. Does nothing by default.

    - #### getRemote

          public Protocol getRemote()

      Returns the protocol passed to `setRemote(Protocol)`. Throws IllegalStateException by default.

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

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