Package org.apache.zookeeper
Class ClientCnxn
java.lang.Object
org.apache.zookeeper.ClientCnxn
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
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionClientCnxn
(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
Modifier and TypeMethodDescriptionvoid
addAuthInfo
(String scheme, byte[] auth) void
close()
Close the connection, which includes; send session disconnect to the server, shutdown the send/event threads.void
Shutdown the send/event threads.protected void
finishPacket
(org.apache.zookeeper.ClientCnxn.Packet p) long
long
byte[]
int
int
getXid()
static boolean
Tests that current thread is the main event loop.protected void
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) 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) void
void
sendPacket
(Record request, Record response, AsyncCallback cb, int opCode) void
start()
submitRequest
(RequestHeader h, Record request, Record response, ZooKeeper.WatchRegistration watchRegistration) submitRequest
(RequestHeader h, Record request, Record response, ZooKeeper.WatchRegistration watchRegistration, WatchDeregistration watchDeregistration) toString()
-
Field Details
-
NOTIFICATION_XID
public static final int NOTIFICATION_XID- See Also:
-
PING_XID
public static final int PING_XID- See Also:
-
AUTHPACKET_XID
public static final int AUTHPACKET_XID- See Also:
-
SET_WATCHES_XID
public static final int SET_WATCHES_XID- See Also:
-
xid
protected int xid
-
-
Constructor Details
-
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 Details
-
getSessionId
public long getSessionId() -
getSessionPasswd
public byte[] getSessionPasswd() -
getSessionTimeout
public int getSessionTimeout() -
toString
-
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
-
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
Close 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
-
getZooKeeperSaslClient
-