Package org.apache.zookeeper
Class ClientCnxn
- java.lang.Object
-
- org.apache.zookeeper.ClientCnxn
-
public class ClientCnxn extends Object
This class manages the socket i/o for the client. ClientCnxn maintains a list of available servers to connect to and "transparently" switches servers it is connected to as needed.
-
-
Field Summary
Fields Modifier and Type Field Description static intAUTHPACKET_XIDstatic intNOTIFICATION_XIDstatic intPING_XIDstatic intSET_WATCHES_XIDprotected intxid
-
Constructor Summary
Constructors Constructor Description ClientCnxn(String chrootPath, HostProvider hostProvider, int sessionTimeout, ZKClientConfig clientConfig, Watcher defaultWatcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, boolean canBeReadOnly)Creates a connection object.ClientCnxn(String chrootPath, HostProvider hostProvider, int sessionTimeout, ZKClientConfig clientConfig, Watcher defaultWatcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, long sessionId, byte[] sessionPasswd, boolean canBeReadOnly)Creates a connection object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAuthInfo(String scheme, byte[] auth)voidclose()Close the connection, which includes; send session disconnect to the server, shutdown the send/event threads.voiddisconnect()Shutdown the send/event threads.protected voidfinishPacket(org.apache.zookeeper.ClientCnxn.Packet p)longgetLastZxid()longgetSessionId()byte[]getSessionPasswd()intgetSessionTimeout()intgetXid()ZooKeeperSaslClientgetZooKeeperSaslClient()static booleanisInEventThread()Tests that current thread is the main event loop.protected voidonConnecting(InetSocketAddress addr)org.apache.zookeeper.ClientCnxn.PacketqueuePacket(RequestHeader h, ReplyHeader r, Record request, Record response, AsyncCallback cb, String clientPath, String serverPath, Object ctx, ZooKeeper.WatchRegistration watchRegistration)org.apache.zookeeper.ClientCnxn.PacketqueuePacket(RequestHeader h, ReplyHeader r, Record request, Record response, AsyncCallback cb, String clientPath, String serverPath, Object ctx, ZooKeeper.WatchRegistration watchRegistration, WatchDeregistration watchDeregistration)voidsaslCompleted()voidsendPacket(Record request, Record response, AsyncCallback cb, int opCode)voidstart()ReplyHeadersubmitRequest(RequestHeader h, Record request, Record response, ZooKeeper.WatchRegistration watchRegistration)ReplyHeadersubmitRequest(RequestHeader h, Record request, Record response, ZooKeeper.WatchRegistration watchRegistration, WatchDeregistration watchDeregistration)StringtoString()
-
-
-
Field Detail
-
NOTIFICATION_XID
public static final int NOTIFICATION_XID
- See Also:
- Constant Field Values
-
PING_XID
public static final int PING_XID
- See Also:
- Constant Field Values
-
AUTHPACKET_XID
public static final int AUTHPACKET_XID
- See Also:
- Constant Field Values
-
SET_WATCHES_XID
public static final int SET_WATCHES_XID
- See Also:
- Constant Field Values
-
xid
protected int xid
-
-
Constructor Detail
-
ClientCnxn
public ClientCnxn(String chrootPath, HostProvider hostProvider, int sessionTimeout, ZKClientConfig clientConfig, Watcher defaultWatcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, boolean canBeReadOnly) throws IOException
Creates a connection object. The actual network connect doesn't get established until needed. The start() instance method must be called subsequent to construction.- Parameters:
chrootPath- the chroot of this client. Should be removed from this Class in ZOOKEEPER-838hostProvider- the list of ZooKeeper servers to connect tosessionTimeout- the timeout for connections.clientConfig- the client configuration.defaultWatcher- default watcher for this connectionclientCnxnSocket- the socket implementation used (e.g. NIO/Netty)canBeReadOnly- whether the connection is allowed to go to read-only mode in case of partitioning- Throws:
IOException
-
ClientCnxn
public ClientCnxn(String chrootPath, HostProvider hostProvider, int sessionTimeout, ZKClientConfig clientConfig, Watcher defaultWatcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, long sessionId, byte[] sessionPasswd, boolean canBeReadOnly) throws IOException
Creates a connection object. The actual network connect doesn't get established until needed. The start() instance method must be called subsequent to construction.- Parameters:
chrootPath- the chroot of this client. Should be removed from this Class in ZOOKEEPER-838hostProvider- the list of ZooKeeper servers to connect tosessionTimeout- the timeout for connections.clientConfig- the client configuration.defaultWatcher- default watcher for this connectionclientCnxnSocket- the socket implementation used (e.g. NIO/Netty)sessionId- session id if re-establishing sessionsessionPasswd- session passwd if re-establishing sessioncanBeReadOnly- whether the connection is allowed to go to read-only mode in case of partitioning- Throws:
IOException- in cases of broken network
-
-
Method Detail
-
getSessionId
public long getSessionId()
-
getSessionPasswd
public byte[] getSessionPasswd()
-
getSessionTimeout
public int getSessionTimeout()
-
start
public void start()
-
isInEventThread
public static boolean isInEventThread()
Tests that current thread is the main event loop. This method is useful only for tests inside ZooKeeper project it is not a public API intended for use by external applications.- Returns:
- true if Thread.currentThread() is an EventThread.
-
finishPacket
protected void finishPacket(org.apache.zookeeper.ClientCnxn.Packet p)
-
onConnecting
protected void onConnecting(InetSocketAddress addr)
-
getLastZxid
public long getLastZxid()
-
disconnect
public void disconnect()
Shutdown the send/event threads. This method should not be called directly - rather it should be called as part of close operation. This method is primarily here to allow the tests to verify disconnection behavior.
-
close
public void close() throws IOExceptionClose the connection, which includes; send session disconnect to the server, shutdown the send/event threads.- Throws:
IOException
-
getXid
public int getXid()
-
submitRequest
public ReplyHeader submitRequest(RequestHeader h, Record request, Record response, ZooKeeper.WatchRegistration watchRegistration) throws InterruptedException
- Throws:
InterruptedException
-
submitRequest
public ReplyHeader submitRequest(RequestHeader h, Record request, Record response, ZooKeeper.WatchRegistration watchRegistration, WatchDeregistration watchDeregistration) throws InterruptedException
- Throws:
InterruptedException
-
saslCompleted
public void saslCompleted()
-
sendPacket
public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode) throws IOException
- Throws:
IOException
-
queuePacket
public org.apache.zookeeper.ClientCnxn.Packet queuePacket(RequestHeader h, ReplyHeader r, Record request, Record response, AsyncCallback cb, String clientPath, String serverPath, Object ctx, ZooKeeper.WatchRegistration watchRegistration)
-
queuePacket
public org.apache.zookeeper.ClientCnxn.Packet queuePacket(RequestHeader h, ReplyHeader r, Record request, Record response, AsyncCallback cb, String clientPath, String serverPath, Object ctx, ZooKeeper.WatchRegistration watchRegistration, WatchDeregistration watchDeregistration)
-
addAuthInfo
public void addAuthInfo(String scheme, byte[] auth)
-
getZooKeeperSaslClient
public ZooKeeperSaslClient getZooKeeperSaslClient()
-
-