コード例 #1
0
        public void HandleEvent(Object eventObject, DateTime dispatchTime, long sequenceId)
        {
            if (!(eventObject is ClearAllCachesEvent))
            {
                return;
            }
            CommittedRootCache.Clear();
            IRootCache privilegedSecondLevelCache = SecondLevelCacheManager.SelectPrivilegedSecondLevelCache(false);

            if (privilegedSecondLevelCache != null && !Object.ReferenceEquals(privilegedSecondLevelCache, CommittedRootCache))
            {
                privilegedSecondLevelCache.Clear();
            }
            IRootCache nonPrivilegedSecondLevelCache = SecondLevelCacheManager.SelectNonPrivilegedSecondLevelCache(false);

            if (nonPrivilegedSecondLevelCache != null && !Object.ReferenceEquals(nonPrivilegedSecondLevelCache, CommittedRootCache) &&
                !Object.ReferenceEquals(nonPrivilegedSecondLevelCache, privilegedSecondLevelCache))
            {
                nonPrivilegedSecondLevelCache.Clear();
            }
            IList <IWritableCache> firstLevelCaches = FirstLevelCacheManager.SelectFirstLevelCaches();

            for (int a = firstLevelCaches.Count; a-- > 0;)
            {
                IWritableCache firstLevelCache = firstLevelCaches[a];
                firstLevelCache.Clear();
            }
        }
コード例 #2
0
        public static CacheDependencyNode AddRootCache(IRootCache rootCache, IdentityHashMap <IRootCache, CacheDependencyNode> rootCacheToNodeMap)
        {
            rootCache = rootCache.CurrentRootCache;
            CacheDependencyNode node = rootCacheToNodeMap.Get(rootCache);

            if (node != null)
            {
                return(node);
            }
            CacheDependencyNode parentNode = null;
            IRootCache          parent     = ((RootCache)rootCache).Parent;

            if (parent != null)
            {
                parentNode = AddRootCache(parent, rootCacheToNodeMap);
            }
            node            = new CacheDependencyNode(rootCache);
            node.parentNode = parentNode;
            if (parentNode != null)
            {
                parentNode.childNodes.Add(node);
            }
            rootCacheToNodeMap.Put(rootCache, node);
            return(node);
        }
コード例 #3
0
        protected CacheDependencyNode BuildCacheDependency()
        {
            IRootCache             privilegedSecondLevelCache    = SecondLevelCacheManager.SelectPrivilegedSecondLevelCache(true);
            IRootCache             nonPrivilegedSecondLevelCache = SecondLevelCacheManager.SelectNonPrivilegedSecondLevelCache(false);
            IList <IWritableCache> selectedFirstLevelCaches      = FirstLevelCacheManager.SelectFirstLevelCaches();

            IdentityHashMap <IRootCache, CacheDependencyNode> secondLevelCacheToNodeMap = new IdentityHashMap <IRootCache, CacheDependencyNode>();

            if (privilegedSecondLevelCache != null)
            {
                CacheDependencyNodeFactory.AddRootCache(privilegedSecondLevelCache.CurrentRootCache, secondLevelCacheToNodeMap);
            }
            if (nonPrivilegedSecondLevelCache != null)
            {
                CacheDependencyNodeFactory.AddRootCache(nonPrivilegedSecondLevelCache.CurrentRootCache, secondLevelCacheToNodeMap);
            }
            for (int a = selectedFirstLevelCaches.Count; a-- > 0;)
            {
                ChildCache childCache = (ChildCache)selectedFirstLevelCaches[a];

                IRootCache parent = ((IRootCache)childCache.Parent).CurrentRootCache;

                CacheDependencyNode node = CacheDependencyNodeFactory.AddRootCache(parent, secondLevelCacheToNodeMap);
                node.directChildCaches.Add(childCache);
            }
            return(CacheDependencyNodeFactory.BuildRootNode(secondLevelCacheToNodeMap));
        }
コード例 #4
0
        protected IRootCache GetCurrentRootCache()
        {
            IRootCache rootCache = GetCurrentRootCacheIfValid();

            if (rootCache == null)
            {
                rootCache = AcquireRootCache(privileged, rootCacheTL);
            }
            return(rootCache);
        }
