NIOServerCnxn (Apache ZooKeeper - Server 3.7.0 API)
Date: 2021-03-17

org.apache.zookeeper.server

## Class NIOServerCnxn

- java.lang.Object
- - org.apache.zookeeper.server.ServerCnxn
  - - org.apache.zookeeper.server.NIOServerCnxn

- All Implemented Interfaces:
    Watcher
  Direct Known Subclasses:
    ControllableConnection

      public class NIOServerCnxn
      extends ServerCnxn

  This class handles communication with clients using NIO. There is one per client, but only one thread doing the communication.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.zookeeper.server.ServerCnxn

      `ServerCnxn.CloseRequestException, ServerCnxn.DisconnectReason, ServerCnxn.EndOfStreamException`

    - ### Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher

      `Watcher.Event, Watcher.WatcherType`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ByteBuffer` | `incomingBuffer`

    - ### Fields inherited from class org.apache.zookeeper.server.ServerCnxn

      `count, disconnectReason, established, lastCxid, lastLatency, lastOp, lastResponseTime, lastZxid, maxLatency, me, minLatency, packetsReceived, packetsSent, requestsProcessedCount, totalLatency, zooKeeperSaslServer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory factory, NIOServerCnxnFactory.SelectorThread selectorThread)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close(ServerCnxn.DisconnectReason reason)` Close the cnxn and remove it from the factory cnxns list.
    `static void` | `closeSock(SocketChannel sock)` Close resources associated with a sock.
    `void` | `disableRecv(boolean waitDisableRecv)`
    `void` | `disableSelectable()`
    `void` | `enableRecv()`
    `void` | `enableSelectable()`
    `Certificate[]` | `getClientCertificateChain()`
    `int` | `getInterestOps()`
    `InetSocketAddress` | `getRemoteSocketAddress()`
    `long` | `getSessionId()`
    `int` | `getSessionTimeout()`
    `InetAddress` | `getSocketAddress()`
    `boolean` | `isSecure()`
    `boolean` | `isSelectable()`
    `protected boolean` | `isSocketOpen()` Only used in order to allow testing
    `void` | `process(WatchedEvent event)`
    `protected void` | `readRequest()`
    `void` | `sendBuffer(ByteBuffer... buffers)` sendBuffer pushes a byte buffer onto the outgoing buffer queue for asynchronous writes.
    `void` | `sendCloseSession()`
    `int` | `sendResponse(ReplyHeader h, Record r, String tag, String cacheKey, Stat stat, int opCode)` Serializes a ZooKeeper response and enqueues it for sending.
    `protected ServerStats` | `serverStats()`
    `void` | `setClientCertificateChain(Certificate[] chain)`
    `void` | `setSessionId(long sessionId)`
    `void` | `setSessionTimeout(int sessionTimeout)`
    `String` | `toString()` Used by "dump" 4-letter command to list all connection in cnxnExpiryMap

    - ### Methods inherited from class org.apache.zookeeper.server.ServerCnxn

      `addAuthInfo, cleanupWriterSocket, decrOutstandingAndCheckThrottle, dumpConnectionInfo, getAuthInfo, getAvgLatency, getConnectionInfo, getEstablished, getHostAddress, getLastCxid, getLastLatency, getLastOperation, getLastResponseTime, getLastZxid, getMaxLatency, getMinLatency, getOutstandingRequests, getPacketsReceived, getPacketsSent, getSessionIdHex, incrOutstandingAndCheckThrottle, incrPacketsReceived, incrPacketsSent, isInvalid, isStale, isZKServerRunning, packetReceived, packetSent, removeAuthInfo, resetStats, sendResponse, serialize, serializeRecord, setInvalid, setStale, updateStatsForResponse`

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

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

- - ### Field Detail

    - #### incomingBuffer

          protected ByteBuffer incomingBuffer

  - ### Constructor Detail

    - #### NIOServerCnxn

          public NIOServerCnxn(ZooKeeperServer zk,
                               SocketChannel sock,
                               SelectionKey sk,
                               NIOServerCnxnFactory factory,
                               NIOServerCnxnFactory.SelectorThread selectorThread)
                        throws IOException

      Throws:
        `IOException`

  - ### Method Detail

    - #### sendCloseSession

          public void sendCloseSession()

      Specified by:
        `sendCloseSession` in class `ServerCnxn`

    - #### sendBuffer

          public void sendBuffer(ByteBuffer... buffers)

      sendBuffer pushes a byte buffer onto the outgoing buffer queue for asynchronous writes.

    - #### isSelectable

          public boolean isSelectable()

    - #### disableSelectable

          public void disableSelectable()

    - #### enableSelectable

          public void enableSelectable()

    - #### isSocketOpen

          protected boolean isSocketOpen()

      Only used in order to allow testing

    - #### readRequest

          protected void readRequest()
                              throws IOException

      Throws:
        `IOException`

    - #### disableRecv

          public void disableRecv(boolean waitDisableRecv)

    - #### enableRecv

          public void enableRecv()

    - #### getSessionTimeout

          public int getSessionTimeout()

    - #### toString

          public String toString()

      Used by "dump" 4-letter command to list all connection in cnxnExpiryMap
      Overrides:
        `toString` in class `ServerCnxn`
      See Also:
        `for brief stats`

    - #### close

          public void close(ServerCnxn.DisconnectReason reason)

      Close the cnxn and remove it from the factory cnxns list.
      Specified by:
        `close` in class `ServerCnxn`

    - #### closeSock

          public static void closeSock(SocketChannel sock)

      Close resources associated with a sock.

    - #### sendResponse

          public int sendResponse(ReplyHeader h,
                                  Record r,
                                  String tag,
                                  String cacheKey,
                                  Stat stat,
                                  int opCode)

      Description copied from class: `ServerCnxn`
      Serializes a ZooKeeper response and enqueues it for sending. Serializes client response parts and enqueues them into outgoing queue. If both cache key and last modified zxid are provided, the serialized response is caсhed under the provided key, the last modified zxid is stored along with the value. A cache entry is invalidated if the provided last modified zxid is more recent than the stored one. Attention: this function is not thread safe, due to caching not being thread safe.
      Specified by:
        `sendResponse` in class `ServerCnxn`
      Parameters:
        `h` - reply header
        `r` - reply payload, can be null
        `tag` - Jute serialization tag, can be null
        `cacheKey` - Key for caching the serialized payload. A null value prevents caching.
        `stat` - Stat information for the the reply payload, used for cache invalidation. A value of 0 prevents caching.
        `opCode` - The op code appertains to the corresponding request of the response, used to decide which cache (e.g. read response cache, list of children response cache, ...) object to look up to when applicable.

    - #### process

          public void process(WatchedEvent event)

      Specified by:
        `process` in interface `Watcher`
      Specified by:
        `process` in class `ServerCnxn`

    - #### getSessionId

          public long getSessionId()

      Specified by:
        `getSessionId` in class `ServerCnxn`

    - #### setSessionId

          public void setSessionId(long sessionId)

    - #### setSessionTimeout

          public void setSessionTimeout(int sessionTimeout)

    - #### getInterestOps

          public int getInterestOps()

      Specified by:
        `getInterestOps` in class `ServerCnxn`

    - #### getRemoteSocketAddress

          public InetSocketAddress getRemoteSocketAddress()

      Specified by:
        `getRemoteSocketAddress` in class `ServerCnxn`

    - #### getSocketAddress

          public InetAddress getSocketAddress()

    - #### serverStats

          protected ServerStats serverStats()

      Specified by:
        `serverStats` in class `ServerCnxn`

    - #### isSecure

          public boolean isSecure()

      Specified by:
        `isSecure` in class `ServerCnxn`

    - #### getClientCertificateChain

          public Certificate[] getClientCertificateChain()

      Specified by:
        `getClientCertificateChain` in class `ServerCnxn`

    - #### setClientCertificateChain

          public void setClientCertificateChain(Certificate[] chain)

      Specified by:
        `setClientCertificateChain` in class `ServerCnxn`

Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.