Пример #1
0
        public IList <IEntityMetaData> GetMetaData(IList <Type> entityTypes)
        {
            IdentityHashMap <IMergeServiceExtension, IList <Type> > mseToEntityTypes = new IdentityHashMap <IMergeServiceExtension, IList <Type> >();

            for (int a = entityTypes.Count; a-- > 0;)
            {
                Type entityType = entityTypes[a];
                IMergeServiceExtension mergeServiceExtension = mergeServiceExtensions.GetExtension(entityType);
                if (mergeServiceExtension == null)
                {
                    continue;
                }
                IList <Type> groupedEntityTypes = mseToEntityTypes.Get(mergeServiceExtension);
                if (groupedEntityTypes == null)
                {
                    groupedEntityTypes = new List <Type>();
                    mseToEntityTypes.Put(mergeServiceExtension, groupedEntityTypes);
                }
                groupedEntityTypes.Add(entityType);
            }
            List <IEntityMetaData> metaDataResult = new List <IEntityMetaData>(entityTypes.Count);

            foreach (Entry <IMergeServiceExtension, IList <Type> > entry in mseToEntityTypes)
            {
                IList <IEntityMetaData> groupedMetaData = entry.Key.GetMetaData(entry.Value);
                metaDataResult.AddRange(groupedMetaData);
            }
            return(metaDataResult);
        }
Пример #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 ForkStateEntry[] GetForkStateEntries()
        {
            ForkStateEntry[] cachedForkStateEntries = this.cachedForkStateEntries;
            if (cachedForkStateEntries != null)
            {
                return(cachedForkStateEntries);
            }
            Lock writeLock = listeners.GetWriteLock();

            writeLock.Lock();
            try
            {
                // check again: concurrent thread might have been faster
                cachedForkStateEntries = this.cachedForkStateEntries;
                if (cachedForkStateEntries != null)
                {
                    return(cachedForkStateEntries);
                }
                IThreadLocalCleanupBean[] extensions       = listeners.GetExtensions();
                List <ForkStateEntry>     forkStateEntries = new List <ForkStateEntry>(extensions.Length);
                for (int a = 0, size = extensions.Length; a < size; a++)
                {
                    IThreadLocalCleanupBean extension = extensions[a];
                    FieldInfo[]             fields    = ReflectUtil.GetDeclaredFieldsInHierarchy(extension.GetType());
                    foreach (FieldInfo field in fields)
                    {
                        Forkable forkable = AnnotationUtil.GetAnnotation <Forkable>(field, false);
                        if (forkable == null)
                        {
                            continue;
                        }
                        Object valueTL = field.GetValue(extension);
                        if (valueTL == null)
                        {
                            continue;
                        }
                        Type           forkProcessorType = forkable.Processor;
                        IForkProcessor forkProcessor     = null;
                        if (forkProcessorType != null && !typeof(IForkProcessor).Equals(forkProcessorType))
                        {
                            WeakReference   beanContextOfExtensionR = extensionToContextMap.Get(extension);
                            IServiceContext beanContextOfExtension  = beanContextOfExtensionR != null ? (IServiceContext)beanContextOfExtensionR.Target : null;
                            if (beanContextOfExtension == null)
                            {
                                beanContextOfExtension = BeanContext;
                            }
                            forkProcessor = beanContextOfExtension.RegisterBean <IForkProcessor>(forkProcessorType).Finish();
                        }
                        forkStateEntries.Add(new ForkStateEntry(extension, field.Name, valueTL, forkable.Value, forkProcessor));
                    }
                }
                cachedForkStateEntries      = forkStateEntries.ToArray();
                this.cachedForkStateEntries = cachedForkStateEntries;
                return(cachedForkStateEntries);
            }
            finally
            {
                writeLock.Unlock();
            }
        }
