Пример #1
0
        public static IDictionary <ContextStatePathKey, ContextStatePathValue> GetChildContexts(ContextControllerFactoryContext factoryContext, int pathId, OrderedDictionary <ContextStatePathKey, ContextStatePathValue> states)
        {
            ContextStatePathKey start = new ContextStatePathKey(factoryContext.NestingLevel, pathId, int.MinValue);
            ContextStatePathKey end   = new ContextStatePathKey(factoryContext.NestingLevel, pathId, int.MaxValue);

            return(states.Between(start, true, end, true));
        }
Пример #2
0
        public void Visit(int nestingLevel, int pathId, ContextStatePathValueBinding binding, Object payload, ContextController contextController, ContextControllerInstanceHandle instanceHandle)
        {
            var key             = new ContextStatePathKey(nestingLevel, pathId, instanceHandle.SubPathId);
            int maxNestingLevel = _nestedFactories.Length;

            int contextPartitionOrSubPath = instanceHandle.ContextPartitionOrPathId;

            if (contextController.Factory.FactoryContext.NestingLevel == maxNestingLevel)
            {
                var agentInstances = ControllerAgentInstances.Get(contextController);
                if (agentInstances == null)
                {
                    agentInstances = new List <LeafDesc>();
                    ControllerAgentInstances.Put(contextController, agentInstances);
                }
                var value = new ContextStatePathValue(contextPartitionOrSubPath, binding.ToByteArray(payload), instanceHandle.Instances.State);
                agentInstances.Add(new LeafDesc(key, value));

                // generate a nice payload text from the paths of keys
                var entry      = _subcontexts.Get(contextController);
                var keys       = ContextManagerNested.GetTreeCompositeKey(_nestedFactories, payload, entry, _subcontexts);
                var descriptor = new ContextPartitionDescriptor(contextPartitionOrSubPath, new ContextPartitionIdentifierNested(keys), value.State);
                AgentInstanceInfo.Put(contextPartitionOrSubPath, descriptor);
                States.Put(key, value);
            }
            else
            {
                // handle non-leaf
                Subpaths.Add(contextPartitionOrSubPath);
                States.Put(key, new ContextStatePathValue(contextPartitionOrSubPath, binding.ToByteArray(payload), ContextPartitionState.STARTED));
            }
        }
 public static ContextControllerCondition GetEndpoint(String contextName,
                                                      EPServicesContext servicesContext,
                                                      AgentInstanceContext agentInstanceContext,
                                                      ContextDetailCondition endpoint,
                                                      ContextControllerConditionCallback callback,
                                                      ContextInternalFilterAddendum filterAddendum,
                                                      bool isStartEndpoint,
                                                      int nestingLevel,
                                                      int pathId,
                                                      int subpathId) {
     if (endpoint is ContextDetailConditionCrontab) {
         var crontab = (ContextDetailConditionCrontab) endpoint;
         var scheduleSlot = agentInstanceContext.StatementContext.ScheduleBucket.AllocateSlot();
         return new ContextControllerConditionCrontab(agentInstanceContext.StatementContext, scheduleSlot, crontab, callback, filterAddendum);
     }
     else if (endpoint is ContextDetailConditionFilter) {
         var filter = (ContextDetailConditionFilter) endpoint;
         return new ContextControllerConditionFilter(servicesContext, agentInstanceContext, filter, callback, filterAddendum);
     }
     else if (endpoint is ContextDetailConditionPattern) {
         var key = new ContextStatePathKey(nestingLevel, pathId, subpathId);
         var pattern = (ContextDetailConditionPattern) endpoint;
         return new ContextControllerConditionPattern(servicesContext, agentInstanceContext, pattern, callback, filterAddendum, isStartEndpoint, key);
     }
     else if (endpoint is ContextDetailConditionTimePeriod) {
         var timePeriod = (ContextDetailConditionTimePeriod) endpoint;
         var scheduleSlot = agentInstanceContext.StatementContext.ScheduleBucket.AllocateSlot();
         return new ContextControllerConditionTimePeriod(contextName, agentInstanceContext, scheduleSlot, timePeriod, callback, filterAddendum);
     }
     else if (endpoint is ContextDetailConditionImmediate) {
         return new ContextControllerConditionImmediate();
     }
     throw new IllegalStateException("Unrecognized context range endpoint " + endpoint.GetType());
 }
 public ContextControllerConditionPattern(EPServicesContext servicesContext, AgentInstanceContext agentInstanceContext, ContextDetailConditionPattern endpointPatternSpec, ContextControllerConditionCallback callback, ContextInternalFilterAddendum filterAddendum, bool startEndpoint, ContextStatePathKey contextStatePathKey)
 {
     _servicesContext      = servicesContext;
     _agentInstanceContext = agentInstanceContext;
     _endpointPatternSpec  = endpointPatternSpec;
     _callback             = callback;
     _filterAddendum       = filterAddendum;
     _isStartEndpoint      = startEndpoint;
     _contextStatePathKey  = contextStatePathKey;
 }
Пример #5
0
        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);
        }
