protected internal override PvmExecutionImpl EventNotificationsStarted(PvmExecutionImpl execution)
        {
            execution.IncrementSequenceCounter();

            // hack around execution tree structure not being in sync with activity instance concept:
            // if we end a scope activity, take remembered activity instance from parent and set on
            // execution before calling END listeners.
            var          parent   = execution.Parent;
            IPvmActivity activity = execution.Activity;

            if ((parent != null) && execution.IsScope && (activity != null) && activity.IsScope &&
                (activity.ActivityBehavior is ICompositeActivityBehavior ||
                 (CompensationBehavior.IsCompensationThrowing(execution) &&
                  !LegacyBehavior.IsCompensationThrowing(execution))))
            {
                Log.DebugLeavesActivityInstance(execution, execution.ActivityInstanceId);

                // use remembered activity instance id from parent
                execution.ActivityInstanceId = parent.ActivityInstanceId;
                // make parent go one scope up.
                parent.LeaveActivityInstance();
            }

            return(execution);
        }
Example #2
0
        public virtual void TestVariables()
        {
            var processDefinition =
                new ProcessDefinitionBuilder().CreateActivity("a")
                .Initial()
                .Behavior(new WaitState())
                .EndActivity()
                .BuildProcessDefinition();

            PvmExecutionImpl processInstance = (PvmExecutionImpl)processDefinition.CreateProcessInstance();

            processInstance.SetVariable("amount", 500L);
            processInstance.SetVariable("msg", "hello world");
            processInstance.Start();

            Assert.AreEqual(500L, processInstance.GetVariable("amount"));
            Assert.AreEqual("hello world", processInstance.GetVariable("msg"));

            var activityInstance = processInstance.FindExecution("a");

            Assert.AreEqual(500L, activityInstance.GetVariable("amount"));
            Assert.AreEqual("hello world", activityInstance.GetVariable("msg"));

            IDictionary <string, object> expectedVariables = new Dictionary <string, object>();

            expectedVariables["amount"] = 500L;
            expectedVariables["msg"]    = "hello world";

            //TODO JAVA 行为不一样
            //Assert.AreEqual(expectedVariables, activityInstance.Variables);
            //Assert.AreEqual(expectedVariables, processInstance.Variables);
        }
Example #3
0
        public virtual void execute(PvmExecutionImpl execution)
        {
            execution.activityInstanceDone();

            ActivityBehavior activityBehavior = getActivityBehavior(execution);

            if (activityBehavior is FlowNodeActivityBehavior)
            {
                FlowNodeActivityBehavior behavior = (FlowNodeActivityBehavior)activityBehavior;

                ActivityImpl activity           = execution.getActivity();
                string       activityInstanceId = execution.ActivityInstanceId;
                if (!string.ReferenceEquals(activityInstanceId, null))
                {
                    LOG.debugLeavesActivityInstance(execution, activityInstanceId);
                }

                try
                {
                    behavior.doLeave(execution);
                }
                catch (Exception e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    throw new PvmException("couldn't leave activity <" + activity.getProperty("type") + " id=\"" + activity.Id + "\" ...>: " + e.Message, e);
                }
            }
            else
            {
                throw new PvmException("Behavior of current activity is not an instance of " + typeof(FlowNodeActivityBehavior).Name + ". Execution " + execution);
            }
        }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void notify(org.camunda.bpm.engine.delegate.DelegateExecution execution) throws Exception
        public virtual void notify(DelegateExecution execution)
        {
            PvmExecutionImpl executionImpl = (PvmExecutionImpl)execution;

            LOG.debug("collecting event: " + execution.EventName + " on " + executionImpl.EventSource);
            events.Add(execution.EventName + " on " + executionImpl.EventSource);
        }