Пример #4
0
        protected ClassEntry <V> CopyStructure()
        {
            ClassEntry <V> newClassEntry = new ClassEntry <V>();
            LinkedHashMap <Type, Object> newTypeToDefEntryMap = newClassEntry.typeToDefEntryMap;
            LinkedHashMap <StrongKey <V>, List <DefEntry <V> > > newDefinitionReverseMap = newClassEntry.definitionReverseMap;
            IdentityHashMap <DefEntry <V>, DefEntry <V> >        originalToCopyMap       = new IdentityHashMap <DefEntry <V>, DefEntry <V> >();

            {
                foreach (Entry <Type, Object> entry in classEntry.typeToDefEntryMap)
                {
                    Type   key   = entry.Key;
                    Object value = entry.Value;

                    if (Object.ReferenceEquals(value, alreadyHandled))
                    {
                        newTypeToDefEntryMap.Put(key, alreadyHandled);
                    }
                    else
                    {
                        InterfaceFastList <DefEntry <V> > list = (InterfaceFastList <DefEntry <V> >)value;

                        InterfaceFastList <DefEntry <V> > newList = new InterfaceFastList <DefEntry <V> >();

                        IListElem <DefEntry <V> > pointer = list.First;
                        while (pointer != null)
                        {
                            DefEntry <V> defEntry    = pointer.ElemValue;
                            DefEntry <V> newDefEntry = new DefEntry <V>(defEntry.extension, defEntry.type, defEntry.distance);
                            originalToCopyMap.Put(defEntry, newDefEntry);

                            newList.PushLast(newDefEntry);
                            pointer = pointer.Next;
                        }
                        newTypeToDefEntryMap.Put(key, newList);
                    }
                    TypeToDefEntryMapChanged(newClassEntry, key);
                }
            }
            foreach (Entry <StrongKey <V>, List <DefEntry <V> > > entry in classEntry.definitionReverseMap)
            {
                List <DefEntry <V> > defEntries    = entry.Value;
                List <DefEntry <V> > newDefEntries = new List <DefEntry <V> >(defEntries.Count);

                for (int a = 0, size = defEntries.Count; a < size; a++)
                {
                    DefEntry <V> newDefEntry = originalToCopyMap.Get(defEntries[a]);
                    if (newDefEntry == null)
                    {
                        throw new Exception("Must never happen");
                    }
                    newDefEntries.Add(newDefEntry);
                }
                newDefinitionReverseMap.Put(entry.Key, newDefEntries);
            }
            return(newClassEntry);
        }
Пример #5
0
        protected void CheckParentCache(ICache parentCache, ICache currentParentCache, ICache childCache, IdentityHashMap <ICache, List <ICache> > cacheToChildCaches,
                                        IdentityHashMap <ICache, ICache> cacheToProxyCache)
        {
            if (currentParentCache != parentCache)
            {
                cacheToProxyCache.Put(currentParentCache, parentCache);
            }
            List <ICache> childCaches = cacheToChildCaches.Get(currentParentCache);

            if (childCaches == null)
            {
                childCaches = new List <ICache>();
                cacheToChildCaches.Put(currentParentCache, childCaches);
            }
            childCaches.Add(childCache);
        }
Пример #6
0
        protected IChangeContainer FillClonedChangeContainer(IChangeContainer original, IdentityHashMap <IChangeContainer, IChangeContainer> alreadyClonedMap)
        {
            IChangeContainer clone = alreadyClonedMap.Get(original);

            if (clone is CreateContainer)
            {
                ((CreateContainer)clone).Primitives = ClonePrimitives(((CreateContainer)original).Primitives);
                ((CreateContainer)clone).Relations  = CloneRelations(((CreateContainer)original).Relations);
            }
            else if (clone is UpdateContainer)
            {
                ((UpdateContainer)clone).Primitives = ClonePrimitives(((UpdateContainer)original).Primitives);
                ((UpdateContainer)clone).Relations  = CloneRelations(((UpdateContainer)original).Relations);
            }
            ((AbstractChangeContainer)clone).Reference = CloneObjRef(original.Reference, true);
            return(clone);
        }
