Package org.apache.zookeeper.server
Class NIOServerCnxn
- java.lang.Object
- 
- org.apache.zookeeper.server.ServerCnxn
- 
- org.apache.zookeeper.server.NIOServerCnxn
 
 
- 
- All Implemented Interfaces:
- ServerWatcher,- 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.ServerCnxnServerCnxn.CloseRequestException, ServerCnxn.DisconnectReason, ServerCnxn.EndOfStreamException
 - 
Nested classes/interfaces inherited from interface org.apache.zookeeper.WatcherWatcher.Event, Watcher.WatcherType
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected ByteBufferincomingBuffer- 
Fields inherited from class org.apache.zookeeper.server.ServerCnxncount, disconnectReason, established, lastCxid, lastLatency, lastOp, lastResponseTime, lastZxid, maxLatency, me, minLatency, packetsReceived, packetsSent, totalLatency, zooKeeperSaslServer
 
- 
 - 
Constructor SummaryConstructors Constructor Description NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory factory, NIOServerCnxnFactory.SelectorThread selectorThread)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose(ServerCnxn.DisconnectReason reason)Close the cnxn and remove it from the factory cnxns list.static voidcloseSock(SocketChannel sock)Close resources associated with a sock.voiddisableRecv(boolean waitDisableRecv)voiddisableSelectable()voidenableRecv()voidenableSelectable()Certificate[]getClientCertificateChain()intgetInterestOps()InetSocketAddressgetRemoteSocketAddress()longgetSessionId()intgetSessionTimeout()InetAddressgetSocketAddress()booleanisSecure()booleanisSelectable()protected booleanisSocketOpen()Only used in order to allow testingvoidprocess(WatchedEvent event, List<ACL> znodeAcl)protected voidreadRequest()voidsendBuffer(ByteBuffer... buffers)sendBuffer pushes a byte buffer onto the outgoing buffer queue for asynchronous writes.voidsendCloseSession()intsendResponse(ReplyHeader h, Record r, String tag, String cacheKey, Stat stat, int opCode)Serializes a ZooKeeper response and enqueues it for sending.protected ServerStatsserverStats()voidsetClientCertificateChain(Certificate[] chain)voidsetSessionId(long sessionId)voidsetSessionTimeout(int sessionTimeout)StringtoString()Used by "dump" 4-letter command to list all connection in cnxnExpiryMap- 
Methods inherited from class org.apache.zookeeper.server.ServerCnxnaddAuthInfo, 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, process, removeAuthInfo, resetStats, sendResponse, serialize, serializeRecord, setInvalid, setStale, updateStatsForResponse
 
- 
 
- 
- 
- 
Field Detail- 
incomingBufferprotected ByteBuffer incomingBuffer 
 
- 
 - 
Constructor Detail- 
NIOServerCnxnpublic NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory factory, NIOServerCnxnFactory.SelectorThread selectorThread) throws IOException - Throws:
- IOException
 
 
- 
 - 
Method Detail- 
sendCloseSessionpublic void sendCloseSession() - Specified by:
- sendCloseSessionin class- ServerCnxn
 
 - 
sendBufferpublic void sendBuffer(ByteBuffer... buffers) sendBuffer pushes a byte buffer onto the outgoing buffer queue for asynchronous writes.
 - 
isSelectablepublic boolean isSelectable() 
 - 
disableSelectablepublic void disableSelectable() 
 - 
enableSelectablepublic void enableSelectable() 
 - 
isSocketOpenprotected boolean isSocketOpen() Only used in order to allow testing
 - 
readRequestprotected void readRequest() throws IOException- Throws:
- IOException
 
 - 
disableRecvpublic void disableRecv(boolean waitDisableRecv) 
 - 
enableRecvpublic void enableRecv() 
 - 
getSessionTimeoutpublic int getSessionTimeout() 
 - 
toStringpublic String toString() Used by "dump" 4-letter command to list all connection in cnxnExpiryMap- Overrides:
- toStringin class- ServerCnxn
- See Also:
- for brief stats
 
 - 
closepublic void close(ServerCnxn.DisconnectReason reason) Close the cnxn and remove it from the factory cnxns list.- Specified by:
- closein class- ServerCnxn
 
 - 
closeSockpublic static void closeSock(SocketChannel sock) Close resources associated with a sock.
 - 
sendResponsepublic int sendResponse(ReplyHeader h, Record r, String tag, String cacheKey, Stat stat, int opCode) Description copied from class:ServerCnxnSerializes 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:
- sendResponsein 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.
 
 - 
processpublic void process(WatchedEvent event, List<ACL> znodeAcl) - Specified by:
- processin interface- ServerWatcher
- Specified by:
- processin class- ServerCnxn
 
 - 
getSessionIdpublic long getSessionId() - Specified by:
- getSessionIdin class- ServerCnxn
 
 - 
setSessionIdpublic void setSessionId(long sessionId) 
 - 
setSessionTimeoutpublic void setSessionTimeout(int sessionTimeout) 
 - 
getInterestOpspublic int getInterestOps() - Specified by:
- getInterestOpsin class- ServerCnxn
 
 - 
getRemoteSocketAddresspublic InetSocketAddress getRemoteSocketAddress() - Specified by:
- getRemoteSocketAddressin class- ServerCnxn
 
 - 
getSocketAddresspublic InetAddress getSocketAddress() 
 - 
serverStatsprotected ServerStats serverStats() - Specified by:
- serverStatsin class- ServerCnxn
 
 - 
isSecurepublic boolean isSecure() - Specified by:
- isSecurein class- ServerCnxn
 
 - 
getClientCertificateChainpublic Certificate[] getClientCertificateChain() - Specified by:
- getClientCertificateChainin class- ServerCnxn
 
 - 
setClientCertificateChainpublic void setClientCertificateChain(Certificate[] chain) - Specified by:
- setClientCertificateChainin class- ServerCnxn
 
 
- 
 
-