Package org.apache.zookeeper
Class ClientCnxn
- java.lang.Object
-
- org.apache.zookeeper.ClientCnxn
-
public class ClientCnxn extends java.lang.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 int
packetLen
ZooKeeperSaslClient
zooKeeperSaslClient
-
Constructor Summary
Constructors Constructor Description ClientCnxn(java.lang.String chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper, ClientWatchManager watcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, boolean canBeReadOnly)
Creates a connection object.ClientCnxn(java.lang.String chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper, ClientWatchManager watcher, 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 void
addAuthInfo(java.lang.String scheme, byte[] auth)
void
close()
Close the connection, which includes; send session disconnect to the server, shutdown the send/event threads.void
disconnect()
Shutdown the send/event threads.void
enableWrite()
static boolean
getDisableAutoResetWatch()
tests use this to check on reset of watcheslong
getLastZxid()
long
getSessionId()
byte[]
getSessionPasswd()
int
getSessionTimeout()
int
getXid()
void
sendPacket(Record request, Record response, AsyncCallback cb, int opCode)
static void
setDisableAutoResetWatch(boolean b)
tests use this to set the auto resetvoid
start()
org.apache.zookeeper.proto.ReplyHeader
submitRequest(org.apache.zookeeper.proto.RequestHeader h, Record request, Record response, org.apache.zookeeper.ZooKeeper.WatchRegistration watchRegistration)
java.lang.String
toString()
-
-
-
Field Detail
-
zooKeeperSaslClient
public ZooKeeperSaslClient zooKeeperSaslClient
-
packetLen
public static final int packetLen
-
-
Constructor Detail
-
ClientCnxn
public ClientCnxn(java.lang.String chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper, ClientWatchManager watcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, boolean canBeReadOnly) throws java.io.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.zooKeeper
- the zookeeper object that this connection is related to.watcher
- 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:
java.io.IOException
-
ClientCnxn
public ClientCnxn(java.lang.String chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper, ClientWatchManager watcher, org.apache.zookeeper.ClientCnxnSocket clientCnxnSocket, long sessionId, byte[] sessionPasswd, boolean canBeReadOnly)
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.zooKeeper
- the zookeeper object that this connection is related to.watcher
- 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:
java.io.IOException
-
-
Method Detail
-
getSessionId
public long getSessionId()
-
getSessionPasswd
public byte[] getSessionPasswd()
-
getSessionTimeout
public int getSessionTimeout()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDisableAutoResetWatch
public static boolean getDisableAutoResetWatch()
tests use this to check on reset of watches- Returns:
- if the auto reset of watches are disabled
-
setDisableAutoResetWatch
public static void setDisableAutoResetWatch(boolean b)
tests use this to set the auto reset- Parameters:
b
- the value to set disable watches to
-
start
public void start()
-
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 java.io.IOException
Close the connection, which includes; send session disconnect to the server, shutdown the send/event threads.- Throws:
java.io.IOException
-
getXid
public int getXid()
-
submitRequest
public org.apache.zookeeper.proto.ReplyHeader submitRequest(org.apache.zookeeper.proto.RequestHeader h, Record request, Record response, org.apache.zookeeper.ZooKeeper.WatchRegistration watchRegistration) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
enableWrite
public void enableWrite()
-
sendPacket
public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode) throws java.io.IOException
- Throws:
java.io.IOException
-
addAuthInfo
public void addAuthInfo(java.lang.String scheme, byte[] auth)
-
-