Пример #7
0
        protected IOriCollection Intern(ICUDResult cudResult, IMethodDescription methodDescription, IList <MergeOperation> mergeOperationSequence,
                                        IncrementalMergeState state)
        {
            IList <IChangeContainer> allChanges   = cudResult.AllChanges;
            IList <Object>           originalRefs = cudResult.GetOriginalRefs();
            IdentityHashMap <IChangeContainer, int> changeToChangeIndexDict = new IdentityHashMap <IChangeContainer, int>();

            for (int a = allChanges.Count; a-- > 0;)
            {
                changeToChangeIndexDict.Put(allChanges[a], a);
            }
            IObjRef[] objRefs      = new IObjRef[allChanges.Count];
            long[]    allChangedOn = new long[allChanges.Count];
            String[]  allChangedBy = new String[allChanges.Count];

            CHashSet <long>   changedOnSet = new CHashSet <long>();
            CHashSet <String> changedBySet = new CHashSet <String>();

            for (int a = 0, size = mergeOperationSequence.Count; a < size; a++)
            {
                MergeOperation         mergeOperation        = mergeOperationSequence[a];
                IMergeServiceExtension mergeServiceExtension = mergeOperation.MergeServiceExtension;

                IList <IChangeContainer> changesForMergeService = mergeOperation.ChangeContainer;
                ICUDResult msCudResult = BuildCUDResult(changesForMergeService, changeToChangeIndexDict, originalRefs);

                IOriCollection msOriCollection = mergeServiceExtension.Merge(msCudResult, methodDescription);

                MergeController.ApplyChangesToOriginals(msCudResult, msOriCollection, state.GetStateCache());

                IList <IObjRef> allChangeORIs = msOriCollection.AllChangeORIs;

                long?  msDefaultChangedOn = msOriCollection.ChangedOn;
                String msDefaultChangedBy = msOriCollection.ChangedBy;

                long[]   msAllChangedOn = msOriCollection.AllChangedOn;
                String[] msAllChangedBy = msOriCollection.AllChangedBy;
                for (int b = changesForMergeService.Count; b-- > 0;)
                {
                    int index = changeToChangeIndexDict.Get(changesForMergeService[b]);
                    objRefs[index] = allChangeORIs[b];

                    if (msAllChangedOn != null)
                    {
                        long msChangedOn = msAllChangedOn[b];
                        allChangedOn[index] = msChangedOn;
                        changedOnSet.Add(msChangedOn);
                    }
                    else
                    {
                        allChangedOn[index] = msDefaultChangedOn.Value;
                    }
                    if (msAllChangedBy != null)
                    {
                        String msChangedBy = msAllChangedBy[b];
                        allChangedBy[index] = msChangedBy;
                        changedBySet.Add(msChangedBy);
                    }
                    else
                    {
                        allChangedBy[index] = msDefaultChangedBy;
                    }
                }
                if (msDefaultChangedOn != null)
                {
                    changedOnSet.Add(msDefaultChangedOn.Value);
                }
                if (msDefaultChangedBy != null)
                {
                    changedBySet.Add(msDefaultChangedBy);
                }
            }
            OriCollection oriCollection = new OriCollection();

            oriCollection.AllChangeORIs = new List <IObjRef>(objRefs);

            if (changedBySet.Count == 1)
            {
                Iterator <String> iter = changedBySet.Iterator();
                iter.MoveNext();
                oriCollection.ChangedBy = iter.Current;
            }
            else
            {
                oriCollection.AllChangedBy = allChangedBy;
            }
            if (changedOnSet.Count == 1)
            {
                Iterator <long> iter = changedOnSet.Iterator();
                iter.MoveNext();
                oriCollection.ChangedOn = iter.Current;
            }
            else
            {
                oriCollection.AllChangedOn = allChangedOn;
            }
            foreach (IMergeListener mergeListener in mergeListeners.GetExtensions())
            {
                mergeListener.PostMerge(cudResult, objRefs);
            }
            if (originalRefs != null)
            {
                // Set each original ref to null in order to suppress a post-processing in a potentially calling IMergeProcess
                for (int a = originalRefs.Count; a-- > 0;)
                {
                    originalRefs[a] = null;
                }
            }
            // TODO DCE must be fired HERE <---
            return(oriCollection);
        }
