Example #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));
            }
        }
 public ContextControllerTreeAgentInstanceList(long filterVersionAfterAllocation, Object initPartitionKey, IDictionary <string, object> initContextProperties, IList <AgentInstance> agentInstances, ContextPartitionState state)
 {
     _filterVersionAfterAllocation = filterVersionAfterAllocation;
     _initPartitionKey             = initPartitionKey;
     _initContextProperties        = initContextProperties;
     _agentInstances = agentInstances;
     _state          = state;
 }
        public void Visit(int nestingLevel, int pathId, ContextStatePathValueBinding binding, Object payload, ContextController contextController, ContextControllerInstanceHandle instanceHandle)
        {
            ContextStatePathKey key = new ContextStatePathKey(nestingLevel, pathId, instanceHandle.SubPathId);
            int agentInstanceId     = instanceHandle.ContextPartitionOrPathId;

            States.Put(key, new ContextStatePathValue(agentInstanceId, binding.ToByteArray(payload), instanceHandle.Instances.State));

            ContextPartitionState      state      = instanceHandle.Instances.State;
            ContextPartitionIdentifier identifier = contextController.Factory.KeyPayloadToIdentifier(payload);
            ContextPartitionDescriptor descriptor = new ContextPartitionDescriptor(agentInstanceId, identifier, state);

            ContextPartitionInfo.Put(agentInstanceId, descriptor);
        }
Example #4
0
 internal static void SetState(IDictionary <int, ContextPartitionDescriptor> original, ContextPartitionState state)
 {
     foreach (var entry in original)
     {
         entry.Value.State = state;
     }
 }
 /// <summary>Ctor. </summary>
 /// <param name="agentInstanceId">context partition id</param>
 /// <param name="identifier">identifier object specific to context declaration</param>
 /// <param name="state">current state</param>
 public ContextPartitionDescriptor(int agentInstanceId, ContextPartitionIdentifier identifier, ContextPartitionState state)
 {
     AgentInstanceId = agentInstanceId;
     Identifier      = identifier;
     State           = state;
 }
Example #6
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));
            }
        }
Example #7
0
 public ContextStatePathValue(int?optionalContextPartitionId, byte[] blob, ContextPartitionState state)
 {
     OptionalContextPartitionId = optionalContextPartitionId;
     Blob  = blob;
     State = state;
 }