Exemplo n.º 1
0
        /// <summary>
        /// connect to zookeeper
        /// </summary>
        /// <param name="name"></param>
        /// <param name="connection"></param>
        private void ConnectToZookeeper(string name, IConnection connection)
        {
            var connectRequest = new Data.ConnectRequest(this._protocolVersion,
                                                         this._zkClient._lastZxid,
                                                         (int)this._zkClient._sessionTimeout.TotalMilliseconds,
                                                         this._sessionID,
                                                         this._sessionPassword);

            var request = new Request <ZookResponse>(this._zkClient.NextRequestSeqID(), "connect",
                                                     Utils.Marshaller.Serialize(connectRequest, true),
                                                     ex => connection.BeginDisconnect(ex),
                                                     response =>
            {
                Data.ConnectResponse result = null;
                try { result = Utils.Marshaller.Deserialize <Data.ConnectResponse>(response.Payload); }
                catch (Exception ex) { connection.BeginDisconnect(ex); return; }

                if (result.SessionTimeOut <= 0)    //session expired
                {
                    this._protocolVersion          = 0;
                    this._sessionID                = 0;
                    this._negotiatedSessionTimeout = 0;
                    this._sessionPassword          = new byte[16];

                    connection.BeginDisconnect(new ApplicationException("zookeeper session expired"));
                    this._zkClient.SetKeeperState(Data.KeeperState.Expired); return;
                }

                this._protocolVersion          = result.ProtocolVersion;
                this._negotiatedSessionTimeout = result.SessionTimeOut;
                this._sessionID       = result.SessionID;
                this._sessionPassword = result.SessionPassword;

                this._currConnection = connection;
                this._zkClient.SetKeeperState(Data.KeeperState.SyncConnected);
                this.FireServerAvailable(name, connection);
            })
            {
                Tag = "connect"
            };

            connection.UserData = request;
            connection.BeginSend(request);
        }
Exemplo n.º 2
0
        /// <summary>
        /// connect to zookeeper
        /// </summary>
        /// <param name="name"></param>
        /// <param name="connection"></param>
        private void ConnectToZookeeper(string name, IConnection connection)
        {
            var connectRequest = new Data.ConnectRequest(this._protocolVersion,
                this._zkClient._lastZxid,
                (int)this._zkClient._sessionTimeout.TotalMilliseconds,
                this._sessionID,
                this._sessionPassword);

            var request = new Request<ZookResponse>(this._zkClient.NextRequestSeqID(), "connect",
                Utils.Marshaller.Serialize(connectRequest, true),
                ex => connection.BeginDisconnect(ex),
                response =>
                {
                    Data.ConnectResponse result = null;
                    try { result = Utils.Marshaller.Deserialize<Data.ConnectResponse>(response.Payload); }
                    catch (Exception ex) { connection.BeginDisconnect(ex); return; }

                    if (result.SessionTimeOut <= 0)//session expired
                    {
                        this._protocolVersion = 0;
                        this._sessionID = 0;
                        this._negotiatedSessionTimeout = 0;
                        this._sessionPassword = new byte[16];

                        connection.BeginDisconnect(new ApplicationException("zookeeper session expired"));
                        this._zkClient.SetKeeperState(Data.KeeperState.Expired); return;
                    }

                    this._protocolVersion = result.ProtocolVersion;
                    this._negotiatedSessionTimeout = result.SessionTimeOut;
                    this._sessionID = result.SessionID;
                    this._sessionPassword = result.SessionPassword;

                    this._currConnection = connection;
                    this._zkClient.SetKeeperState(Data.KeeperState.SyncConnected);
                    this.FireServerAvailable(name, connection);
                }) { Tag = "connect" };

            connection.UserData = request;
            connection.BeginSend(request);
        }