コード例 #5
0
        protected override void InterceptIntern(IInvocation invocation)
        {
            if (clearMethod.Equals(invocation.Method))
            {
                IRootCache rootCache = GetCurrentRootCacheIfValid();
                if (rootCache == null)
                {
                    // Nothing to do
                    return;
                }
            }
            IRootCache rootCache2 = GetCurrentRootCache();

            invocation.ReturnValue = invocation.Method.Invoke(rootCache2, invocation.Arguments);
        }
コード例 #6
0
ファイル: RevertChangesHelper.cs プロジェクト: vogelb/ambeth
        protected void WaitEventToResume(IBackgroundWorkerParamDelegate <IProcessResumeItem> resumeDelegate, IBackgroundWorkerParamDelegate <Exception> errorDelegate)
        {
            IRootCache             rootCache = RootCache;
            IList <IWritableCache> selectedFirstLevelCaches = FirstLevelCacheManager.SelectFirstLevelCaches();

            ISet <Object> collisionSet = new IdentityHashSet <Object>();

            collisionSet.Add(rootCache);
            for (int a = selectedFirstLevelCaches.Count; a-- > 0;)
            {
                collisionSet.Add(selectedFirstLevelCaches[a]);
            }
            // Without the current rootcache we can not handle the event now. We have to block till the rootCache and all childCaches get valid
            EventDispatcher.WaitEventToResume(collisionSet, -1, resumeDelegate, errorDelegate);
        }
コード例 #7
0
        protected IRootCache GetCurrentRootCache(bool privileged, bool forceInstantiation)
        {
            IRootCache rootCache = privileged ? privilegedRootCacheTL.Value : rootCacheTL.Value;

            if (rootCache != null)
            {
                return(rootCache);
            }
            if (!transactionalRootCacheActiveTL.Value)
            {
                // If no thread-bound root cache is active (which implies that no transaction is currently active
                // return the unbound root cache (which reads committed data)
                return(CommittedRootCache);
            }
            // if we need a cache and security is active the privileged cache is a prerequisite in both cases
            IRootCache privilegedRootCache = privilegedRootCacheTL.Value;

            if (privilegedRootCache == null)
            {
                if (!forceInstantiation)
                {
                    // do not create an instance of anything in this case
                    return(null);
                }
                // here we know that the non-privileged one could not have existed before, so we simply create the privileged one
                privilegedRootCache = AcquireRootCache(true, privilegedRootCacheTL);
            }
            if (privileged)
            {
                // we need only the privilegedRootCache so we are finished
                return(privilegedRootCache);
            }
            IRootCache nonPrivilegedRootCache = rootCacheTL.Value;

            if (nonPrivilegedRootCache == null)
            {
                if (!forceInstantiation)
                {
                    // do not create an instance of anything in this case
                    return(null);
                }
                // share the locks from the privileged rootCache
                nonPrivilegedRootCache = AcquireRootCache(privileged, rootCacheTL, (ICacheRetriever)privilegedRootCache, privilegedRootCache.ReadLock,
                                                          privilegedRootCache.WriteLock);
            }
            return(nonPrivilegedRootCache);
        }
コード例 #8
0
        protected override void InterceptIntern(IInvocation invocation)
        {
            if (clearMethod.Equals(invocation.Method))
            {
                IRootCache rootCache = privilegedRootCacheTL.Value;
                if (rootCache != null)
                {
                    rootCache.Clear();
                }
                rootCache = rootCacheTL.Value;
                if (rootCache != null)
                {
                    rootCache.Clear();
                }
                return;
            }
            ICacheIntern requestingCache = null;

            foreach (Object arg in invocation.Arguments)
            {
                if (arg is ICacheIntern)
                {
                    requestingCache = (ICacheIntern)arg;
                    break;
                }
            }
            bool privileged;

            if (requestingCache != null)
            {
                privileged = requestingCache.Privileged;
            }
            else
            {
                privileged = IsCurrentPrivileged();
            }
            IRootCache rootCache2 = GetCurrentRootCache(privileged);

            invocation.ReturnValue = invocation.Method.Invoke(rootCache2, invocation.Arguments);
        }
