Esempio n. 1
0
        public void Activate(EventBean optionalTriggeringEvent, IDictionary <String, Object> optionalTriggeringPattern, ContextControllerState controllerState, ContextInternalFilterAddendum activationFilterAddendum, int?importPathId)
        {
            ContextControllerFactoryContext factoryContext = _factory.FactoryContext;

            _activationFilterAddendum = activationFilterAddendum;

            if (factoryContext.NestingLevel == 1)
            {
                controllerState = ContextControllerStateUtil.GetRecoveryStates(_factory.FactoryContext.StateCache, factoryContext.OutermostContextName);
            }
            if (controllerState == null)
            {
                // handle preallocate
                if (_factory.HashedSpec.IsPreallocate)
                {
                    for (int i = 0; i < _factory.HashedSpec.Granularity; i++)
                    {
                        var properties = ContextPropertyEventType.GetHashBean(factoryContext.ContextName, i);
                        _currentSubpathId++;

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

                            _factory.PopulateContextInternalFilterAddendums(filterAddendumToUse, i);
                        }

                        ContextControllerInstanceHandle handle = _activationCallback.ContextPartitionInstantiate(null, _currentSubpathId, null, this, optionalTriggeringEvent, null, i, properties, controllerState, filterAddendumToUse, _factory.FactoryContext.IsRecoveringResilient, ContextPartitionState.STARTED);
                        _partitionKeys.Put(i, handle);

                        _factory.FactoryContext.StateCache.AddContextPath(
                            _factory.FactoryContext.OutermostContextName,
                            _factory.FactoryContext.NestingLevel,
                            _pathId, _currentSubpathId, handle.ContextPartitionOrPathId, i,
                            _factory.Binding);
                    }
                    return;
                }

                // start filters if not preallocated
                ActivateFilters(optionalTriggeringEvent);

                return;
            }

            // initialize from existing state
            int pathIdToUse = importPathId ?? _pathId;

            InitializeFromState(optionalTriggeringEvent, optionalTriggeringPattern, controllerState, pathIdToUse, null, false);

            // activate filters
            if (!_factory.HashedSpec.IsPreallocate)
            {
                ActivateFilters(null);
            }
        }
        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);
        }
        public void Create(Object key, EventBean theEvent)
        {
            lock (_lock)
            {
                var exists = _partitionKeys.ContainsKey(key);
                if (exists)
                {
                    return;
                }

                _currentSubpathId++;

                // determine properties available for querying
                var factoryContext = _factory.FactoryContext;
                var props          = ContextPropertyEventType.GetPartitionBean(
                    factoryContext.ContextName, 0, key, _factory.SegmentedSpec.Items[0].PropertyNames);

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

                    _factory.PopulateContextInternalFilterAddendums(filterAddendum, key);
                }

                var handle = _activationCallback.ContextPartitionInstantiate(
                    null, _currentSubpathId, null, this, theEvent, null, key, props, null, filterAddendum, false,
                    ContextPartitionState.STARTED);

                _partitionKeys.Put(key, handle);

                // update the filter version for this handle
                long filterVersion = factoryContext.ServicesContext.FilterService.FiltersVersion;
                _factory.FactoryContext.AgentInstanceContextCreate.EpStatementAgentInstanceHandle.StatementFilterVersion.StmtFilterVersion = filterVersion;

                var keyObjectSaved = GetKeyObjectsAccountForMultikey(key);
                _factory.FactoryContext.StateCache.AddContextPath(
                    factoryContext.OutermostContextName, factoryContext.NestingLevel, _pathId, _currentSubpathId,
                    handle.ContextPartitionOrPathId, keyObjectSaved, _factory.Binding);
            }
        }