コード例 #1
0
        public long AddObject(object obj, long parentHandle)
        {
            MrsTracer.ProxyService.Function("HandleCache.AddObject({0})", new object[]
            {
                obj.GetType().Name
            });
            long handle;

            lock (this.locker)
            {
                HandleCache.HandleRec handleRec = new HandleCache.HandleRec();
                handleRec.Obj          = obj;
                handleRec.ParentHandle = parentHandle;
                handleRec.Handle       = this.nextHandleValue;
                this.nextHandleValue  += 1L;
                this.cache.Add(handleRec.Handle, handleRec);
                MrsTracer.ProxyService.Debug("HandleCache.AddObject({0}) returns {1}", new object[]
                {
                    obj.GetType().Name,
                    handleRec.Handle
                });
                handle = handleRec.Handle;
            }
            return(handle);
        }
コード例 #2
0
        public T GetObject <T>(long handle) where T : class
        {
            MrsTracer.ProxyService.Function("HandleCache.GetObject<{1}>({0})", new object[]
            {
                handle,
                typeof(T).Name
            });
            T result;

            lock (this.locker)
            {
                HandleCache.HandleRec handleRec = this.FindObject(handle, HandleCache.FindObjectOptions.MustExist);
                T t = handleRec.Obj as T;
                if (t == null)
                {
                    MrsTracer.ProxyService.Error("Handle {0} has wrong type: {1}, expected {2}.", new object[]
                    {
                        handle,
                        handleRec.Obj.GetType().Name,
                        typeof(T).Name
                    });
                    throw new InvalidHandleTypePermanentException(handle, handleRec.Obj.GetType().Name, typeof(T).Name);
                }
                result = t;
            }
            return(result);
        }
コード例 #3
0
        private void RemoveFromCache(HandleCache.HandleRec rec)
        {
            Lazy <List <HandleCache.HandleRec> > lazy = new Lazy <List <HandleCache.HandleRec> >(() => new List <HandleCache.HandleRec>());

            foreach (HandleCache.HandleRec handleRec in this.cache.Values)
            {
                if (handleRec.ParentHandle == rec.Handle)
                {
                    lazy.Value.Add(handleRec);
                }
            }
            if (lazy.IsValueCreated)
            {
                foreach (HandleCache.HandleRec rec2 in lazy.Value)
                {
                    this.RemoveFromCache(rec2);
                }
            }
            IDisposable disposable = rec.Obj as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            this.cache.Remove(rec.Handle);
        }
コード例 #4
0
 public void ReleaseObject(long handle)
 {
     MrsTracer.ProxyService.Function("HandleCache.ReleaseObject({0})", new object[]
     {
         handle
     });
     lock (this.locker)
     {
         HandleCache.HandleRec handleRec = this.FindObject(handle, HandleCache.FindObjectOptions.MayBeAbsent);
         if (handleRec != null)
         {
             this.RemoveFromCache(handleRec);
         }
     }
 }
コード例 #5
0
        public long GetParentHandle(long handle)
        {
            MrsTracer.ProxyService.Function("HandleCache.GetParentHandle({0})", new object[]
            {
                handle
            });
            long parentHandle;

            lock (this.locker)
            {
                HandleCache.HandleRec handleRec = this.FindObject(handle, HandleCache.FindObjectOptions.MustExist);
                parentHandle = handleRec.ParentHandle;
            }
            return(parentHandle);
        }
コード例 #6
0
 protected override void InternalDispose(bool calledFromDispose)
 {
     if (calledFromDispose)
     {
         lock (this.locker)
         {
             if (this.cache.Count > 0)
             {
                 MrsTracer.ProxyService.Error("HandleCache being disposed with {0} open handles", new object[]
                 {
                     this.cache.Count
                 });
                 while (this.cache.Count > 0)
                 {
                     HandleCache.HandleRec rec = this.cache.Values.First <HandleCache.HandleRec>();
                     this.RemoveFromCache(rec);
                 }
             }
         }
     }
 }