public void ContextPartitionRecursiveVisit( IntSeqKey controllerPath, int subpathOrAgentInstanceId, ContextController originator, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel) { if (controllerPath.Length != originator.Factory.FactoryEnv.NestingLevel - 1) { throw new IllegalStateException("Unrecognized controller path"); } var nestingLevel = originator.Factory.FactoryEnv.NestingLevel; // starts at 1 for root if (nestingLevel < ContextControllers.Length) { var childController = ContextControllers[nestingLevel]; var subPath = controllerPath.AddToEnd(subpathOrAgentInstanceId); childController.VisitSelectedPartitions( subPath, selectorPerLevel[nestingLevel], visitor, selectorPerLevel); return; } visitor.Add(subpathOrAgentInstanceId, originator.Factory.FactoryEnv.NestingLevel); }
public void VisitSelectedPartitions( ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor) { var nestingLevel = Factory.FactoryContext.NestingLevel; if (contextPartitionSelector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered)contextPartitionSelector; var identifier = new ContextPartitionIdentifierCategory(); foreach (var entry in _handleCategories) { identifier.ContextPartitionId = entry.Value.ContextPartitionOrPathId; var categoryName = _factory.CategorySpec.Items[entry.Key].Name; identifier.Label = categoryName; if (filter.Filter(identifier)) { visitor.Visit(nestingLevel, PathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } if (contextPartitionSelector is ContextPartitionSelectorCategory) { var category = (ContextPartitionSelectorCategory)contextPartitionSelector; if (category.Labels == null || category.Labels.IsEmpty()) { return; } foreach (var entry in _handleCategories) { String categoryName = _factory.CategorySpec.Items[entry.Key].Name; if (category.Labels.Contains(categoryName)) { visitor.Visit(nestingLevel, PathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } if (contextPartitionSelector is ContextPartitionSelectorById) { var byId = (ContextPartitionSelectorById)contextPartitionSelector; foreach (var entry in _handleCategories) { var cpid = entry.Value.ContextPartitionOrPathId; if (byId.ContextPartitionIds.Contains(cpid)) { visitor.Visit(nestingLevel, PathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } if (contextPartitionSelector is ContextPartitionSelectorAll) { foreach (var entry in _handleCategories) { var categoryName = _factory.CategorySpec.Items[entry.Key].Name; visitor.Visit(nestingLevel, PathId, _factory.Binding, entry.Key, this, entry.Value); } return; } throw ContextControllerSelectorUtil.GetInvalidSelector( new Type[] { typeof(ContextPartitionSelectorCategory) }, contextPartitionSelector); }
public override void VisitSelectedPartitions( IntSeqKey path, ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel) { if (contextPartitionSelector is ContextPartitionSelectorCategory) { var category = (ContextPartitionSelectorCategory) contextPartitionSelector; if (category.Labels == null || category.Labels.IsEmpty()) { return; } var ids = CategorySvc.MgmtGetSubpathOrCPIds(path); if (ids != null) { var count = -1; foreach (ContextControllerDetailCategoryItem categoryItem in factory.CategorySpec.Items) { count++; var subpathOrCPID = ids[count]; if (category.Labels.Contains(categoryItem.Name)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPID, this, visitor, selectorPerLevel); } } } return; } if (contextPartitionSelector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered) contextPartitionSelector; var ids = CategorySvc.MgmtGetSubpathOrCPIds(path); if (ids != null) { var count = -1; foreach (ContextControllerDetailCategoryItem categoryItem in factory.CategorySpec.Items) { var identifierCategory = new ContextPartitionIdentifierCategory(categoryItem.Name); count++; if (factory.FactoryEnv.IsLeaf) { identifierCategory.ContextPartitionId = ids[count]; } if (filter.Filter(identifierCategory)) { realization.ContextPartitionRecursiveVisit( path, ids[count], this, visitor, selectorPerLevel); } } } return; } if (contextPartitionSelector is ContextPartitionSelectorAll) { var ids = CategorySvc.MgmtGetSubpathOrCPIds(path); if (ids != null) { foreach (var id in ids) { realization.ContextPartitionRecursiveVisit(path, id, this, visitor, selectorPerLevel); } } return; } if (contextPartitionSelector is ContextPartitionSelectorById) { var byId = (ContextPartitionSelectorById) contextPartitionSelector; var ids = CategorySvc.MgmtGetSubpathOrCPIds(path); foreach (var id in ids) { if (byId.ContextPartitionIds.Contains(id)) { realization.ContextPartitionRecursiveVisit(path, id, this, visitor, selectorPerLevel); } } } throw ContextControllerSelectorUtil.GetInvalidSelector( new[] {typeof(ContextPartitionSelectorCategory)}, contextPartitionSelector); }
public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor) { var nestingLevel = _factory.FactoryContext.NestingLevel; if (contextPartitionSelector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered)contextPartitionSelector; var identifier = new ContextPartitionIdentifierInitiatedTerminated(); foreach (var entry in EndConditions) { identifier.EndTime = entry.Value.EndTime; identifier.StartTime = entry.Value.StartTime; identifier.Properties = entry.Value.StartProperties; identifier.ContextPartitionId = entry.Value.InstanceHandle.ContextPartitionOrPathId; if (filter.Filter(identifier)) { var state = new ContextControllerInitTermState(_factory.FactoryContext.ServicesContext.SchedulingService.Time, entry.Value.StartProperties); visitor.Visit(nestingLevel, _pathId, _factory.Binding, state, this, entry.Value.InstanceHandle); } } return; } if (contextPartitionSelector is ContextPartitionSelectorById) { var filter = (ContextPartitionSelectorById)contextPartitionSelector; foreach (var entry in EndConditions) { if (filter.ContextPartitionIds.Contains(entry.Value.InstanceHandle.ContextPartitionOrPathId)) { var state = new ContextControllerInitTermState(_factory.FactoryContext.ServicesContext.SchedulingService.Time, entry.Value.StartProperties); visitor.Visit(nestingLevel, _pathId, _factory.Binding, state, this, entry.Value.InstanceHandle); } } return; } if (contextPartitionSelector is ContextPartitionSelectorAll) { foreach (var entry in EndConditions) { var state = new ContextControllerInitTermState(_factory.FactoryContext.ServicesContext.SchedulingService.Time, entry.Value.StartProperties); visitor.Visit(nestingLevel, _pathId, _factory.Binding, state, this, entry.Value.InstanceHandle); } return; } throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[0], contextPartitionSelector); }
public abstract void VisitSelectedPartitions( IntSeqKey path, ContextPartitionSelector selector, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel);
public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor) { int nestingLevel = _factory.FactoryContext.NestingLevel; if (contextPartitionSelector is ContextPartitionSelectorHash) { var hash = (ContextPartitionSelectorHash)contextPartitionSelector; if (hash.Hashes == null || hash.Hashes.IsEmpty()) { return; } foreach (int hashCode in hash.Hashes) { var handle = _partitionKeys.Get(hashCode); if (handle != null) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, hashCode, this, handle); } } return; } if (contextPartitionSelector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered)contextPartitionSelector; var identifierHash = new ContextPartitionIdentifierHash(); foreach (var entry in _partitionKeys) { identifierHash.Hash = entry.Key; identifierHash.ContextPartitionId = entry.Value.ContextPartitionOrPathId; if (filter.Filter(identifierHash)) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } if (contextPartitionSelector is ContextPartitionSelectorAll) { foreach (var entry in _partitionKeys) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value); } return; } if (contextPartitionSelector is ContextPartitionSelectorById) { var byId = (ContextPartitionSelectorById)contextPartitionSelector; foreach (var entry in _partitionKeys) { int cpid = entry.Value.ContextPartitionOrPathId; if (byId.ContextPartitionIds.Contains(cpid)) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[] { typeof(ContextPartitionSelectorHash) }, contextPartitionSelector); }
public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor) { var nestingLevel = _factory.FactoryContext.NestingLevel; if (contextPartitionSelector is ContextPartitionSelectorFiltered filtered) { var identifier = new ContextPartitionIdentifierPartitioned(); foreach (var entry in _partitionKeys) { identifier.ContextPartitionId = entry.Value.ContextPartitionOrPathId; var identifierOA = GetKeyObjectsAccountForMultikey(entry.Key); identifier.Keys = identifierOA; if (filtered.Filter(identifier)) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, identifierOA, this, entry.Value); } } return; } else if (contextPartitionSelector is ContextPartitionSelectorSegmented partitioned) { if (partitioned.PartitionKeys?.IsEmpty() != false) { return; } foreach (var keyObjects in partitioned.PartitionKeys) { var key = GetKeyObjectForLookup(keyObjects); var instanceHandle = _partitionKeys.Get(key); if (instanceHandle != null) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, keyObjects, this, instanceHandle); } } return; } else if (contextPartitionSelector is ContextPartitionSelectorById filteredById) { foreach (var entry in _partitionKeys) { if (filteredById.ContextPartitionIds.Contains(entry.Value.ContextPartitionOrPathId)) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, GetKeyObjectsAccountForMultikey(entry.Key), this, entry.Value); } } return; } else if (contextPartitionSelector is ContextPartitionSelectorAll) { foreach (var entry in _partitionKeys) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, GetKeyObjectsAccountForMultikey(entry.Key), this, entry.Value); } return; } throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[] { typeof(ContextPartitionSelectorSegmented) }, contextPartitionSelector); }
public override void VisitSelectedPartitions( IntSeqKey path, ContextPartitionSelector selector, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel) { if (selector is ContextPartitionSelectorSegmented) { var partitioned = (ContextPartitionSelectorSegmented) selector; if (partitioned.PartitionKeys == null || partitioned.PartitionKeys.IsEmpty()) { return; } foreach (var key in partitioned.PartitionKeys) { var keyForLookup = key.Length == 1 ? key[0] : new HashableMultiKey(key); var subpathOrCPId = GetSubpathOrCPId(path, keyForLookup); if (subpathOrCPId != -1) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } } return; } if (selector is ContextPartitionSelectorFiltered) { var filtered = (ContextPartitionSelectorFiltered) selector; var identifier = new ContextPartitionIdentifierPartitioned(); VisitPartitions( path, ( key, subpathOrCPId) => { if (factory.FactoryEnv.IsLeaf) { identifier.ContextPartitionId = subpathOrCPId; } var keys = key is HashableMultiKey ? ((HashableMultiKey) key).Keys : new[] {key}; identifier.Keys = keys; if (filtered.Filter(identifier)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } }); return; } if (selector is ContextPartitionSelectorAll) { VisitPartitions( path, ( key, subpathOrCPId) => realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel)); return; } if (selector is ContextPartitionSelectorById) { var ids = (ContextPartitionSelectorById) selector; VisitPartitions( path, ( key, subpathOrCPId) => { if (ids.ContextPartitionIds.Contains(subpathOrCPId)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } }); } throw ContextControllerSelectorUtil.GetInvalidSelector( new[] {typeof(ContextPartitionSelectorSegmented)}, selector); }
public override void VisitSelectedPartitions( IntSeqKey path, ContextPartitionSelector selector, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel) { if (selector is ContextPartitionSelectorHash) { var selectorHash = (ContextPartitionSelectorHash) selector; if (selectorHash.Hashes == null || selectorHash.Hashes.IsEmpty()) { return; } foreach (var hash in selectorHash.Hashes) { var subpathOrCPId = GetSubpathOrCPId(path, hash); if (subpathOrCPId != -1) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } } return; } if (selector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered) selector; var identifierHash = new ContextPartitionIdentifierHash(); VisitPartitions( path, ( hash, subpathOrCPId) => { identifierHash.Hash = hash; if (factory.FactoryEnv.IsLeaf) { identifierHash.ContextPartitionId = subpathOrCPId; } if (filter.Filter(identifierHash)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } }); return; } if (selector is ContextPartitionSelectorAll) { VisitPartitions( path, ( hash, subpathOrCPId) => realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel)); return; } if (selector is ContextPartitionSelectorById) { var byId = (ContextPartitionSelectorById) selector; VisitPartitions( path, ( hash, subpathOrCPId) => { if (byId.ContextPartitionIds.Contains(subpathOrCPId)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } }); return; } throw ContextControllerSelectorUtil.GetInvalidSelector( new[] {typeof(ContextPartitionSelectorHash)}, selector); }