Esempio n. 1
0
        /// <summary>
        /// Add a watcher to the path.
        /// </summary>
        /// <param name="sessionId">Id of the session that is installing the watcher</param>
        /// <param name="path">Path to watch</param>
        /// <param name="watcher">Watcher to added</param>
        /// <returns>The number of watchers in the collection after the given watcher was added</returns>
        public int AddWatcher(ulong sessionId, string path, MarshallerChannel.ProxyWatcher watcher)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            WatcherRecord replacedWatcher = null;
            var           timer           = Stopwatch.StartNew();

            this.watchersLock.EnterWriteLock();
            try
            {
                Dictionary <ulong, WatcherRecord> existingWatchers;
                if (!this.watchers.TryGetValue(path, out existingWatchers))
                {
                    existingWatchers = new Dictionary <ulong, WatcherRecord>();
                    this.watchers.Add(path, existingWatchers);
                }

                if (existingWatchers.TryGetValue(sessionId, out replacedWatcher))
                {
                    RingMasterEventSource.Log.WatcherCollection_RemoveExistingWatcher(sessionId, path);
                    existingWatchers.Remove(sessionId);
                    this.watcherCount--;
                }

                if (watcher != null)
                {
                    WatcherRecord newWatcher = new WatcherRecord(watcher);
                    existingWatchers.Add(sessionId, newWatcher);
                    this.watcherCount++;

                    RingMasterEventSource.Log.WatcherCollection_AddWatcher(sessionId, path, this.watcherCount, timer.ElapsedMilliseconds);
                }

                return(this.watcherCount);
            }
            finally
            {
                this.watchersLock.ExitWriteLock();

                if (replacedWatcher != null)
                {
                    replacedWatcher.NotifyWatcherRemoved(isSessionTerminating: false);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the watcher.
        /// </summary>
        /// <param name="watcher">The watcher.</param>
        /// <param name="context">context string?</param>
        public override void AddWatcher(IWatcher watcher, string context = null)
        {
            lock (this.Persisted)
            {
                if (this.Persisted.Node != this)
                {
                    this.Persisted.Node.AddWatcher(watcher, context);
                    return;
                }

                MarshallerChannel.ProxyWatcher pxy = watcher as MarshallerChannel.ProxyWatcher;
                if (pxy != null && context != null)
                {
                    pxy.SetToString(context);
                }

                if (this.Watchers == null)
                {
                    this.Watchers = new LinkedList <IWatcher>();
                }

                this.Watchers.Add(watcher);
            }
        }
Esempio n. 3
0
 public WatcherRecord(MarshallerChannel.ProxyWatcher watcher)
 {
     this.watcher = watcher;
 }
Esempio n. 4
0
        /// <summary>
        /// Adds the bulk watcher.
        /// </summary>
        /// <param name="sessionId">Id of the session that is adding the watcher</param>
        /// <param name="path">Path to watch</param>
        /// <param name="watcher">Watcher to add</param>
        internal static void AddBulkWatcher(ulong sessionId, string path, MarshallerChannel.ProxyWatcher watcher)
        {
            int count = SbulkWatchers.AddWatcher(sessionId, path, watcher);

            RingMasterServerInstrumentation.Instance.UpdateBulkWatcherCount(count);
        }