Example #1
0
        /**
         * Creates a connection object. The actual network connect doesn't get
         * established until needed. The start() instance method must be called
         * subsequent to construction.
         *
         * @param chrootPath - the chroot of this client. Should be removed from this Class in ZOOKEEPER-838
         * @param hostProvider
         *            the list of ZooKeeper servers to connect to
         * @param sessionTimeout
         *            the timeout for connections.
         * @param zooKeeper
         *            the zookeeper object that this connection is related to.
         * @param watcher watcher for this connection
         * @param clientCnxnSocket
         *            the socket implementation used (e.g. NIO/Netty)
         * @param sessionId
         *            session id if re-establishing session
         * @param sessionPasswd
         *            session passwd if re-establishing session
         * @param canBeReadOnly
         *            whether the connection is allowed to go to read-only mode in
         *            case of partitioning
         * @throws IOException
         */

        internal ClientCnxn(string chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper,
                            ClientWatchManager watcher,
                            long sessionId, byte[] sessionPasswd, bool canBeReadOnly)
        {
            this.zooKeeper      = zooKeeper;
            this.watcher        = watcher;
            this.sessionId      = sessionId;
            this.sessionPasswd  = sessionPasswd;
            this.sessionTimeout = sessionTimeout;
            this.hostProvider   = hostProvider;
            this.chrootPath     = chrootPath;
            readTimeout         = sessionTimeout * 2 / 3;
            readOnly            = canBeReadOnly;
            clientCnxnSocket    = new ClientCnxnSocketNIO(this);
            timer       = new Timer(delegate { clientCnxnSocket.wakeupCnxn(); }, null, Timeout.Infinite, Timeout.Infinite);
            state.Value = (int)ZooKeeper.States.CONNECTING;
        }
Example #2
0
 private void close()
 {
     state.Value = (int)ZooKeeper.States.CLOSED;
     clientCnxnSocket.wakeupCnxn();
 }