Example #5
0
        public virtual void Execute(PvmExecutionImpl execution)
        {
            // Assumption: execution is scope
            var cancellingActivity = execution.NextActivity;

            execution.NextActivity = null;

            // first, cancel and destroy the current scope
            execution.IsActive = true;

            PvmExecutionImpl propagatingExecution = null;

            if (LegacyBehavior.IsConcurrentScope(execution))
            {
                // this is legacy behavior
                LegacyBehavior.CancelConcurrentScope(execution, (IPvmActivity)cancellingActivity.EventScope);
                propagatingExecution = execution;
            }
            else
            {
                // Unlike PvmAtomicOperationTransitionDestroyScope this needs to use delete() (instead of destroy() and remove()).
                // The reason is that PvmAtomicOperationTransitionDestroyScope is executed when a scope (or non scope) is left using
                // a sequence flow. In that case the execution will have completed all the work inside the current activity
                // and will have no more child executions. In PvmAtomicOperationCancelScope the scope is cancelled due to
                // a boundary event firing. In that case the execution has not completed all the work in the current scope / activity
                // and it is necessary to delete the complete hierarchy of executions below and including the execution itself.
                execution.DeleteCascade("Cancel scope activity " + cancellingActivity + " executed.");
                propagatingExecution = (PvmExecutionImpl)execution.Parent;
            }

            propagatingExecution.Activity = (ActivityImpl)(cancellingActivity);
            propagatingExecution.IsActive = true;
            propagatingExecution.IsEnded  = false;
            ActivityCancelled(propagatingExecution);
        }
Example #6
0
        protected internal override IPvmActivity GetInterruptingActivity(PvmExecutionImpl execution)
        {
            var nextActivity = execution.NextActivity;

            execution.NextActivity = null;
            return(nextActivity);
        }
        public virtual void Execute(PvmExecutionImpl execution)
        {
            var executionStartContext = execution.ExecutionStartContext;

            var instantiationStack = executionStartContext.InstantiationStack;
            var activityStack      = instantiationStack.Activities;
            var currentActivity    = activityStack[0];

            activityStack.RemoveAt(0);

            var propagatingExecution = execution;

            if (currentActivity.IsScope)
            {
                propagatingExecution          = (PvmExecutionImpl)execution.CreateExecution();
                execution.IsActive            = false;
                propagatingExecution.Activity = (ActivityImpl)(currentActivity);
                propagatingExecution.Initialize();
            }
            else
            {
                propagatingExecution.Activity = (ActivityImpl)(currentActivity);
            }

            // notify listeners for the instantiated activity
            propagatingExecution.PerformOperation(OperationOnScopeInitialization);
        }
        protected internal override void EventNotificationsCompleted(PvmExecutionImpl execution)
        {
            base.EventNotificationsCompleted(execution);

            var          transition = execution.Transition;
            IPvmActivity destination;

            if (transition == null)
            {
                destination = execution.Activity;
            }
            else
            {
                destination = transition.Destination;
            }
            execution.Transition = (null);
            execution.Activity   = (ActivityImpl)(destination);

            var executionStartContext = execution.ExecutionStartContext;

            if (executionStartContext != null)
            {
                executionStartContext.ExecutionStarted(execution);
                execution.DisposeExecutionStartContext();
            }

            execution.DispatchDelayedEventsAndPerformOperation(PvmAtomicOperationFields.ActivityExecute);
        }
Example #9
0
        public virtual void execute(PvmExecutionImpl execution)
        {
            ExecutionStartContext executionStartContext = execution.ExecutionStartContext;

            InstantiationStack  instantiationStack = executionStartContext.InstantiationStack;
            IList <PvmActivity> activityStack      = instantiationStack.Activities;
            PvmActivity         currentActivity    = activityStack.RemoveAt(0);

            PvmExecutionImpl propagatingExecution = execution;

            if (currentActivity.Scope)
            {
                propagatingExecution = execution.createExecution();
                execution.Active     = false;
                propagatingExecution.setActivity(currentActivity);
                propagatingExecution.initialize();
            }
            else
            {
                propagatingExecution.setActivity(currentActivity);
            }

            // notify listeners for the instantiated activity
            propagatingExecution.performOperation(operationOnScopeInitialization);
        }
