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

org.apache.zookeeper.server

## Class ServerCnxn

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

- All Implemented Interfaces:
    Watcher
  Direct Known Subclasses:
    DumbWatcher, NettyServerCnxn, NIOServerCnxn

      public abstract class ServerCnxn
      extends Object
      implements Watcher

  Interface to a Server connection - represents a connection from a client to the server.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ServerCnxn.CloseRequestException`
    `static class` | `ServerCnxn.DisconnectReason`
    `protected static class` | `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 long` | `count`
    `protected ServerCnxn.DisconnectReason` | `disconnectReason`
    `protected Date` | `established`
    `protected long` | `lastCxid`
    `protected long` | `lastLatency`
    `protected String` | `lastOp`
    `protected long` | `lastResponseTime`
    `protected long` | `lastZxid`
    `protected long` | `maxLatency`
    `static Object` | `me`
    `protected long` | `minLatency`
    `protected AtomicLong` | `packetsReceived`
    `protected AtomicLong` | `packetsSent`
    `protected long` | `requestsProcessedCount`
    `protected long` | `totalLatency`
    `protected ZooKeeperSaslServer` | `zooKeeperSaslServer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ServerCnxn(ZooKeeperServer zkServer)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAuthInfo(Id id)`
    `void` | `cleanupWriterSocket(PrintWriter pwriter)` clean up the socket related to a command and also make sure we flush the data before we do that
    `abstract void` | `close(ServerCnxn.DisconnectReason reason)`
    `void` | `decrOutstandingAndCheckThrottle(ReplyHeader h)`
    `void` | `dumpConnectionInfo(PrintWriter pwriter, boolean brief)` Print information about the connection.
    `List<Id>` | `getAuthInfo()` auth info for the cnxn, returns an unmodifyable list
    `long` | `getAvgLatency()` Average latency in ms
    `abstract Certificate[]` | `getClientCertificateChain()`
    `Map<String,Object>` | `getConnectionInfo(boolean brief)`
    `Date` | `getEstablished()` Date/time the connection was established
    `String` | `getHostAddress()` Returns the IP address or empty string.
    `abstract int` | `getInterestOps()`
    `long` | `getLastCxid()` Last cxid of this connection
    `long` | `getLastLatency()` Latency of last response to client on this connection in ms
    `String` | `getLastOperation()` Last operation performed by this connection
    `long` | `getLastResponseTime()` Last time server sent a response to client on this connection
    `long` | `getLastZxid()` Last zxid of this connection
    `long` | `getMaxLatency()` Max latency in ms
    `long` | `getMinLatency()` Min latency in ms
    `long` | `getOutstandingRequests()` The number of requests that have been submitted but not yet responded to.
    `long` | `getPacketsReceived()` Number of packets received
    `long` | `getPacketsSent()` Number of packets sent (incl notifications)
    `abstract InetSocketAddress` | `getRemoteSocketAddress()`
    `abstract long` | `getSessionId()`
    `String` | `getSessionIdHex()` Get session id in hexadecimal notation.
    `void` | `incrOutstandingAndCheckThrottle(RequestHeader h)`
    `protected long` | `incrPacketsReceived()`
    `protected long` | `incrPacketsSent()`
    `boolean` | `isInvalid()`
    `abstract boolean` | `isSecure()`
    `boolean` | `isStale()`
    `boolean` | `isZKServerRunning()`
    `protected void` | `packetReceived(long bytes)`
    `protected void` | `packetSent()`
    `abstract void` | `process(WatchedEvent event)`
    `boolean` | `removeAuthInfo(Id id)`
    `void` | `resetStats()` Reset counters
    `abstract void` | `sendCloseSession()`
    `int` | `sendResponse(ReplyHeader h, Record r, String tag)`
    `abstract int` | `sendResponse(ReplyHeader h, Record r, String tag, String cacheKey, Stat stat, int opCode)` Serializes a ZooKeeper response and enqueues it for sending.
    `protected ByteBuffer[]` | `serialize(ReplyHeader h, Record r, String tag, String cacheKey, Stat stat, int opCode)`
    `protected byte[]` | `serializeRecord(Record record)`
    `protected abstract ServerStats` | `serverStats()`
    `abstract void` | `setClientCertificateChain(Certificate[] chain)`
    `void` | `setInvalid()`
    `void` | `setStale()`
    `String` | `toString()` Prints detailed stats information for the connection.
    `protected void` | `updateStatsForResponse(long cxid, long zxid, String op, long start, long end)`

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

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

- - ### Field Detail

    - #### me

          public static final Object me

    - #### zooKeeperSaslServer

          protected ZooKeeperSaslServer zooKeeperSaslServer

    - #### established

          protected final Date established

    - #### packetsReceived

          protected final AtomicLong packetsReceived

    - #### packetsSent

          protected final AtomicLong packetsSent

    - #### minLatency

          protected long minLatency

    - #### maxLatency

          protected long maxLatency

    - #### lastOp

          protected String lastOp

    - #### lastCxid

          protected long lastCxid

    - #### lastZxid

          protected long lastZxid

    - #### lastResponseTime

          protected long lastResponseTime

    - #### lastLatency

          protected long lastLatency

    - #### count

          protected long count

    - #### totalLatency

          protected long totalLatency

    - #### requestsProcessedCount

          protected long requestsProcessedCount

    - #### disconnectReason

          protected ServerCnxn.DisconnectReason disconnectReason

  - ### Constructor Detail

    - #### ServerCnxn

          public ServerCnxn(ZooKeeperServer zkServer)

  - ### Method Detail

    - #### incrOutstandingAndCheckThrottle

          public void incrOutstandingAndCheckThrottle(RequestHeader h)

    - #### decrOutstandingAndCheckThrottle

          public void decrOutstandingAndCheckThrottle(ReplyHeader h)

    - #### close

          public abstract void close(ServerCnxn.DisconnectReason reason)

    - #### sendResponse

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

      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.
      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.
      Throws:
        `IOException`

    - #### sendResponse

          public int sendResponse(ReplyHeader h,
                                  Record r,
                                  String tag)
                           throws IOException

      Throws:
        `IOException`

    - #### serializeRecord

          protected byte[] serializeRecord(Record record)
                                    throws IOException

      Throws:
        `IOException`

    - #### serialize

          protected ByteBuffer[] serialize(ReplyHeader h,
                                           Record r,
                                           String tag,
                                           String cacheKey,
                                           Stat stat,
                                           int opCode)
                                    throws IOException

      Throws:
        `IOException`

    - #### sendCloseSession

          public abstract void sendCloseSession()

    - #### process

          public abstract void process(WatchedEvent event)

      Specified by:
        `process` in interface `Watcher`

    - #### getSessionId

          public abstract long getSessionId()

    - #### getAuthInfo

          public List<Id> getAuthInfo()

      auth info for the cnxn, returns an unmodifyable list

    - #### addAuthInfo

          public void addAuthInfo(Id id)

    - #### removeAuthInfo

          public boolean removeAuthInfo(Id id)

    - #### isStale

          public boolean isStale()

    - #### setStale

          public void setStale()

    - #### isInvalid

          public boolean isInvalid()

    - #### setInvalid

          public void setInvalid()

    - #### packetReceived

          protected void packetReceived(long bytes)

    - #### packetSent

          protected void packetSent()

    - #### serverStats

          protected abstract ServerStats serverStats()

    - #### resetStats

          public void resetStats()

      Reset counters

    - #### incrPacketsReceived

          protected long incrPacketsReceived()

    - #### incrPacketsSent

          protected long incrPacketsSent()

    - #### updateStatsForResponse

          protected void updateStatsForResponse(long cxid,
                                                long zxid,
                                                String op,
                                                long start,
                                                long end)

    - #### getEstablished

          public Date getEstablished()

      Date/time the connection was established

    - #### getOutstandingRequests

          public long getOutstandingRequests()

      The number of requests that have been submitted but not yet responded to.

    - #### getPacketsReceived

          public long getPacketsReceived()

      Number of packets received

    - #### getPacketsSent

          public long getPacketsSent()

      Number of packets sent (incl notifications)

    - #### getMinLatency

          public long getMinLatency()

      Min latency in ms

    - #### getAvgLatency

          public long getAvgLatency()

      Average latency in ms

    - #### getMaxLatency

          public long getMaxLatency()

      Max latency in ms

    - #### getLastOperation

          public String getLastOperation()

      Last operation performed by this connection

    - #### getLastCxid

          public long getLastCxid()

      Last cxid of this connection

    - #### getLastZxid

          public long getLastZxid()

      Last zxid of this connection

    - #### getLastResponseTime

          public long getLastResponseTime()

      Last time server sent a response to client on this connection

    - #### getLastLatency

          public long getLastLatency()

      Latency of last response to client on this connection in ms

    - #### toString

          public String toString()

      Prints detailed stats information for the connection.
      Overrides:
        `toString` in class `Object`
      See Also:
        `for brief stats`

    - #### getRemoteSocketAddress

          public abstract InetSocketAddress getRemoteSocketAddress()

    - #### getInterestOps

          public abstract int getInterestOps()

    - #### isSecure

          public abstract boolean isSecure()

    - #### getClientCertificateChain

          public abstract Certificate[] getClientCertificateChain()

    - #### setClientCertificateChain

          public abstract void setClientCertificateChain(Certificate[] chain)

    - #### dumpConnectionInfo

          public void dumpConnectionInfo(PrintWriter pwriter,
                                         boolean brief)

      Print information about the connection.
      Parameters:
        `brief` - iff true prints brief details, otw full detail

    - #### getConnectionInfo

          public Map<String,Object> getConnectionInfo(boolean brief)

    - #### cleanupWriterSocket

          public void cleanupWriterSocket(PrintWriter pwriter)

      clean up the socket related to a command and also make sure we flush the data before we do that
      Parameters:
        `pwriter` - the pwriter for a command socket

    - #### isZKServerRunning

          public boolean isZKServerRunning()

      Returns:
        true if the server is running, false otherwise.

    - #### getHostAddress

          public String getHostAddress()

      Returns the IP address or empty string.

    - #### getSessionIdHex

          public String getSessionIdHex()

      Get session id in hexadecimal notation.

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