コード例 #1
0
ファイル: Session.cs プロジェクト: Azure/RingMaster
            public void Process(WatchedEvent evt)
            {
                var watcherCall = new WatcherCall();
                watcherCall.WatcherId = this.Id;
                watcherCall.Kind = this.Kind;
                watcherCall.WatcherEvt = evt;

                this.session.SendWatcherNotification(watcherCall);
            }
コード例 #2
0
ファイル: ZooKeeperSession.cs プロジェクト: Azure/RingMaster
            public void Process(WatchedEvent evt)
            {
                var watcherCall = new WatcherCall();

                watcherCall.WatcherId  = this.Id;
                watcherCall.Kind       = this.Kind;
                watcherCall.WatcherEvt = evt;

                this.session.SendWatcherNotification(watcherCall);
                Trace.TraceInformation("Watcher Notification Sent WatcherId:{0}, Evt:{1}", watcherCall.WatcherId, watcherCall.WatcherEvt);
            }
コード例 #3
0
ファイル: Session.cs プロジェクト: Azure/RingMaster
        /// <summary>
        /// Sends the watcher notification
        /// </summary>
        /// <param name="watcherCall">Watcher call</param>
        internal void SendWatcherNotification(WatcherCall watcherCall)
        {
            RingMasterServerEventSource.Log.SendWatcherNotification(this.sessionId, watcherCall.WatcherId);
            var messageToClient = new RequestResponse();
            messageToClient.CallId = ulong.MaxValue;
            messageToClient.Content = watcherCall;

            byte[] packet = this.protocol.SerializeResponse(messageToClient, this.connection.ProtocolVersion);
            this.connection.Send(packet);

            this.instrumentation?.OnWatcherNotified(this.sessionId);
        }
コード例 #4
0
ファイル: ZkprSerializer.cs プロジェクト: Azure/RingMaster
        /// <summary>
        /// Serializes a response object
        /// </summary>
        /// <param name="response">Response object</param>
        public void SerializeWatcherResponse(RequestResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            this.SerializeReplyHeader(response.Stat == null ? 0L : response.Stat.Mzxid, response.ResultCode, (int)this.watcherNotificationId); // Watcher has 'special id'
            WatcherCall wc = response.Content as WatcherCall;

            this.binaryWriter.WriteBE((int)wc.WatcherEvt.EventType);
            this.binaryWriter.WriteBE((int)wc.WatcherEvt.KeeperState);
            this.binaryWriter.WriteString32BitPrefixLengthBE(wc.WatcherEvt.Path);
        }
コード例 #5
0
ファイル: Deserializer.cs プロジェクト: Azure/RingMaster
        /// <summary>
        /// Deserialize a <see cref="WatcherCall"/>
        /// </summary>
        /// <returns>A <see cref="WatcherCall"/></returns>
        private WatcherCall DeserializeWatcherCall()
        {
            WatcherCall watcherCall = new WatcherCall();

            watcherCall.WatcherId = this.binaryReader.ReadUInt64();

            if (this.serializationVersionUsed >= SerializationFormatVersions.Version23)
            {
                watcherCall.Kind = (WatcherKind)this.binaryReader.ReadByte();
            }
            else
            {
                watcherCall.Kind = this.binaryReader.ReadBoolean() ? WatcherKind.OneUse : default(WatcherKind);
            }

            bool nullwatcher = this.binaryReader.ReadBoolean();

            if (!nullwatcher)
            {
                WatchedEvent.WatchedEventType        type  = (WatchedEvent.WatchedEventType) this.binaryReader.ReadInt32();
                WatchedEvent.WatchedEventKeeperState state = (WatchedEvent.WatchedEventKeeperState) this.binaryReader.ReadInt32();
                string path = this.binaryReader.ReadString();

                byte[] data = null;
                IStat  stat = null;
                if (this.serializationVersionUsed >= SerializationFormatVersions.Version23)
                {
                    data = this.DeserializeByteArray();
                    stat = this.DeserializeStat();
                }

                watcherCall.WatcherEvt = new WatchedEvent(type, state, path, data, stat);
            }
            else
            {
                watcherCall.WatcherEvt = null;
            }

            return(watcherCall);
        }
コード例 #6
0
        /// <summary>
        /// Serialize <see cref="WatcherCall"/>.
        /// </summary>
        /// <param name="watcherCall"><see cref="WatcherCall"/> to serialize</param>
        private void SerializeWatcherCall(WatcherCall watcherCall)
        {
            Debug.Assert(watcherCall != null, "watcherCall parameter is null");

            // ReSharper disable once PossibleNullReferenceException
            this.binaryWriter.Write(watcherCall.WatcherId);
            this.binaryWriter.Write((byte)watcherCall.Kind);

            var evt = watcherCall.WatcherEvt;

            this.binaryWriter.Write(evt == null);
            if (evt != null)
            {
                this.binaryWriter.Write((int)evt.EventType);
                this.binaryWriter.Write((int)evt.KeeperState);
                this.binaryWriter.Write(evt.Path);

                if (this.versionToUse >= SerializationFormatVersions.Version23)
                {
                    this.SerializeData(evt.Data);
                    this.SerializeStat(evt.Stat);
                }
            }
        }