コード例 #9
0
        protected void CleanupSecondLevelCachesIntern(CacheDependencyNode node, IList <IObjRef> deletesList, IList <IObjRef> objRefsRemovePriorVersions)
        {
            IRootCache rootCache = node.rootCache;
            Lock       writeLock = rootCache.WriteLock;

            writeLock.Lock();
            try
            {
                rootCache.Remove(deletesList);
                rootCache.RemovePriorVersions(objRefsRemovePriorVersions);
            }
            finally
            {
                writeLock.Unlock();
            }
            List <CacheDependencyNode> childNodes = node.childNodes;

            for (int a = childNodes.Count; a-- > 0;)
            {
                CleanupSecondLevelCachesIntern(childNodes[a], deletesList, objRefsRemovePriorVersions);
            }
        }
コード例 #10
0
        public void DisposeTransactionalRootCache(bool success)
        {
            transactionalRootCacheActiveTL.Value = false;

            DisposeCurrentRootCache(rootCacheTL);

            IRootCache rootCache = privilegedRootCacheTL.Value;

            if (rootCache == null)
            {
                DisposeCurrentRootCache(privilegedRootCacheTL);
                // This may happen if an exception occurs while committing and therefore calling a rollback
                return;
            }
            try
            {
                if (success)
                {
                    List <RootCacheValue> content = new List <RootCacheValue>();

                    // Save information into second level cache for committed data
                    rootCache.GetContent(delegate(Type entityType, sbyte idIndex, Object id, Object value)
                    {
                        content.Add((RootCacheValue)value);
                    }
                                         );
                    if (content.Count > 0)
                    {
                        rootCache.Clear();
                        CommittedRootCache.Put(content);
                    }
                }
            }
            finally
            {
                DisposeCurrentRootCache(privilegedRootCacheTL);
            }
        }
コード例 #11
0
        protected void ChangeFirstLevelCachesIntern(CacheDependencyNode node, ISet <IObjRef> intermediateDeletes)
        {
            List <CacheDependencyNode> childNodes = node.childNodes;

            for (int a = childNodes.Count; a-- > 0;)
            {
                ChangeFirstLevelCachesIntern(childNodes[a], intermediateDeletes);
            }
            CacheChangeItem[] cacheChangeItems = node.cacheChangeItems;
            if (cacheChangeItems == null)
            {
                return;
            }
            IRootCache parentCache = node.rootCache;
            // RootCache readlock must be acquired before individual writelock to the child caches due to deadlock reasons
            Lock parentCacheReadLock = parentCache.ReadLock;

            parentCacheReadLock.Lock();
            try
            {
                HashMap <IObjRef, CacheValueAndPrivilege> objRefToCacheValueMap = node.objRefToCacheValueMap;

                for (int a = cacheChangeItems.Length; a-- > 0;)
                {
                    CacheChangeItem cci = cacheChangeItems[a];
                    if (cci == null)
                    {
                        continue;
                    }
                    ChildCache childCache = node.directChildCaches[a];

                    IList <IObjRef> deletedObjRefs  = cci.DeletedObjRefs;
                    IList <Object>  objectsToUpdate = cci.UpdatedObjects;
                    IList <IObjRef> objRefsToUpdate = cci.UpdatedObjRefs;

                    IRootCache parent = ((IRootCache)childCache.Parent).CurrentRootCache;

                    Lock writeLock = childCache.WriteLock;
                    writeLock.Lock();
                    try
                    {
                        if (deletedObjRefs != null && deletedObjRefs.Count > 0)
                        {
                            childCache.Remove(deletedObjRefs);
                        }
                        foreach (IObjRef intermediateDeleteObjRef in intermediateDeletes)
                        {
                            childCache.Remove(intermediateDeleteObjRef);
                        }
                        if (objectsToUpdate != null && objectsToUpdate.Count > 0)
                        {
                            List <IObjRef> objRefsToForget = null;
                            for (int b = objectsToUpdate.Count; b-- > 0;)
                            {
                                Object  objectInCache = objectsToUpdate[b];
                                IObjRef objRefInCache = objRefsToUpdate[b];
                                // Check if the objects still have their id. They may have lost them concurrently because this
                                // method here may be called from another thread (e.g. UI thread)
                                IEntityMetaData metaData = ((IEntityMetaDataHolder)objectInCache).Get__EntityMetaData();
                                Object          id       = metaData.IdMember.GetValue(objectInCache, false);
                                if (id == null)
                                {
                                    continue;
                                }
                                CacheValueAndPrivilege cacheValueP = objRefToCacheValueMap.Get(objRefInCache);
                                if (cacheValueP == null)
                                {
                                    if (objRefsToForget == null)
                                    {
                                        objRefsToForget = new List <IObjRef>();
                                    }
                                    objRefsToForget.Add(objRefInCache);

                                    foreach (PrimitiveMember member in metaData.PrimitiveMembers)
                                    {
                                        member.SetValue(objectInCache, null);
                                    }
                                    RelationMember[] relationMembers = metaData.RelationMembers;
                                    for (int relationIndex = relationMembers.Length; relationIndex-- > 0;)
                                    {
                                        ((IValueHolderContainer)objectInCache).Set__Uninitialized(relationIndex, null);
                                    }
                                    continue;
                                }
                                if (!parentCache.ApplyValues(objectInCache, childCache, cacheValueP.privilege))
                                {
                                    if (Log.WarnEnabled)
                                    {
                                        Log.Warn("No entry for object '" + objectInCache + "' found in second level cache");
                                    }
                                }
                            }
                            if (objRefsToForget != null)
                            {
                                childCache.Remove(objRefsToForget);
                            }
                        }
                    }
                    finally
                    {
                        writeLock.Unlock();
                    }
                }
            }
            finally
            {
                parentCacheReadLock.Unlock();
            }
        }
