Example #1
0
        protected void AddLiveFirstLevelCaches(IList <IWritableCache> liveChildCaches, bool isTransactionActive)
        {
            if (allFLCs.Count == 0)
            {
                return;
            }
            Thread currentThread = Thread.CurrentThread;

            DictionaryExtension.Loop(allFLCs, delegate(int cacheId, FlcEntry flcEntry)
            {
                CacheFactoryDirective cacheFactoryDirective = flcEntry.GetCacheFactoryDirective();
                if (CacheFactoryDirective.NoDCE.Equals(cacheFactoryDirective))
                {
                    // This cache is not interested in DCEs at all
                    return;
                }
                if (isTransactionActive && CacheFactoryDirective.SubscribeGlobalDCE.Equals(cacheFactoryDirective))
                {
                    // This cache is not interested in transactional DCEs
                    return;
                }
                IWritableCache childCache = flcEntry.GetFirstLevelCache();
                if (childCache == null)
                {
                    // This cache is not valid any more
                    return;
                }
                if (!flcEntry.IsInterestedInThread(currentThread))
                {
                    // This cache is bound to a different thread than the current one
                    return;
                }
                liveChildCaches.Add(childCache);
            });
        }
Example #2
0
        public void UnregisterFirstLevelCache(IWritableCache firstLevelCache, CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, String name)
        {
            // cacheFactoryDirective and foreignThreadAware will be intentionally ignored at unregister

            unboundWriteLock.Lock();
            try
            {
                CheckCachesForCleanup();
                int      cacheId  = firstLevelCache.CacheId;
                FlcEntry flcEntry = DictionaryExtension.ValueOrDefault(allFLCs, cacheId);
                if (flcEntry == null)
                {
                    throw new Exception("CacheId is not mapped to a valid cache instance");
                }
                IWritableCache existingChildCache = flcEntry.GetFirstLevelCache();
                if (existingChildCache == null)
                {
                    throw new Exception("Fatal error occured. Reference lost to cache");
                }
                if (existingChildCache != firstLevelCache)
                {
                    throw new Exception("Fatal error occured. CacheId invalid - it is not mapped to the specified cache instance");
                }
                allFLCs.Remove(cacheId);
                foreignThreadAware    = flcEntry.IsForeignThreadAware();
                cacheFactoryDirective = flcEntry.GetCacheFactoryDirective();

                LogFLC(firstLevelCache, cacheFactoryDirective, foreignThreadAware, name, flcEntry, false);
                firstLevelCache.CacheId = 0;
            }
            finally
            {
                unboundWriteLock.Unlock();
            }
        }
Example #3
0
 public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, bool?useWeakEntries, String name)
 {
     if (!SecurityActive)
     {
         return(CreatePrivileged(cacheFactoryDirective, foreignThreadAware, useWeakEntries, name));
     }
     return(CreateIntern(cacheFactoryDirective, false, foreignThreadAware, useWeakEntries, name));
 }
Example #4
0
 public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, String name)
 {
     if (!SecurityActive)
     {
         return(CreatePrivileged(cacheFactoryDirective, name));
     }
     return(CreateIntern(cacheFactoryDirective, false, false, null, name));
 }
Example #5
0
        protected IDisposableCache CreateIntern(CacheFactoryDirective cacheFactoryDirective, bool privileged, bool foreignThreadAware, bool?useWeakEntries, String name)
        {
            IBeanRuntime <ChildCache> firstLevelCacheBC = BeanContext.RegisterBean <ChildCache>();

            if (!foreignThreadAware)
            {
                // Do not inject EventQueue because caches without foreign interest will never receive async DCEs
                firstLevelCacheBC.IgnoreProperties("EventQueue");
            }
            if (useWeakEntries.HasValue)
            {
                firstLevelCacheBC.PropertyValue("WeakEntries", useWeakEntries.Value);
            }
            if (name != null)
            {
                firstLevelCacheBC.PropertyValue("Name", name);
            }
            firstLevelCacheBC.PropertyValue("Privileged", privileged);
            ChildCache firstLevelCache = firstLevelCacheBC.Finish();

            FirstLevelCacheExtendable.RegisterFirstLevelCache(firstLevelCache, cacheFactoryDirective, foreignThreadAware, name);
            return(firstLevelCache);
        }
