Class ServerCnxn

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

    public abstract class ServerCnxn
    extends java.lang.Object
    implements Watcher
    Interface to a Server connection - represents a connection from a client to the server.
    • Field Detail

      • me

        public static final java.lang.Object me
      • established

        protected final java.util.Date established
      • packetsReceived

        protected final java.util.concurrent.atomic.AtomicLong packetsReceived
      • packetsSent

        protected final java.util.concurrent.atomic.AtomicLong packetsSent
      • minLatency

        protected long minLatency
      • maxLatency

        protected long maxLatency
      • lastOp

        protected java.lang.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
    • Method Detail

      • incrOutstandingAndCheckThrottle

        public void incrOutstandingAndCheckThrottle​(RequestHeader h)
      • decrOutstandingAndCheckThrottle

        public void decrOutstandingAndCheckThrottle​(ReplyHeader h)
      • sendResponse

        public abstract int sendResponse​(ReplyHeader h,
                                         Record r,
                                         java.lang.String tag,
                                         java.lang.String cacheKey,
                                         Stat stat,
                                         int opCode)
                                  throws java.io.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:
        java.io.IOException
      • sendResponse

        public int sendResponse​(ReplyHeader h,
                                Record r,
                                java.lang.String tag)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeRecord

        protected byte[] serializeRecord​(Record record)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • serialize

        protected java.nio.ByteBuffer[] serialize​(ReplyHeader h,
                                                  Record r,
                                                  java.lang.String tag,
                                                  java.lang.String cacheKey,
                                                  Stat stat,
                                                  int opCode)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • sendCloseSession

        public abstract void sendCloseSession()
      • getSessionId

        public abstract long getSessionId()
      • getAuthInfo

        public java.util.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()
      • incrPacketsReceived

        protected long incrPacketsReceived()
      • incrPacketsSent

        protected long incrPacketsSent()
      • updateStatsForResponse

        protected void updateStatsForResponse​(long cxid,
                                              long zxid,
                                              java.lang.String op,
                                              long start,
                                              long end)
      • getEstablished

        public java.util.Date getEstablished()
      • getOutstandingRequests

        public long getOutstandingRequests()
      • getPacketsReceived

        public long getPacketsReceived()
      • getPacketsSent

        public long getPacketsSent()
      • getMinLatency

        public long getMinLatency()
      • getAvgLatency

        public long getAvgLatency()
      • getMaxLatency

        public long getMaxLatency()
      • getLastOperation

        public java.lang.String getLastOperation()
      • getLastCxid

        public long getLastCxid()
      • getLastZxid

        public long getLastZxid()
      • getLastResponseTime

        public long getLastResponseTime()
      • getLastLatency

        public long getLastLatency()
      • toString

        public java.lang.String toString()
        Prints detailed stats information for the connection.
        Overrides:
        toString in class java.lang.Object
        See Also:
        for brief stats
      • getRemoteSocketAddress

        public abstract java.net.InetSocketAddress getRemoteSocketAddress()
      • getInterestOps

        public abstract int getInterestOps()
      • isSecure

        public abstract boolean isSecure()
      • getClientCertificateChain

        public abstract java.security.cert.Certificate[] getClientCertificateChain()
      • setClientCertificateChain

        public abstract void setClientCertificateChain​(java.security.cert.Certificate[] chain)
      • dumpConnectionInfo

        public void dumpConnectionInfo​(java.io.PrintWriter pwriter,
                                       boolean brief)
        Print information about the connection.
        Parameters:
        brief - iff true prints brief details, otw full detail
      • getConnectionInfo

        public java.util.Map<java.lang.String,​java.lang.Object> getConnectionInfo​(boolean brief)
      • cleanupWriterSocket

        public void cleanupWriterSocket​(java.io.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 java.lang.String getHostAddress()
        Returns the IP address or empty string.
      • getSessionIdHex

        public java.lang.String getSessionIdHex()
        Get session id in hexadecimal notation.