Exemplo n.º 1
0
        public void Activate(
            EventBean optionalTriggeringEvent,
            IDictionary <String, Object> optionalTriggeringPattern,
            ContextControllerState controllerState,
            ContextInternalFilterAddendum activationFilterAddendum,
            int?importPathId)
        {
            if (Factory.FactoryContext.NestingLevel == 1)
            {
                controllerState = ContextControllerStateUtil.GetRecoveryStates(
                    Factory.StateCache, Factory.FactoryContext.OutermostContextName);
            }

            if (controllerState == null)
            {
                var count = 0;
                foreach (var category in _factory.CategorySpec.Items)
                {
                    var context =
                        ContextPropertyEventType.GetCategorizedBean(
                            Factory.FactoryContext.ContextName, 0, category.Name);
                    _currentSubpathId++;

                    // merge filter addendum, if any
                    var filterAddendumToUse = activationFilterAddendum;
                    if (_factory.HasFiltersSpecsNestedContexts())
                    {
                        filterAddendumToUse = activationFilterAddendum != null
                            ? activationFilterAddendum.DeepCopy()
                            : new ContextInternalFilterAddendum();

                        _factory.PopulateContextInternalFilterAddendums(filterAddendumToUse, count);
                    }

                    var handle = _activationCallback.ContextPartitionInstantiate(
                        null, _currentSubpathId, null, this, optionalTriggeringEvent, optionalTriggeringPattern, count,
                        context, controllerState, filterAddendumToUse, Factory.FactoryContext.IsRecoveringResilient,
                        ContextPartitionState.STARTED);
                    _handleCategories.Put(count, handle);

                    Factory.StateCache.AddContextPath(
                        Factory.FactoryContext.OutermostContextName, Factory.FactoryContext.NestingLevel, PathId,
                        _currentSubpathId, handle.ContextPartitionOrPathId, count, _factory.Binding);
                    count++;
                }
                return;
            }

            var pathIdToUse = importPathId != null ? importPathId.Value : PathId;

            InitializeFromState(
                optionalTriggeringEvent, optionalTriggeringPattern, activationFilterAddendum, controllerState,
                pathIdToUse, null);
        }
Exemplo n.º 2
0
        private void InitializeFromState(
            EventBean optionalTriggeringEvent,
            IDictionary <String, Object> optionalTriggeringPattern,
            ContextInternalFilterAddendum activationFilterAddendum,
            ContextControllerState controllerState,
            int pathIdToUse,
            AgentInstanceSelector agentInstanceSelector)
        {
            var states        = controllerState.States;
            var childContexts = ContextControllerStateUtil.GetChildContexts(
                Factory.FactoryContext, pathIdToUse, states);

            int maxSubpathId = int.MinValue;

            foreach (var entry in childContexts)
            {
                var categoryNumber = (int)_factory.Binding.ByteArrayToObject(entry.Value.Blob, null);
                ContextDetailCategoryItem category = _factory.CategorySpec.Items[categoryNumber];

                // merge filter addendum, if any
                var filterAddendumToUse = activationFilterAddendum;
                if (_factory.HasFiltersSpecsNestedContexts())
                {
                    filterAddendumToUse = activationFilterAddendum != null
                        ? activationFilterAddendum.DeepCopy()
                        : new ContextInternalFilterAddendum();

                    _factory.PopulateContextInternalFilterAddendums(filterAddendumToUse, categoryNumber);
                }

                // check if exists already
                if (controllerState.IsImported)
                {
                    var existingHandle = _handleCategories.Get(categoryNumber);
                    if (existingHandle != null)
                    {
                        _activationCallback.ContextPartitionNavigate(
                            existingHandle, this, controllerState, entry.Value.OptionalContextPartitionId.Value,
                            filterAddendumToUse, agentInstanceSelector, entry.Value.Blob);
                        continue;
                    }
                }

                var context =
                    ContextPropertyEventType.GetCategorizedBean(Factory.FactoryContext.ContextName, 0, category.Name);

                var contextPartitionId = entry.Value.OptionalContextPartitionId.Value;
                var assignedSubPathId  = !controllerState.IsImported ? entry.Key.SubPath : ++_currentSubpathId;
                var handle             =
                    _activationCallback.ContextPartitionInstantiate(
                        contextPartitionId, assignedSubPathId, entry.Key.SubPath, this, null, null, categoryNumber,
                        context, controllerState, filterAddendumToUse, Factory.FactoryContext.IsRecoveringResilient,
                        entry.Value.State);
                _handleCategories.Put(categoryNumber, handle);

                if (entry.Key.SubPath > maxSubpathId)
                {
                    maxSubpathId = assignedSubPathId;
                }
            }
            if (!controllerState.IsImported)
            {
                _currentSubpathId = maxSubpathId != int.MinValue ? maxSubpathId : 0;
            }
        }