private AgentInstance StartStatement( int contextId, ContextControllerStatementDesc statementDesc, ContextController originator, Object partitionKey, IDictionary <String, Object> contextProperties, bool isRecoveringResilient) { // build filters var proxy = GetMergedFilterAddendums(statementDesc, originator, partitionKey, contextId); // build built-in context properties var properties = ContextPropertyEventType.GetNestedBeanBase(_contextName, contextId); properties.Put( _nestedContextFactories[_nestedContextFactories.Length - 1].FactoryContext.ContextName, contextProperties); RecursivePopulateBuiltinProps(originator, properties); properties.Put(ContextPropertyEventType.PROP_CTX_NAME, _contextName); properties.Put(ContextPropertyEventType.PROP_CTX_ID, contextId); var contextBean = (MappedEventBean) _servicesContext.EventAdapterService.AdapterForTypedMap( properties, _contextDescriptor.ContextPropertyRegistry.ContextEventType); // activate var result = StatementAgentInstanceUtil.Start( _servicesContext, statementDesc.Statement, false, contextId, contextBean, proxy, isRecoveringResilient); return(new AgentInstance(result.StopCallback, result.AgentInstanceContext, result.FinalView)); }
public void Create(int id, EventBean theEvent) { lock (this) { ContextControllerFactoryContext factoryContext = _factory.FactoryContext; if (_partitionKeys.ContainsKey(id)) { return; } IDictionary <String, Object> properties = ContextPropertyEventType.GetHashBean(factoryContext.ContextName, id); _currentSubpathId++; // merge filter addendum, if any ContextInternalFilterAddendum filterAddendumToUse = _activationFilterAddendum; if (_factory.HasFiltersSpecsNestedContexts) { filterAddendumToUse = _activationFilterAddendum != null?_activationFilterAddendum.DeepCopy() : new ContextInternalFilterAddendum(); _factory.PopulateContextInternalFilterAddendums(filterAddendumToUse, id); } ContextControllerInstanceHandle handle = _activationCallback.ContextPartitionInstantiate(null, _currentSubpathId, null, this, theEvent, null, id, properties, null, filterAddendumToUse, _factory.FactoryContext.IsRecoveringResilient, ContextPartitionState.STARTED); _partitionKeys.Put(id, handle); _factory.FactoryContext.StateCache.AddContextPath(factoryContext.OutermostContextName, factoryContext.NestingLevel, _pathId, _currentSubpathId, handle.ContextPartitionOrPathId, id, _factory.Binding); // update the filter version for this handle long filterVersion = factoryContext.ServicesContext.FilterService.FiltersVersion; _factory.FactoryContext.AgentInstanceContextCreate.EpStatementAgentInstanceHandle.StatementFilterVersion.StmtFilterVersion = filterVersion; } }
public ContextManagerNested(ContextControllerFactoryServiceContext factoryServiceContext) { _contextName = factoryServiceContext.ContextName; _servicesContext = factoryServiceContext.ServicesContext; _contextPartitionIdManager = factoryServiceContext.AgentInstanceContextCreate.StatementContext.ContextControllerFactoryService.AllocatePartitionIdMgr( _contextName, factoryServiceContext.AgentInstanceContextCreate.StatementContext.StatementId); _nestedContextFactories = factoryServiceContext.AgentInstanceContextCreate.StatementContext.ContextControllerFactoryService.GetFactory( factoryServiceContext); StatementAIResourceRegistryFactory resourceRegistryFactory = () => new StatementAIResourceRegistry(new AIRegistryAggregationMap(), new AIRegistryExprMap()); var contextProps = ContextPropertyEventType.GetNestedTypeBase(); foreach (var factory in _nestedContextFactories) { contextProps.Put(factory.FactoryContext.ContextName, factory.ContextBuiltinProps); } var contextPropsType = _servicesContext.EventAdapterService.CreateAnonymousMapType( _contextName, contextProps, true); var registry = new ContextPropertyRegistryImpl( Collections.GetEmptyList <ContextDetailPartitionItem>(), contextPropsType); _contextDescriptor = new ContextDescriptor( _contextName, false, registry, resourceRegistryFactory, this, factoryServiceContext.Detail); }
public override void ValidateFactory() { if (_categorySpec.Items.IsEmpty()) { throw new ExprValidationException("Empty list of partition items"); } _contextBuiltinProps = ContextPropertyEventType.GetCategorizedType(); }
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 override void ValidateFactory() { _contextBuiltinProps = ContextPropertyEventType.GetInitiatedTerminatedType(); LinkedHashSet <String> allTags = new LinkedHashSet <String>(); ContextPropertyEventType.AddEndpointTypes(FactoryContext.ContextName, _detail.Start, _contextBuiltinProps, allTags); ContextPropertyEventType.AddEndpointTypes(FactoryContext.ContextName, _detail.End, _contextBuiltinProps, allTags); _matchedEventMapMeta = new MatchedEventMapMeta(allTags, false); }
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); }
private void InitializeFromState(EventBean optionalTriggeringEvent, IDictionary <String, Object> optionalTriggeringPattern, ContextControllerState controllerState, int pathIdToUse, AgentInstanceSelector agentInstanceSelector) { var factoryContext = _factory.FactoryContext; var states = controllerState.States; var childContexts = ContextControllerStateUtil.GetChildContexts(factoryContext, pathIdToUse, states); var maxSubpathId = int.MinValue; foreach (var entry in childContexts) { var hashAlgoGeneratedId = (int?)_factory.Binding.ByteArrayToObject(entry.Value.Blob, null); // merge filter addendum, if any var filterAddendumToUse = _activationFilterAddendum; if (_factory.HasFiltersSpecsNestedContexts()) { filterAddendumToUse = _activationFilterAddendum != null?_activationFilterAddendum.DeepCopy() : new ContextInternalFilterAddendum(); _factory.PopulateContextInternalFilterAddendums(filterAddendumToUse, hashAlgoGeneratedId); } // check if exists already if (controllerState.IsImported) { var existingHandle = _partitionKeys.Get(hashAlgoGeneratedId.Value); if (existingHandle != null) { _activationCallback.ContextPartitionNavigate(existingHandle, this, controllerState, entry.Value.OptionalContextPartitionId.Value, filterAddendumToUse, agentInstanceSelector, entry.Value.Blob); continue; } } var properties = ContextPropertyEventType.GetHashBean(factoryContext.ContextName, hashAlgoGeneratedId.Value); var assignedSubPathId = !controllerState.IsImported ? entry.Key.SubPath : ++_currentSubpathId; var handle = _activationCallback.ContextPartitionInstantiate(entry.Value.OptionalContextPartitionId, assignedSubPathId, entry.Key.SubPath, this, optionalTriggeringEvent, optionalTriggeringPattern, hashAlgoGeneratedId, properties, controllerState, filterAddendumToUse, factoryContext.IsRecoveringResilient, entry.Value.State); _partitionKeys.Put(hashAlgoGeneratedId.Value, handle); if (entry.Key.SubPath > maxSubpathId) { maxSubpathId = assignedSubPathId; } } if (!controllerState.IsImported) { _currentSubpathId = maxSubpathId != int.MinValue ? maxSubpathId : 0; } }
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); } }
public override void ValidateFactory() { Type[] propertyTypes = ContextControllerPartitionedUtil.ValidateContextDesc(FactoryContext.ContextName, _segmentedSpec); _contextBuiltinProps = ContextPropertyEventType.GetPartitionType(_segmentedSpec, propertyTypes); }
public override void ValidateFactory() { ValidatePopulateContextDesc(); _contextBuiltinProps = ContextPropertyEventType.GetHashType(); }
private void InitializeFromState( EventBean optionalTriggeringEvent, IDictionary <String, Object> optionalTriggeringPattern, ContextInternalFilterAddendum activationFilterAddendum, ContextControllerState controllerState, int pathIdToUse, AgentInstanceSelector agentInstanceSelector, bool loadingExistingState) { 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, loadingExistingState); 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, loadingExistingState || 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; } }
private void InitializeFromState( EventBean optionalTriggeringEvent, IDictionary <String, Object> optionalTriggeringPattern, ContextInternalFilterAddendum filterAddendum, ContextControllerState controllerState, int pathIdToUse, AgentInstanceSelector agentInstanceSelector, bool loadingExistingState) { var factoryContext = _factory.FactoryContext; var states = controllerState.States; // restart if there are states var maxSubpathId = int.MinValue; var childContexts = ContextControllerStateUtil.GetChildContexts(factoryContext, pathIdToUse, states); var eventAdapterService = _factory.FactoryContext.ServicesContext.EventAdapterService; foreach (var entry in childContexts) { var keys = (Object[])_factory.Binding.ByteArrayToObject(entry.Value.Blob, eventAdapterService); var mapKey = GetKeyObjectForLookup(keys); // merge filter addendum, if any var myFilterAddendum = _activationFilterAddendum; if (_factory.HasFiltersSpecsNestedContexts) { filterAddendum = _activationFilterAddendum != null ? _activationFilterAddendum.DeepCopy() : new ContextInternalFilterAddendum(); _factory.PopulateContextInternalFilterAddendums(filterAddendum, mapKey); } // check if exists already if (controllerState.IsImported) { var existingHandle = _partitionKeys.Get(mapKey); if (existingHandle != null) { _activationCallback.ContextPartitionNavigate( existingHandle, this, controllerState, entry.Value.OptionalContextPartitionId.Value, myFilterAddendum, agentInstanceSelector, entry.Value.Blob, loadingExistingState); continue; } } var props = ContextPropertyEventType.GetPartitionBean( factoryContext.ContextName, 0, mapKey, _factory.SegmentedSpec.Items[0].PropertyNames); var assignedSubpathId = !controllerState.IsImported ? entry.Key.SubPath : ++_currentSubpathId; var handle = _activationCallback.ContextPartitionInstantiate( entry.Value.OptionalContextPartitionId, assignedSubpathId, entry.Key.SubPath, this, optionalTriggeringEvent, optionalTriggeringPattern, mapKey, props, controllerState, myFilterAddendum, loadingExistingState || factoryContext.IsRecoveringResilient, entry.Value.State); _partitionKeys.Put(mapKey, handle); if (entry.Key.SubPath > maxSubpathId) { maxSubpathId = assignedSubpathId; } } if (!controllerState.IsImported) { _currentSubpathId = maxSubpathId != int.MinValue ? maxSubpathId : 0; } }