Example #10
0
        public virtual void execute(PvmExecutionImpl execution)
        {
            PvmExecutionImpl nextLeaf;

            do
            {
                nextLeaf = findNextLeaf(execution);

                // propagate skipCustomListeners property
                PvmExecutionImpl deleteRoot = getDeleteRoot(execution);
                if (deleteRoot != null)
                {
                    nextLeaf.SkipCustomListeners = deleteRoot.SkipCustomListeners;
                    nextLeaf.SkipIoMappings      = deleteRoot.SkipIoMappings;
                }

                PvmExecutionImpl subProcessInstance = nextLeaf.SubProcessInstance;
                if (subProcessInstance != null)
                {
                    if (deleteRoot.SkipSubprocesses)
                    {
                        subProcessInstance.SuperExecution = null;
                    }
                    else
                    {
                        subProcessInstance.deleteCascade(execution.DeleteReason, nextLeaf.SkipCustomListeners, nextLeaf.SkipIoMappings);
                    }
                }

                nextLeaf.performOperation(PvmAtomicOperation_Fields.DELETE_CASCADE_FIRE_ACTIVITY_END);
            } while (!nextLeaf.DeleteRoot);
        }
Example #11
0
        public static string getParentActivityInstanceId(PvmExecutionImpl execution)
        {
            IDictionary <ScopeImpl, PvmExecutionImpl> activityExecutionMapping = execution.createActivityExecutionMapping();
            PvmExecutionImpl parentScopeExecution = activityExecutionMapping[execution.getActivity().FlowScope];

            return(parentScopeExecution.ParentActivityInstanceId);
        }
Example #12
0
 protected internal override void EventNotificationsCompleted(PvmExecutionImpl execution)
 {
     execution.DispatchDelayedEventsAndPerformOperation((e) => {
         e.LeaveActivityInstance();
         e.PerformOperation(PvmAtomicOperationFields.TransitionDestroyScope);
     });
 }
Example #13
0
        protected internal virtual TransitionInstanceImpl CreateTransitionInstance(PvmExecutionImpl execution)
        {
            TransitionInstanceImpl transitionInstance = new TransitionInstanceImpl();

            // can use execution id as persistent ID for transition as an execution
            // can execute as most one transition at a time.
            transitionInstance.Id = execution.Id;
            transitionInstance.ParentActivityInstanceId = execution.ParentActivityInstanceId;
            transitionInstance.ProcessInstanceId        = execution.ProcessInstanceId;
            transitionInstance.ProcessDefinitionId      = execution.ProcessDefinitionId;
            transitionInstance.ExecutionId = execution.Id;
            transitionInstance.ActivityId  = execution.ActivityId;

            ActivityImpl activity = (ActivityImpl)execution.Activity;

            if (activity != null)
            {
                string name = activity.Name;
                if (string.IsNullOrEmpty(name))
                {
                    name = (string)activity.GetProperty("name");
                }
                transitionInstance.ActivityName = name;
                transitionInstance.ActivityType = (string)activity.GetProperty("type");
            }

            return(transitionInstance);
        }
Example #14
0
        public virtual void HandleIntermediateEvent(EventSubscriptionEntity eventSubscription, object payload,
                                                    CommandContext commandContext)
        {
            PvmExecutionImpl execution = eventSubscription.Execution;
            ActivityImpl     activity  = eventSubscription.Activity;

            EnsureUtil.EnsureNotNull("Error while sending signal for event subscription '" + eventSubscription.Id + "': " + "no activity associated with event subscription", "activity", activity);

            if (payload is IDictionary)
            {
                var processVariables = payload as IDictionary <string, object>;
                execution.Variables = processVariables;
            }

            if (activity == execution.Activity)
            {
                execution.Signal("signal", null);
            }
            else
            {
                // hack around the fact that the start event is refrenced by event subscriptions for event subprocesses
                // and not the subprocess itself
                if (activity.ActivityBehavior is EventSubProcessStartEventActivityBehavior)
                {
                    activity = (ActivityImpl)activity.FlowScope;
                }

                execution.ExecuteEventHandlerActivity(activity);
            }
        }
        public virtual void Execute(PvmExecutionImpl execution)
        {
            // reset activity instance id before creating the scope
            execution.ActivityInstanceId = execution.ParentActivityInstanceId;

            PvmExecutionImpl propagatingExecution = null;
            IPvmActivity     activity             = execution.Activity;

            if (activity != null && activity.IsScope)
            {
                propagatingExecution            = (PvmExecutionImpl)execution.CreateExecution();
                propagatingExecution.Activity   = activity;
                propagatingExecution.Transition = (execution.Transition);
                execution.Transition            = (null);
                execution.IsActive = false;
                execution.Activity = (null);
                Log.CreateScope(execution, propagatingExecution);
                propagatingExecution.Initialize();
            }
            else
            {
                propagatingExecution = execution;
            }


            ScopeCreated(propagatingExecution);
        }