Пример #8
0
        protected IOriCollection MergeIntern(ICUDResult cudResultOriginal, IMethodDescription methodDescription)
        {
            IResultingBackgroundWorkerDelegate <IOriCollection> runnable = new IResultingBackgroundWorkerDelegate <IOriCollection>(delegate()
            {
                IDisposableCache childCache = CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, false, false,
                                                                            "MergeServiceRegistry.STATE");
                try
                {
                    IncrementalMergeState state = null;
                    ICUDResult cudResultOfCache;
                    if (MergeProcess.IsAddNewlyPersistedEntities() || (Log.DebugEnabled && CudResultPrinter != null))
                    {
                        childCache = CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, false, false,
                                                                   "MergeServiceRegistry.STATE");
                        state            = (IncrementalMergeState)CudResultApplier.AcquireNewState(childCache);
                        cudResultOfCache = CudResultApplier.ApplyCUDResultOnEntitiesOfCache(cudResultOriginal, true, state);
                    }
                    else
                    {
                        cudResultOfCache = cudResultOriginal;
                    }
                    if (Log.DebugEnabled)
                    {
                        if (CudResultPrinter != null)
                        {
                            Log.Debug("Initial merge [" + RuntimeHelpers.GetHashCode(state) + "]:\n" + CudResultPrinter.PrintCUDResult(cudResultOfCache, state));
                        }
                        else
                        {
                            Log.Debug("Initial merge [" + RuntimeHelpers.GetHashCode(state) + "]. No Details available");
                        }
                    }
                    List <MergeOperation> mergeOperationSequence = new List <MergeOperation>();
                    ICUDResult extendedCudResult = WhatIfMerged(cudResultOfCache, methodDescription, mergeOperationSequence, state);

                    if (Log.DebugEnabled)
                    {
                        Log.Debug("Merge finished [" + RuntimeHelpers.GetHashCode(state) + "]");
                    }
                    if (MergeSecurityManager != null)
                    {
                        SecurityActive.ExecuteWithSecurityDirective(SecurityDirective.ENABLE_ENTITY_CHECK, delegate()
                        {
                            MergeSecurityManager.CheckMergeAccess(extendedCudResult, methodDescription);
                        });
                    }
                    List <Object> originalRefsOfCache  = new List <Object>(cudResultOfCache.GetOriginalRefs());
                    List <Object> originalRefsExtended = new List <Object>(extendedCudResult.GetOriginalRefs());
                    IOriCollection oriCollExtended     = Intern(extendedCudResult, methodDescription, mergeOperationSequence, state);

                    IList <IChangeContainer> allChangesOriginal = cudResultOriginal.AllChanges;
                    IList <IObjRef> allChangedObjRefsExtended   = oriCollExtended.AllChangeORIs;
                    IObjRef[] allChangedObjRefsResult           = new IObjRef[allChangesOriginal.Count];

                    IdentityHashMap <Object, int?> originalRefOfCacheToIndexMap = new IdentityHashMap <Object, int?>();
                    for (int a = originalRefsOfCache.Count; a-- > 0;)
                    {
                        originalRefOfCacheToIndexMap.Put(originalRefsOfCache[a], a);
                    }
                    for (int a = originalRefsExtended.Count; a-- > 0;)
                    {
                        int?indexOfCache = originalRefOfCacheToIndexMap.Get(originalRefsExtended[a]);
                        if (indexOfCache == null)
                        {
                            // this is a change implied by a rule or an persistence-implicit change
                            // we do not know about it in the outer original CUDResult
                            continue;
                        }
                        IObjRef objRefExtended = allChangedObjRefsExtended[a];
                        IObjRef objRefOriginal = allChangesOriginal[indexOfCache.Value].Reference;
                        if (objRefExtended == null)
                        {
                            // entity has been deleted
                            objRefOriginal.Id      = null;
                            objRefOriginal.Version = null;
                        }
                        else
                        {
                            objRefOriginal.Id      = objRefExtended.Id;
                            objRefOriginal.Version = objRefExtended.Version;
                        }
                        if (objRefOriginal is IDirectObjRef)
                        {
                            ((IDirectObjRef)objRefOriginal).Direct = null;
                        }
                        allChangedObjRefsResult[indexOfCache.Value] = objRefOriginal;
                    }
                    OriCollection oriCollection = new OriCollection(new List <IObjRef>(allChangedObjRefsResult));

                    return(oriCollection);
                }
                finally
                {
                    childCache.Dispose();
                }
            });

            if (SecurityActive == null || !SecurityActive.FilterActivated)
            {
                return(runnable());
            }
            else
            {
                return(SecurityActive.ExecuteWithoutFiltering(runnable));
            }
        }
