Beispiel #1
0
        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 (_uLock.Acquire()) {
                // 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);
                    }
                }

                // 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 || optionalTriggeringPattern != null)
                {
                    StatementAgentInstanceUtil.EvaluateEventForStatement(_servicesContext, optionalTriggeringEvent, optionalTriggeringPattern, newInstances);
                }

                // save leaf
                var filterVersion     = _servicesContext.FilterService.FiltersVersion;
                var agentInstanceList = new ContextControllerTreeAgentInstanceList(filterVersion, partitionKey, contextProperties, newInstances, state);
                _agentInstances.Put(assignedContextId, agentInstanceList);

                // Update the filter version for this handle
                _factory.FactoryContext.AgentInstanceContextCreate.EpStatementAgentInstanceHandle.StatementFilterVersion.StmtFilterVersion = filterVersion;

                return(new ContextNestedHandleImpl(subPathId, assignedContextId, agentInstanceList));
            }
        }
Beispiel #2
0
 public ContextNestedHandleImpl(int subPathId, int contextPartitionId, ContextControllerTreeAgentInstanceList instances)
 {
     SubPathId = subPathId;
     ContextPartitionOrPathId = contextPartitionId;
     Instances = instances;
 }
Beispiel #3
0
        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));
            }
        }