예제 #1
0
        /// <summary>
        /// Notifies the cache about a watcher event.
        /// </summary>
        /// <param name="rc">The result code.</param>
        /// <param name="onChange">The watcher event.</param>
        /// <param name="cachePrefix">The cache prefix to use.</param>
        /// <returns><c>true</c> if the caller needs to restart the watcher, <c>false</c> otherwise.</returns>
        public bool NotifyWatcherEvent(RingMasterException.Code rc, WatchedEvent onChange, string cachePrefix)
        {
            if (onChange == null)
            {
                return(false);
            }

            if (onChange.EventType == WatchedEvent.WatchedEventType.WatcherRemoved)
            {
                this.Wipe(cachePrefix);
                return(true);
            }

            if (onChange.KeeperState == WatchedEvent.WatchedEventKeeperState.SyncConnected)
            {
                if (onChange.EventType == WatchedEvent.WatchedEventType.NodeCreated ||
                    onChange.EventType == WatchedEvent.WatchedEventType.NodeDeleted)
                {
                    this.Invalidate(cachePrefix, PrefixedClientCache.GetParent(onChange.Path));
                }

                this.Invalidate(cachePrefix, onChange.Path);
            }

            return(false);
        }
        private void CacheInvalidate(IRingMasterClientCache cache, IRingMasterRequest req)
        {
            if (cache == null || req == null)
            {
                return;
            }

            switch (req.RequestType)
            {
            case RingMasterRequestType.GetData:
            case RingMasterRequestType.GetChildren:
            case RingMasterRequestType.GetAcl:
            case RingMasterRequestType.Exists:
                return;

            case RingMasterRequestType.Create:
            {
                cache.Invalidate(this.cachePrefix, req.Path);
                cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(req.Path));
                break;
            }

            case RingMasterRequestType.Delete:
            {
                RequestDelete delete = req as RequestDelete;

                if (delete.IsCascade)
                {
                    cache.Wipe(this.cachePrefix);
                }
                else
                {
                    cache.Invalidate(this.cachePrefix, req.Path);
                    cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(req.Path));
                }

                break;
            }

            case RingMasterRequestType.Move:
            {
                RequestMove move = req as RequestMove;

                cache.Invalidate(this.cachePrefix, move.Path);
                cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(move.Path));
                cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(move.PathDst));
                break;
            }

            default:
            {
                cache.Invalidate(this.cachePrefix, req.Path);

                AbstractRingMasterCompoundRequest list = req as AbstractRingMasterCompoundRequest;

                if (list != null && list.Requests != null)
                {
                    foreach (IRingMasterRequest child in list.Requests)
                    {
                        this.CacheInvalidate(cache, child);
                    }
                }

                break;
            }
            }
        }