Example #16
0
 public OutgoingExecution(PvmExecutionImpl outgoingExecution, PvmTransition outgoingTransition)
 {
     this.outgoingExecution  = outgoingExecution;
     this.outgoingTransition = outgoingTransition;
     outgoingExecution.setTransition(outgoingTransition);
     outgoingExecution.ActivityInstanceId = null;
 }
        public override void Execute(PvmExecutionImpl execution)
        {
            var scope = GetScope(execution);
            var executionListenerIndex = execution.ListenerIndex;
            var executionListeners     = scope.GetListeners(EventName);

            foreach (var listener in executionListeners)
            {
                execution.EventName   = EventName;
                execution.EventSource = scope;
                //try
                //{
                execution.InvokeListener(listener);
                //}
                //catch (Exception e)
                //{
                //    throw e;
                //}
                //catch (Exception e)
                //{
                //    throw new PvmException("couldn't execute event listener : " + e.Message, e);
                //}
                executionListenerIndex += 1;
                execution.ListenerIndex = executionListenerIndex;
            }
            execution.ListenerIndex = 0;
            execution.EventName     = null;
            execution.EventSource   = null;

            EventNotificationsCompleted(execution);
        }
Example #18
0
 protected internal static void ensureScope(PvmExecutionImpl execution)
 {
     if (!execution.Scope)
     {
         throw new ProcessEngineException("Execution must be scope.");
     }
 }
Example #19
0
        protected internal override void eventNotificationsCompleted(PvmExecutionImpl execution)
        {
            base.eventNotificationsCompleted(execution);

            TransitionImpl transition = execution.getTransition();
            PvmActivity    destination;

            if (transition == null)
            {     // this is null after async cont. -> transition is not stored in execution
                destination = execution.getActivity();
            }
            else
            {
                destination = transition.getDestination();
            }
            execution.setTransition(null);
            execution.setActivity(destination);

            ExecutionStartContext executionStartContext = execution.ExecutionStartContext;

            if (executionStartContext != null)
            {
                executionStartContext.executionStarted(execution);
                execution.disposeExecutionStartContext();
            }

            execution.dispatchDelayedEventsAndPerformOperation(PvmAtomicOperation_Fields.ACTIVITY_EXECUTE);
        }
Example #20
0
        public virtual void handleIntermediateEvent(EventSubscriptionEntity eventSubscription, object payload, object localPayload, CommandContext commandContext)
        {
            PvmExecutionImpl execution = eventSubscription.Execution;
            ActivityImpl     activity  = eventSubscription.Activity;

            ensureNotNull("Error while sending signal for event subscription '" + eventSubscription.Id + "': " + "no activity associated with event subscription", "activity", activity);

            if (payload is System.Collections.IDictionary)
            {
                execution.Variables = (IDictionary <string, object>)payload;
            }

            if (localPayload is System.Collections.IDictionary)
            {
                execution.VariablesLocal = (IDictionary <string, object>)localPayload;
            }

            if (activity.Equals(execution.getActivity()))
            {
                execution.signal("signal", null);
            }
            else
            {
                // hack around the fact that the start event is referenced by event subscriptions for event subprocesses
                // and not the subprocess itself
                if (activity.ActivityBehavior is EventSubProcessStartEventActivityBehavior)
                {
                    activity = (ActivityImpl)activity.FlowScope;
                }

                execution.executeEventHandlerActivity(activity);
            }
        }
Example #21
0
 protected internal static void ensureConcurrent(PvmExecutionImpl execution)
 {
     if (!execution.Concurrent)
     {
         throw new ProcessEngineException("Execution must be concurrent.");
     }
 }
