示例#1
0
        /// <summary>
        /// Sets the information.
        /// </summary>
        /// <param name="prefix">The prefix.</param>
        /// <param name="path">The path.</param>
        /// <param name="kind">The kind of info to set.</param>
        /// <param name="info">The information to set.</param>
        public void SetInfo(string prefix, string path, CachedKind kind, IRingMasterClientCacheDataEntry info)
        {
            if (info == null)
            {
                this.Invalidate(prefix, path);
                return;
            }

            LruCache <string, DataEntry> cache = this.GetCacheForPrefix(prefix, true);
            DataEntry entry;

            if (!cache.TryGetValue(path, out entry))
            {
                lock (cache)
                {
                    if (!cache.TryGetValue(path, out entry))
                    {
                        entry = new DataEntry();
                        cache.Add(path, entry);
                    }
                }
            }

            lock (entry)
            {
                if ((kind & CachedKind.NodeAcls) != CachedKind.None)
                {
                    entry.Acls = info.Acls;
                }

                if ((kind & CachedKind.NodeData) != CachedKind.None)
                {
                    entry.Data = info.Data;
                }

                if ((kind & CachedKind.NodeChildren) != CachedKind.None)
                {
                    entry.Children = info.Children;
                }

                if ((kind & CachedKind.NodeStats) != CachedKind.None)
                {
                    entry.Stat = info.Stat;
                }

                if (entry.Stat == null && entry.Children == null && entry.Data == null && entry.Acls == null)
                {
                    cache.Remove(path);
                }
            }

            if (this.debugCache)
            {
                System.Console.Write(string.Format("*** SETINFO {0}/{1}/{2} at {3}", prefix, path, kind, this.GetStack()));
            }
        }
示例#2
0
        /// <summary>
        /// Tries to get information.
        /// </summary>
        /// <param name="prefix">The prefix.</param>
        /// <param name="path">The path.</param>
        /// <param name="kind">The kind of data to retrieve.</param>
        /// <param name="info">The information retrieved.</param>
        /// <returns><c>true</c> if data has been retrieved, <c>false</c> otherwise.</returns>
        public bool TryGetInfo(string prefix, string path, CachedKind kind, out IRingMasterClientCacheDataEntry info)
        {
            info = null;
            bool result = true;

            try
            {
                LruCache <string, DataEntry> cache = this.GetCacheForPrefix(prefix, false);
                if (cache == null)
                {
                    result = false;
                    return(result);
                }

                DataEntry entry;
                if (!cache.TryGetValue(path, out entry))
                {
                    result = false;
                    return(result);
                }

                DataEntry copy = new DataEntry();
                info = copy;

                if ((kind & CachedKind.NodeAcls) != CachedKind.None)
                {
                    copy.Acls = entry.Acls;
                }

                if ((kind & CachedKind.NodeData) != CachedKind.None)
                {
                    copy.Data = entry.Data;
                }

                if ((kind & CachedKind.NodeChildren) != CachedKind.None)
                {
                    copy.Children = entry.Children;
                }

                if ((kind & CachedKind.NodeStats) != CachedKind.None)
                {
                    copy.Stat = entry.Stat;
                }

                return(result);
            }
            finally
            {
                if (this.debugCache)
                {
                    System.Console.Write(string.Format("*** GETINFO {0}/{1}/{2} --> {3} at {4}", prefix, path, kind, result, this.GetStack()));
                }
            }
        }