internal static ContextPartitionIdentifier[] GetTreeCompositeKey( ContextControllerFactory[] nestedContextFactories, Object initPartitionKey, ContextControllerTreeEntry treeEntry, IDictionary <ContextController, ContextControllerTreeEntry> subcontexts) { var length = nestedContextFactories.Length; var keys = new ContextPartitionIdentifier[length]; keys[length - 1] = nestedContextFactories[length - 1].KeyPayloadToIdentifier(initPartitionKey); keys[length - 2] = nestedContextFactories[length - 2].KeyPayloadToIdentifier(treeEntry.InitPartitionKey); // get parent's parent if (length > 2) { var parent = treeEntry.Parent; var parentEntry = subcontexts.Get(parent); for (var i = 0; i < length - 2; i++) { keys[length - 2 - i] = nestedContextFactories[length - 2 - i].KeyPayloadToIdentifier(parentEntry.InitPartitionKey); parent = parentEntry.Parent; parentEntry = subcontexts.Get(parent); } } return(keys); }
private void RecursivePopulateFilterAddendum( ContextControllerStatementDesc statement, ContextControllerTreeEntry originatorEntry, int contextId, IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]> result) { if (originatorEntry.Parent == null) { return; } originatorEntry.Parent.Factory.PopulateFilterAddendums( result, statement, originatorEntry.InitPartitionKey, contextId); var parentEntry = _subcontexts.Get(originatorEntry.Parent); if (parentEntry != null) { RecursivePopulateFilterAddendum(statement, parentEntry, contextId, result); } }
public ContextControllerInstanceHandle ContextPartitionInstantiate( int?optionalContextPartitionId, int subPathId, int?importSubpathId, ContextController originator, EventBean optionalTriggeringEvent, IDictionary <String, Object> optionalTriggeringPattern, Object partitionKey, IDictionary <String, Object> contextProperties, ContextControllerState states, ContextInternalFilterAddendum filterAddendum, bool isRecoveringResilient, ContextPartitionState state) { using (_iLock.Acquire()) { ContextControllerTreeEntry entry; // detect non-leaf var nestingLevel = originator.Factory.FactoryContext.NestingLevel; // starts at 1 for root if (nestingLevel < _nestedContextFactories.Length) { // next sub-sontext var nextFactory = _nestedContextFactories[originator.Factory.FactoryContext.NestingLevel]; var nextContext = nextFactory.CreateNoCallback(subPathId, this); // link current context to sub-context var branch = _subcontexts.Get(originator); if (branch.ChildContexts == null) { branch.ChildContexts = new Dictionary <int, ContextController>(); } branch.ChildContexts.Put(subPathId, nextContext); // save child branch, linking sub-context to its parent entry = new ContextControllerTreeEntry(originator, null, partitionKey, contextProperties); _subcontexts.Put(nextContext, entry); // now post-initialize, this may actually call back nextContext.Activate( optionalTriggeringEvent, optionalTriggeringPattern, states, filterAddendum, importSubpathId); if (Log.IsDebugEnabled) { Log.Debug( "Instantiating branch context path for " + _contextName + " from level " + originator.Factory.FactoryContext.NestingLevel + "(" + originator.Factory.FactoryContext.ContextName + ")" + " parentPath " + originator.PathId + " for level " + nextContext.Factory.FactoryContext.NestingLevel + "(" + nextContext.Factory.FactoryContext.ContextName + ")" + " childPath " + subPathId ); } return(new ContextManagerNestedInstanceHandle(subPathId, nextContext, subPathId, true, null)); } // assign context id int assignedContextId; if (optionalContextPartitionId != null && !states.IsImported) { assignedContextId = optionalContextPartitionId.Value; _contextPartitionIdManager.AddExisting(optionalContextPartitionId.Value); } else { assignedContextId = _contextPartitionIdManager.AllocateId(); if (states != null && states.PartitionImportCallback != null && optionalContextPartitionId != null) { states.PartitionImportCallback.Allocated(assignedContextId, optionalContextPartitionId.Value); } } if (Log.IsDebugEnabled) { Log.Debug( "Instantiating agent instance for " + _contextName + " from level " + originator.Factory.FactoryContext.NestingLevel + "(" + originator.Factory.FactoryContext.ContextName + ")" + " parentPath " + originator.PathId + " contextPartId " + assignedContextId); } // handle leaf creation IList <AgentInstance> newInstances = new List <AgentInstance>(); if (state == ContextPartitionState.STARTED) { foreach (var statementEntry in _statements) { var statementDesc = statementEntry.Value; var instance = StartStatement( assignedContextId, statementDesc, originator, partitionKey, contextProperties, isRecoveringResilient); newInstances.Add(instance); } } // for all new contexts: evaluate this event for this statement if (optionalTriggeringEvent != null) { StatementAgentInstanceUtil.EvaluateEventForStatement( _servicesContext, optionalTriggeringEvent, optionalTriggeringPattern, newInstances); } // save leaf entry = _subcontexts.Get(originator); if (entry.AgentInstances == null) { entry.AgentInstances = new LinkedHashMap <int, ContextControllerTreeAgentInstanceList>(); } var filterVersion = _servicesContext.FilterService.FiltersVersion; var agentInstanceList = new ContextControllerTreeAgentInstanceList( filterVersion, partitionKey, contextProperties, newInstances, state); entry.AgentInstances.Put(assignedContextId, agentInstanceList); return(new ContextManagerNestedInstanceHandle( subPathId, originator, assignedContextId, false, agentInstanceList)); } }