Example #22
0
        public virtual void execute(PvmExecutionImpl execution)
        {
            // reset activity instance id before creating the scope
            execution.ActivityInstanceId = execution.ParentActivityInstanceId;

            PvmExecutionImpl propagatingExecution = null;
            PvmActivity      activity             = execution.getActivity();

            if (activity.Scope)
            {
                propagatingExecution = execution.createExecution();
                propagatingExecution.setActivity(activity);
                propagatingExecution.setTransition(execution.getTransition());
                execution.setTransition(null);
                execution.Active = false;
                execution.setActivity(null);
                LOG.createScope(execution, propagatingExecution);
                propagatingExecution.initialize();
            }
            else
            {
                propagatingExecution = execution;
            }


            scopeCreated(propagatingExecution);
        }
        protected internal virtual bool CanHaveChildScopes(PvmExecutionImpl execution)
        {
            IPvmActivity activity = execution.Activity;

            return(activity.ActivityBehavior is ICompositeActivityBehavior ||
                   CompensationBehavior.IsCompensationThrowing(execution));
        }
Example #24
0
        public override void execute(PvmExecutionImpl execution)
        {
            ScopeImpl scope = getScope(execution);
            int       executionListenerIndex = execution.ListenerIndex;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<org.camunda.bpm.engine.delegate.DelegateListener<? extends org.camunda.bpm.engine.delegate.BaseDelegateExecution>> executionListeners = scope.getListeners(getEventName());
            IList <DelegateListener <BaseDelegateExecution> > executionListeners = scope.getListeners(EventName);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (org.camunda.bpm.engine.delegate.DelegateListener<? extends org.camunda.bpm.engine.delegate.BaseDelegateExecution> listener : executionListeners)
            foreach (DelegateListener <BaseDelegateExecution> listener in executionListeners)
            {
                execution.EventName   = EventName;
                execution.EventSource = scope;
                try
                {
                    execution.invokeListener(listener);
                }
                catch (Exception e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    throw new PvmException("couldn't execute event listener : " + e.Message, e);
                }
                executionListenerIndex += 1;
                execution.ListenerIndex = executionListenerIndex;
            }
            execution.ListenerIndex = 0;
            execution.EventName     = null;
            execution.EventSource   = null;

            eventNotificationsCompleted(execution);
        }
Example #25
0
        public static string GetParentActivityInstanceId(PvmExecutionImpl execution)
        {
            var activityExecutionMapping = execution.CreateActivityExecutionMapping();
            var parentScopeExecution     = activityExecutionMapping[execution.Activity.FlowScope];

            return(parentScopeExecution.ParentActivityInstanceId);
        }
        protected internal override PvmExecutionImpl EventNotificationsStarted(PvmExecutionImpl execution)
        {
            execution.IncrementSequenceCounter();
            execution.ActivityInstanceStarting();
            execution.EnterActivityInstance();

            return(execution);
        }
Example #27
0
 protected internal virtual PvmExecutionImpl findNextLeaf(PvmExecutionImpl execution)
 {
     if (execution.hasChildren())
     {
         return(findNextLeaf(execution.Executions[0]));
     }
     return(execution);
 }
Example #28
0
 protected internal static bool IsMultiInstanceInCompensation(IPvmActivity activity,
                                                              PvmExecutionImpl scopeExecutionCandidate)
 {
     return(activity.ActivityBehavior is MultiInstanceActivityBehavior &&
            (((scopeExecutionCandidate != null) &&
              (FindCompensationThrowingAncestorExecution(scopeExecutionCandidate) != null)) ||
             (scopeExecutionCandidate == null)));
 }
Example #29
0
        protected internal static bool WasNoScope73(IPvmActivity activity, PvmExecutionImpl scopeExecutionCandidate)
        {
            var activityBehavior = (IActivityBehavior)activity.ActivityBehavior;

            return(activityBehavior is CompensationEventActivityBehavior ||
                   activityBehavior is CancelEndEventActivityBehavior ||
                   IsMultiInstanceInCompensation(activity, scopeExecutionCandidate));
        }
Example #30
0
        public virtual void execute(PvmExecutionImpl execution)
        {
            execution.activityInstanceStarted();

            execution.continueIfExecutionDoesNotAffectNextOperation(new CallbackAnonymousInnerClass(this, execution)
                                                                    , new CallbackAnonymousInnerClass2(this, execution)
                                                                    , execution);
        }