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); }); }
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(); } }
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)); }
public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, String name) { if (!SecurityActive) { return(CreatePrivileged(cacheFactoryDirective, name)); } return(CreateIntern(cacheFactoryDirective, false, false, null, name)); }
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); }
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(); } }
public IDisposableCache CreatePrivileged(CacheFactoryDirective cacheFactoryDirective, String name) { return(CreateIntern(cacheFactoryDirective, true, false, null, name)); }
public IDisposableCache CreatePrivileged(CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, bool?useWeakEntries, String name) { return(new CacheMock()); }
public IDisposableCache CreatePrivileged(CacheFactoryDirective cacheFactoryDirective, String name) { return(new CacheMock()); }
public FlcEntry(CacheFactoryDirective cacheFactoryDirective, WeakReference firstLevelCacheR, WeakReference owningThreadR) { this.cacheFactoryDirective = cacheFactoryDirective; this.firstLevelCacheR = firstLevelCacheR; this.owningThreadR = owningThreadR; }
public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware, bool?useWeakEntries, String name) { return(null); }
public IDisposableCache Create(CacheFactoryDirective cacheFactoryDirective, String name) { return(null); }
public void RegisterFirstLevelCache(IWritableCache firstLevelCache, CacheFactoryDirective cacheFactoryDirective, bool foreignThreadAware) { RegisterFirstLevelCache(firstLevelCache, cacheFactoryDirective, foreignThreadAware, null); }
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()); }