Пример #6
0
        public void ContextPartitionNavigate(ContextControllerInstanceHandle existingHandle, ContextController originator, ContextControllerState controllerState, int exportedCPOrPathId, ContextInternalFilterAddendum filterAddendum, AgentInstanceSelector agentInstanceSelector, byte[] payload, bool isRecoveringResilient)
        {
            var entry = _agentInstances.Get(existingHandle.ContextPartitionOrPathId);

            if (entry == null)
            {
                return;
            }

            if (entry.State == ContextPartitionState.STOPPED)
            {
                entry.State = ContextPartitionState.STARTED;
                entry.AgentInstances.Clear();
                foreach (var statement in _statements)
                {
                    var instance = StartStatement(existingHandle.ContextPartitionOrPathId, statement.Value, originator, entry.InitPartitionKey, entry.InitContextProperties, false);
                    entry.AgentInstances.Add(instance);
                }
                var key   = new ContextStatePathKey(1, 0, existingHandle.SubPathId);
                var value = new ContextStatePathValue(existingHandle.ContextPartitionOrPathId, payload, ContextPartitionState.STARTED);
                _rootContext.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, key, value);
            }
            else
            {
                IList <AgentInstance> removed = new List <AgentInstance>(2);
                IList <AgentInstance> added   = new List <AgentInstance>(2);
                foreach (var agentInstance in entry.AgentInstances)
                {
                    if (!agentInstanceSelector.Select(agentInstance))
                    {
                        continue;
                    }

                    // remove
                    StatementAgentInstanceUtil.StopAgentInstanceRemoveResources(agentInstance, null, _servicesContext, false, false);
                    removed.Add(agentInstance);

                    // start
                    var statementDesc = _statements.Get(agentInstance.AgentInstanceContext.StatementId);
                    var instance      = StartStatement(existingHandle.ContextPartitionOrPathId, statementDesc, originator, entry.InitPartitionKey, entry.InitContextProperties, isRecoveringResilient);
                    added.Add(instance);

                    if (controllerState.PartitionImportCallback != null)
                    {
                        controllerState.PartitionImportCallback.Existing(existingHandle.ContextPartitionOrPathId, exportedCPOrPathId);
                    }
                }
                entry.AgentInstances.RemoveAll(removed);
                entry.AgentInstances.AddAll(added);
            }
        }
Пример #7
0
 public LeafDesc(ContextStatePathKey key, ContextStatePathValue value)
 {
     Key   = key;
     Value = value;
 }
Пример #8
0
        public void ContextPartitionNavigate(
            ContextControllerInstanceHandle existingHandle,
            ContextController originator,
            ContextControllerState controllerState,
            int exportedCPOrPathId,
            ContextInternalFilterAddendum filterAddendum,
            AgentInstanceSelector agentInstanceSelector,
            byte[] payload,
            bool isRecoveringResilient)
        {
            var nestedHandle = (ContextManagerNestedInstanceHandle)existingHandle;

            // detect non-leaf
            var nestingLevel = originator.Factory.FactoryContext.NestingLevel; // starts at 1 for root

            if (nestingLevel < _nestedContextFactories.Length)
            {
                nestedHandle.Controller.ImportContextPartitions(
                    controllerState, exportedCPOrPathId, filterAddendum, agentInstanceSelector);
                return;
            }

            var entry = _subcontexts.Get(originator);

            if (entry == null)
            {
                return;
            }
            foreach (var cpEntry in entry.AgentInstances.ToArray())
            {
                if (cpEntry.Value.State == ContextPartitionState.STOPPED)
                {
                    cpEntry.Value.State = ContextPartitionState.STARTED;
                    entry.AgentInstances.Clear();
                    foreach (var statement in _statements)
                    {
                        var instance = StartStatement(
                            existingHandle.ContextPartitionOrPathId, statement.Value, originator,
                            cpEntry.Value.InitPartitionKey, entry.InitContextProperties, false);
                        cpEntry.Value.AgentInstances.Add(instance);
                    }
                    var key = new ContextStatePathKey(
                        _nestedContextFactories.Length, originator.PathId, existingHandle.SubPathId);
                    var value = new ContextStatePathValue(
                        existingHandle.ContextPartitionOrPathId, payload, ContextPartitionState.STARTED);
                    originator.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, key, value);
                }
                else
                {
                    IList <AgentInstance> removed = new List <AgentInstance>(2);
                    IList <AgentInstance> added   = new List <AgentInstance>(2);
                    var current = cpEntry.Value.AgentInstances;

                    foreach (var agentInstance in current)
                    {
                        if (!agentInstanceSelector.Select(agentInstance))
                        {
                            continue;
                        }

                        // remove
                        StatementAgentInstanceUtil.StopAgentInstanceRemoveResources(
                            agentInstance, null, _servicesContext, false, false);
                        removed.Add(agentInstance);

                        // start
                        var statementDesc = _statements.Get(agentInstance.AgentInstanceContext.StatementId);
                        var instance      = StartStatement(
                            cpEntry.Key, statementDesc, originator, cpEntry.Value.InitPartitionKey,
                            entry.InitContextProperties, false);
                        added.Add(instance);

                        if (controllerState.PartitionImportCallback != null)
                        {
                            controllerState.PartitionImportCallback.Existing(
                                existingHandle.ContextPartitionOrPathId, exportedCPOrPathId);
                        }
                    }
                    current.RemoveAll(removed);
                    current.AddAll(added);
                }
            }
        }
Пример #9
0
 public void UpdateContextPath(String contextName, ContextStatePathKey key, ContextStatePathValue value)
 {
     // no action required
 }