Exemple #1
0
        private ContextControllerConditionNonHA ActivateTermination(
            EventBean triggeringEvent,
            object[] parentPartitionKeys,
            object partitionKey,
            IntSeqKey conditionPath,
            string optionalInitCondAsName)
        {
            ContextControllerConditionCallback callback = new ProxyContextControllerConditionCallback(
                (
                    conditionPathArg,
                    originEndpoint,
                    optionalTriggeringEvent,
                    optionalTriggeringPattern,
                    optionalTriggeringEventPattern,
                    optionalPatternForInclusiveEval) => {
                    var parentPath = conditionPathArg.RemoveFromEnd();
                    var getterKey = KeyedFactory.GetGetterKey(partitionKey);
                    var removed = keyedSvc.KeyRemove(parentPath, getterKey);
                    if (removed == null) {
                        return;
                    }

                    // remember the terminating event, we don't want it to initiate a new partition
                    LastTerminatingEvent = optionalTriggeringEvent != null
                        ? optionalTriggeringEvent
                        : optionalTriggeringEventPattern;
                    realization.ContextPartitionTerminate(
                        conditionPath.RemoveFromEnd(),
                        removed.SubpathOrCPId,
                        this,
                        optionalTriggeringPattern, 
                        false,
                        null);
                    removed.TerminationCondition.Deactivate();
                });

            var partitionKeys = CollectionUtil.AddValue(parentPartitionKeys, partitionKey);
            var terminationCondition = ContextControllerConditionFactory.GetEndpoint(
                conditionPath,
                partitionKeys,
                KeyedFactory.keyedSpec.OptionalTermination,
                callback,
                this,
                false);

            ContextControllerEndConditionMatchEventProvider endConditionMatchEventProvider = null;
            if (optionalInitCondAsName != null) {
                endConditionMatchEventProvider = new ProxyContextControllerEndConditionMatchEventProvider(
                    (map, triggeringEventArg) => ContextControllerKeyedUtil.PopulatePriorMatch(optionalInitCondAsName, map, triggeringEventArg),
                    (map, triggeringPattern) => { });
            }

            terminationCondition.Activate(triggeringEvent, endConditionMatchEventProvider, null);

            return terminationCondition;
        }
        private void RangeNotificationEnd(
            IntSeqKey conditionPath,
            ContextControllerConditionNonHA endCondition,
            EventBean optionalTriggeringEvent,
            IDictionary<string, object> optionalTriggeringPattern,
            EventBean optionalTriggeringEventPattern)
        {
            if (endCondition.IsRunning) {
                endCondition.Deactivate();
            }

            var instance = initTermSvc.EndDelete(conditionPath);
            if (instance == null) {
                return;
            }

            // start "@now" we maintain the locks
            var startNow = factory.InitTermSpec.StartCondition is ContextConditionDescriptorImmediate;
            IList<AgentInstance> agentInstancesLocksHeld = null;
            if (startNow) {
                realization.AgentInstanceContextCreate.FilterService.AcquireWriteLock();
                agentInstancesLocksHeld = new List<AgentInstance>(2);
            }

            realization.ContextPartitionTerminate(
                conditionPath.RemoveFromEnd(),
                instance.SubpathIdOrCPId,
                this,
                optionalTriggeringPattern,
                startNow,
                agentInstancesLocksHeld);

            try {
                var controllerPath = conditionPath.RemoveFromEnd();
                var partitionKeys = initTermSvc.MgmtGetParentPartitionKeys(controllerPath);

                var startDesc = factory.initTermSpec.StartCondition;
                var startCondition = ContextControllerConditionFactory.GetEndpoint(
                    controllerPath,
                    partitionKeys,
                    startDesc,
                    this,
                    this,
                    true);
                if (!startCondition.IsImmediate) {
                    startCondition.Activate(optionalTriggeringEvent, null, optionalTriggeringPattern);
                    initTermSvc.MgmtUpdSetStartCondition(controllerPath, startCondition);
                }
                else {
                    // we do not forward triggering events of termination
                    InstantiateAndActivateEndCondition(controllerPath, null, null, null, startCondition);
                }
            }
            finally {
                if (agentInstancesLocksHeld != null) {
                    foreach (var agentInstance in agentInstancesLocksHeld) {
                        agentInstance.AgentInstanceContext.EpStatementAgentInstanceHandle.StatementFilterVersion
                            .StmtFilterVersion = long.MaxValue;
                        if (agentInstance.AgentInstanceContext.StatementContext.EpStatementHandle.HasTableAccess) {
                            agentInstance.AgentInstanceContext.TableExprEvaluatorContext.ReleaseAcquiredLocks();
                        }

                        agentInstance.AgentInstanceContext.AgentInstanceLock.ReleaseWriteLock();
                    }
                }

                if (startNow) {
                    realization.AgentInstanceContextCreate.FilterService.ReleaseWriteLock();
                }
            }
        }