Пример #9
0
        protected CacheWalkerResult BuildWalkedEntry(ICache cache, IObjRef[] objRefs, IdentityHashMap <ICache, List <ICache> > cacheToChildCaches,
                                                     IdentityHashMap <ICache, ICache> cacheToProxyCache)
        {
            List <ICache> childCaches = cacheToChildCaches.Get(cache);

            CacheWalkerResult[] childCacheEntries;

            if (childCaches == null)
            {
                childCacheEntries = null;
            }
            else
            {
                childCacheEntries = new CacheWalkerResult[childCaches.Count];
                for (int a = childCaches.Count; a-- > 0;)
                {
                    childCacheEntries[a] = BuildWalkedEntry(childCaches[a], objRefs, cacheToChildCaches, cacheToProxyCache);
                }
            }
            ICache proxyCache = cacheToProxyCache.Get(cache);

            bool transactional = false, threadLocal = false;

            if (proxyCache != null)
            {
                threadLocal = true;
                if (TransactionState != null && TransactionState.IsTransactionActive)
                {
                    transactional = true;
                }
            }

            IList <Object> cacheValues;

            if (objRefs != allEntityRefs)
            {
                if (cache is ChildCache)
                {
                    cacheValues = cache.GetObjects(objRefs, CacheDirective.FailEarly | CacheDirective.ReturnMisses);
                }
                else
                {
                    cacheValues = cache.GetObjects(objRefs, CacheDirective.FailEarly | CacheDirective.CacheValueResult | CacheDirective.ReturnMisses);
                }
            }
            else
            {
                IdentityHashSet <Object> fCacheValues = new IdentityHashSet <Object>();
                cache.GetContent(new HandleContentDelegate(delegate(Type entityType, sbyte idIndex, Object id, Object value)
                {
                    fCacheValues.Add(value);
                }));
                cacheValues = fCacheValues.ToList();

                // generate ad-hoc objRefs
                objRefs = cacheValues.Count > 0 ? ListUtil.ToArray(ObjRefHelper.ExtractObjRefList(cacheValues, null)) : ObjRef.EMPTY_ARRAY;
            }
            Object childEntries = childCacheEntries;

            if (childCacheEntries != null && childCacheEntries.Length == 1)
            {
                childEntries = childCacheEntries[0];
            }
            CacheWalkerResult parentEntry = new CacheWalkerResult(cache, transactional, threadLocal, objRefs, ListUtil.ToArray(cacheValues), childEntries);

            if (childCacheEntries != null)
            {
                for (int a = childCacheEntries.Length; a-- > 0;)
                {
                    childCacheEntries[a].ParentEntry = parentEntry;
                }
            }
            if (objRefs != allEntityRefs)
            {
                parentEntry.UpdatePendingChanges();
            }
            return(parentEntry);
        }
Пример #10
0
        public void AfterStarted()
        {
            DirectoryInfo targetInfo = new DirectoryInfo(TargetDir);

            targetInfo.Create();

            Log.Info("Saving all generated images to '" + targetInfo.FullName + "'");

            String[] sources = SourceDir.Split(';');
            foreach (String source in sources)
            {
                Log.Info("Scanning for office files in '" + source + "'");
                DirectoryInfo di          = new DirectoryInfo(source);
                FileInfo[]    directories = di.GetFiles("*", SearchOption.AllDirectories);

                IdentityHashMap <IFileParser, List <FileInfo> > queuedFilesMap = new IdentityHashMap <IFileParser, List <FileInfo> >();

                foreach (FileInfo sourceFile in directories)
                {
                    if (sourceFile.Name.Contains('~') || !sourceFile.Exists)
                    {
                        continue;
                    }
                    String lowercaseExtensionName = sourceFile.Extension.ToLowerInvariant();
                    if (lowercaseExtensionName.StartsWith("."))
                    {
                        lowercaseExtensionName = lowercaseExtensionName.Substring(1);
                    }
                    IFileParser fileParser = fileParsers.GetExtension(lowercaseExtensionName);
                    if (fileParser == null)
                    {
                        Log.Debug("Skipping '" + sourceFile.FullName + "': no parser configured for '" + lowercaseExtensionName + "'");
                        continue;
                    }
                    List <FileInfo> queuedFiles = queuedFilesMap.Get(fileParser);
                    if (queuedFiles == null)
                    {
                        queuedFiles = new List <FileInfo>();
                        queuedFilesMap.Put(fileParser, queuedFiles);
                    }
                    queuedFiles.Add(sourceFile);
                }
                List <Thread>  threads = new List <Thread>();
                CountDownLatch latch   = new CountDownLatch(queuedFilesMap.Count);

                foreach (Entry <IFileParser, List <FileInfo> > entry in queuedFilesMap)
                {
                    IFileParser      fileParser  = entry.Key;
                    IList <FileInfo> sourceFiles = entry.Value;
                    Thread           thread      = new Thread(new ThreadStart(delegate()
                    {
                        ParseFiles(fileParser, sourceFiles, targetInfo, latch);
                    }));
                    thread.Name         = fileParser.GetType().Name;
                    thread.IsBackground = true;
                    threads.Add(thread);
                }
                foreach (Thread thread in threads)
                {
                    thread.Start();
                }
                latch.Await(TimeSpan.FromMinutes(5)); // throw exception after some minutes
            }
        }