Class 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.
    • Field Detail

      • incomingBuffer

        protected ByteBuffer incomingBuffer
    • Method Detail

      • 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
      • disableRecv

        public void disableRecv​(boolean waitDisableRecv)
      • enableRecv

        public void enableRecv()
      • getSessionTimeout

        public int getSessionTimeout()
      • 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.
      • setSessionId

        public void setSessionId​(long sessionId)
      • setSessionTimeout

        public void setSessionTimeout​(int sessionTimeout)
      • getSocketAddress

        public InetAddress getSocketAddress()