Example #6
0
        public void RegisterFirstLevelCache(IWritableCache firstLevelCache, CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, String name)
        {
            WeakReference firstLevelCacheR = CreateReferenceEntry(firstLevelCache);
            Thread        thread           = Thread.CurrentThread;
            WeakReference owningThreadR    = !foreignThreadAware?CreateReferenceEntry(thread) : null;

            FlcEntry flcEntry = new FlcEntry(cacheFactoryDirective, firstLevelCacheR, owningThreadR);

            unboundWriteLock.Lock();
            try
            {
                int cacheId;
                int nextCacheId = lastCacheId;
                while (true)
                {
                    if (nextCacheId == Int32.MaxValue)
                    {
                        nextCacheId = 0;
                    }
                    cacheId = ++nextCacheId;

                    if (!allFLCs.ContainsKey(cacheId))
                    {
                        allFLCs.Add(cacheId, flcEntry);
                        lastCacheId = cacheId;
                        break;
                    }
                }
                firstLevelCache.CacheId = cacheId;

                LogFLC(firstLevelCache, cacheFactoryDirective, foreignThreadAware, name, flcEntry, true);
            }
            finally
            {
                unboundWriteLock.Unlock();
            }
        }
Example #7
0
 public IDisposableCache CreatePrivileged(CacheFactoryDirective cacheFactoryDirective, String name)
 {
     return(CreateIntern(cacheFactoryDirective, true, false, null, name));
 }
Example #8
0
 public IDisposableCache CreatePrivileged(CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, bool?useWeakEntries, String name)
 {
     return(new CacheMock());
 }
Example #9
0
 public IDisposableCache CreatePrivileged(CacheFactoryDirective cacheFactoryDirective, String name)
 {
     return(new CacheMock());
 }
Example #10
0
 public FlcEntry(CacheFactoryDirective cacheFactoryDirective, WeakReference firstLevelCacheR, WeakReference owningThreadR)
 {
     this.cacheFactoryDirective = cacheFactoryDirective;
     this.firstLevelCacheR      = firstLevelCacheR;
     this.owningThreadR         = owningThreadR;
 }
Example #11
0
 public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, bool?useWeakEntries, String name)
 {
     return(null);
 }
Example #12
0
 public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, String name)
 {
     return(null);
 }
Example #13
0
 public void RegisterFirstLevelCache(IWritableCache firstLevelCache, CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware)
 {
     RegisterFirstLevelCache(firstLevelCache, cacheFactoryDirective, foreignThreadAware, null);
 }
Example #14
0
        protected void LogFLC(IWritableCache firstLevelCache, CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, String name,
                              FlcEntry flcEntry, bool isRegister)
        {
            if (!Log.DebugEnabled)
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            if (isRegister)
            {
                sb.Append("Registered");
            }
            else
            {
                sb.Append("Unregistered");
            }
            sb.Append(" FLC");
            if (name != null)
            {
                sb.Append(" '").Append(name).Append("'");
            }
            sb.Append(" with id: ").Append(firstLevelCache.CacheId);
            if (firstLevelCache.Privileged)
            {
                sb.Append(", privileged");
            }
            else
            {
                sb.Append(", non-privileged");
            }
            if (CacheFactoryDirective.SubscribeTransactionalDCE.Equals(flcEntry.GetCacheFactoryDirective()))
            {
                sb.Append(", transactional");
                if (foreignThreadAware)
                {
                    sb.Append(", multithreaded");
                }
                else
                {
                    Thread thread = flcEntry.GetOwningThread();
                    sb.Append(", to thread ").Append(thread.ManagedThreadId).Append(':').Append(thread.Name);
                }
            }
            else if (CacheFactoryDirective.SubscribeGlobalDCE.Equals(flcEntry.GetCacheFactoryDirective()))
            {
                sb.Append(", non-transactional");
                if (foreignThreadAware)
                {
                    sb.Append(", multithreaded");
                }
                else
                {
                    Thread thread = flcEntry.GetOwningThread();
                    sb.Append(", to thread ").Append(thread.ManagedThreadId).Append(':').Append(thread.Name);
                }
            }
            else
            {
                sb.Append(", traced");
            }
            Log.Debug(sb.ToString());
        }