コード例 #12
0
        protected void ChangeSecondLevelCacheIntern(CacheDependencyNode node, CacheDirective cacheDirective)
        {
            IRootCache rootCache = node.rootCache;
            HashMap <IObjRef, CacheValueAndPrivilege> objRefToLoadContainerDict = node.objRefToCacheValueMap;
            CHashSet <IObjRef> objRefsToLoad = new CHashSet <IObjRef>(node.objRefsToLoad);

            if (node.cacheChangeItems != null)
            {
                foreach (CacheChangeItem cci in node.cacheChangeItems)
                {
                    if (cci == null)
                    {
                        continue;
                    }
                    objRefsToLoad.AddAll(cci.UpdatedObjRefs);
                }
            }
            IList <IObjRef> objRefs       = objRefsToLoad.ToList();
            IList <Object>  refreshResult = rootCache.GetObjects(objRefs, cacheDirective);

            IPrivilege[] privileges = null;
            if (SecurityActivation != null && PrivilegeProvider != null && SecurityActivation.FilterActivated)
            {
                privileges = PrivilegeProvider.GetPrivilegesByObjRef(objRefs).GetPrivileges();
            }
            for (int a = refreshResult.Count; a-- > 0;)
            {
                RootCacheValue cacheValue = (RootCacheValue)refreshResult[a];
                if (cacheValue == null)
                {
                    continue;
                }
                objRefToLoadContainerDict.Put(objRefs[a], new CacheValueAndPrivilege(cacheValue, privileges != null ? privileges[a] : null));
            }
            CheckCascadeRefreshNeeded(node);

            CHashSet <IObjRef>      cascadeRefreshObjRefsSet      = node.cascadeRefreshObjRefsSet;
            CHashSet <IObjRelation> cascadeRefreshObjRelationsSet = node.cascadeRefreshObjRelationsSet;

            if (cascadeRefreshObjRelationsSet.Count > 0)
            {
                IList <IObjRelationResult> relationsResult = rootCache.GetObjRelations(cascadeRefreshObjRelationsSet.ToList(), cacheDirective);
                for (int a = relationsResult.Count; a-- > 0;)
                {
                    IObjRelationResult relationResult = relationsResult[a];
                    cascadeRefreshObjRefsSet.AddAll(relationResult.Relations);
                }
                // apply gathered information of unknown relations to the rootCache
                rootCache.Put(relationsResult);
            }
            if (cascadeRefreshObjRefsSet.Count > 0)
            {
                IList <IObjRef> cascadeRefreshObjRefsSetList = cascadeRefreshObjRefsSet.ToList();
                refreshResult = rootCache.GetObjects(cascadeRefreshObjRefsSetList, cacheDirective);
            }
            List <CacheDependencyNode> childNodes = node.childNodes;

            for (int a = childNodes.Count; a-- > 0;)
            {
                ChangeSecondLevelCacheIntern(childNodes[a], failInCacheHierarchyAndCacheValueResultAndReturnMissesSet);
            }
        }
コード例 #13
0
ファイル: CacheDependencyNode.cs プロジェクト: vogelb/ambeth
 public CacheDependencyNode(IRootCache rootCache)
 {
     this.rootCache = rootCache;
 }