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); }
public void RegisterThreadLocalCleanupBean(IThreadLocalCleanupBean threadLocalCleanupBean) { Lock writeLock = listeners.GetWriteLock(); writeLock.Lock(); try { listeners.Register(threadLocalCleanupBean); cachedForkStateEntries = null; IServiceContext currentBeanContext = BeanContextInitializer.GetCurrentBeanContext(); if (currentBeanContext != null) { extensionToContextMap.Put(threadLocalCleanupBean, new WeakReference(currentBeanContext)); if (alreadyHookedContextSet.PutIfNotExists(currentBeanContext, null)) { ParamHolder <bool?> inactive = new ParamHolder <bool?>(); currentBeanContext.RegisterDisposeHook(new IBackgroundWorkerParamDelegate <IServiceContext>(delegate(IServiceContext state) { if (inactive.Value.HasValue && inactive.Value.Value) { return; } foreignContextHook(state); })); alreadyHookedContextSet.Put(currentBeanContext, inactive); } } } finally { writeLock.Unlock(); } }
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); }
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); }
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); }
/* Add a new shutdown hook. Checks the shutdown state and the hook itself, * but does not do any security checks. */ internal static void Add(Thread hook) { lock (typeof(ApplicationShutdownHooks)) { if (Hooks == null) { throw new IllegalStateException("Shutdown in progress"); } if (hook.Alive) { throw new IllegalArgumentException("Hook already running"); } if (Hooks.ContainsKey(hook)) { throw new IllegalArgumentException("Hook previously registered"); } Hooks.Put(hook, hook); } }
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); }
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)); } }
protected ICUDResult ApplyIntern(ICUDResult cudResult, bool checkBaseState, IncrementalMergeState incrementalState) { ICache stateCache = incrementalState.GetStateCache(); IList <IChangeContainer> allChanges = cudResult.AllChanges; IList <Object> originalRefs = cudResult.GetOriginalRefs(); IList <Object> allObjects = GetAllExistingObjectsFromCache(stateCache, allChanges); List <Object> hardRefs = new List <Object>(); hardRefs.Add(allObjects); // add list as item intended. adding each item of the source is NOT needed List <IObjRef> toFetchFromCache = new List <IObjRef>(); List <DirectValueHolderRef> toPrefetch = new List <DirectValueHolderRef>(); List <IBackgroundWorkerDelegate> runnables = new List <IBackgroundWorkerDelegate>(); IEntityFactory entityFactory = this.EntityFactory; IdentityHashMap <IObjRef, StateEntry> newObjRefToStateEntryMap = new IdentityHashMap <IObjRef, StateEntry>(); IdentityHashMap <IChangeContainer, IChangeContainer> alreadyClonedMap = new IdentityHashMap <IChangeContainer, IChangeContainer>(); List <IChangeContainer> newAllChanges = new List <IChangeContainer>(allChanges.Count); for (int a = 0, size = allChanges.Count; a < size; a++) { IChangeContainer changeContainer = allChanges[a]; Object originalEntity = originalRefs[a]; StateEntry stateEntry = incrementalState.entityToStateMap.Get(originalEntity); IChangeContainer newChangeContainer; if (changeContainer is CreateContainer) { newChangeContainer = new CreateContainer(); } else if (changeContainer is UpdateContainer) { newChangeContainer = new UpdateContainer(); } else { newChangeContainer = new DeleteContainer(); } newAllChanges.Add(newChangeContainer); alreadyClonedMap.Put(changeContainer, newChangeContainer); if (!(changeContainer is CreateContainer)) { Object stateCacheEntity2 = allObjects[a]; stateEntry = incrementalState.entityToStateMap.Get(stateCacheEntity2); if (stateEntry == null) { stateEntry = new StateEntry(stateCacheEntity2, changeContainer.Reference, incrementalState.entityToStateMap.Count + 1); incrementalState.entityToStateMap.Put(stateCacheEntity2, stateEntry); incrementalState.objRefToStateMap.Put(stateEntry.objRef, stateEntry); } // delete & update do not need further handling continue; } Type realType = changeContainer.Reference.RealType; Object stateCacheEntity; if (stateEntry == null) { stateCacheEntity = entityFactory.CreateEntity(realType); DirectObjRef directObjRef = new DirectObjRef(realType, stateCacheEntity); directObjRef.CreateContainerIndex = a; stateEntry = new StateEntry(stateCacheEntity, directObjRef, incrementalState.entityToStateMap.Count + 1); incrementalState.entityToStateMap.Put(stateCacheEntity, stateEntry); incrementalState.objRefToStateMap.Put(stateEntry.objRef, stateEntry); newObjRefToStateEntryMap.Put(changeContainer.Reference, stateEntry); } else { stateCacheEntity = stateEntry.entity; } allObjects[a] = stateCacheEntity; } cloneStateTL.Value = new CloneState(newObjRefToStateEntryMap, incrementalState); try { for (int a = allChanges.Count; a-- > 0;) { IChangeContainer changeContainer = allChanges[a]; IObjRefContainer entity = (IObjRefContainer)allObjects[a]; changeContainer = FillClonedChangeContainer(changeContainer, alreadyClonedMap); IPrimitiveUpdateItem[] puis; IRelationUpdateItem[] ruis; if (changeContainer is CreateContainer) { CreateContainer createContainer = (CreateContainer)changeContainer; puis = createContainer.Primitives; ruis = createContainer.Relations; } else if (changeContainer is UpdateContainer) { UpdateContainer updateContainer = (UpdateContainer)changeContainer; puis = updateContainer.Primitives; ruis = updateContainer.Relations; } else { ((IDataObject)entity).ToBeDeleted = true; continue; } IEntityMetaData metaData = ((IEntityMetaDataHolder)entity).Get__EntityMetaData(); ApplyPrimitiveUpdateItems(entity, puis, metaData); if (ruis != null) { bool isUpdate = changeContainer is UpdateContainer; foreach (IRelationUpdateItem rui in ruis) { ApplyRelationUpdateItem(entity, rui, isUpdate, metaData, toPrefetch, toFetchFromCache, checkBaseState, runnables); } } } while (toPrefetch.Count > 0 || toFetchFromCache.Count > 0 || runnables.Count > 0) { if (toPrefetch.Count > 0) { PrefetchHelper.Prefetch(toPrefetch); toPrefetch.Clear(); } if (toFetchFromCache.Count > 0) { IList <Object> fetchedObjects = stateCache.GetObjects(toFetchFromCache, CacheDirective.None); hardRefs.Add(fetchedObjects); // add list as item intended. adding each item of the source is NOT needed toFetchFromCache.Clear(); } IBackgroundWorkerDelegate[] runnableArray = runnables.ToArray(); runnables.Clear(); foreach (IBackgroundWorkerDelegate runnable in runnableArray) { runnable(); } } List <Object> newObjects = new List <Object>(allObjects.Count); List <DirectValueHolderRef> changedRelationRefs = new List <DirectValueHolderRef>(); for (int a = allObjects.Count; a-- > 0;) { IChangeContainer newChange = newAllChanges[a]; IRelationUpdateItem[] ruis = null; Object entity = allObjects[a]; if (newChange is CreateContainer) { newObjects.Add(entity); ruis = ((CreateContainer)newChange).Relations; } else if (newChange is UpdateContainer) { ruis = ((UpdateContainer)newChange).Relations; } if (ruis == null) { continue; } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entity.GetType()); foreach (IRelationUpdateItem rui in ruis) { Member member = metaData.GetMemberByName(rui.MemberName); changedRelationRefs.Add(new DirectValueHolderRef((IObjRefContainer)entity, (RelationMember)member)); } } if (newObjects.Count > 0) { ((IWritableCache)stateCache).Put(newObjects); } if (changedRelationRefs.Count > 0) { PrefetchHelper.Prefetch(changedRelationRefs); } return(new CUDResult(newAllChanges, allObjects)); } finally { cloneStateTL.Value = null; } }
protected bool EqualsCUDResult(CUDResultDiff cudResultDiff) { ICUDResult left = cudResultDiff.left; ICUDResult right = cudResultDiff.right; IList <Object> leftRefs = left.GetOriginalRefs(); IList <Object> rightRefs = right.GetOriginalRefs(); if (leftRefs.Count != rightRefs.Count) { if (!cudResultDiff.doFullDiff) { return(false); } } IList <IChangeContainer> leftChanges = left.AllChanges; IList <IChangeContainer> rightChanges = right.AllChanges; IdentityHashMap <Object, int?> rightMap = IdentityHashMap <Object, int?> .Create(rightRefs.Count); for (int a = rightRefs.Count; a-- > 0;) { rightMap.Put(rightRefs[a], a); } for (int a = leftRefs.Count; a-- > 0;) { Object leftEntity = leftRefs[a]; int? rightIndex = rightMap.Remove(leftEntity); if (!rightIndex.HasValue) { if (!cudResultDiff.doFullDiff) { return(false); } cudResultDiff.diffChanges.Add(leftChanges[a]); cudResultDiff.originalRefs.Add(leftEntity); continue; } if (!EqualsChangeContainer(cudResultDiff, leftChanges[a], rightChanges[rightIndex.Value])) { if (!cudResultDiff.doFullDiff) { if (cudResultDiff.containerBuild != null) { throw new Exception(); } return(false); } cudResultDiff.diffChanges.Add(cudResultDiff.containerBuild); cudResultDiff.originalRefs.Add(rightRefs[rightIndex.Value]); cudResultDiff.containerBuild = null; } else if (cudResultDiff.containerBuild != null) { throw new Exception(); } } if (rightMap.Count == 0) { return(true); } foreach (Entry <Object, int> entry in rightMap) { Object rightRef = entry.Key; int rightIndex = entry.Value; IChangeContainer rightChange = rightChanges[rightIndex]; cudResultDiff.diffChanges.Add(rightChange); cudResultDiff.originalRefs.Add(rightRef); } return(false); }
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 } }