public virtual void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext) { IExecutionEntity execution = eventSubscription.Execution; FlowNode currentFlowElement = (FlowNode)execution.CurrentFlowElement; if (currentFlowElement == null) { throw new ActivitiException("Error while sending signal for event subscription '" + eventSubscription.Id + "': " + "no activity associated with event subscription"); } if (payload is System.Collections.IDictionary) { IDictionary <string, object> processVariables = (IDictionary <string, object>)payload; execution.Variables = processVariables; } if (currentFlowElement is BoundaryEvent || currentFlowElement is EventSubProcess) { try { DispatchActivitiesCanceledIfNeeded(eventSubscription, execution, currentFlowElement, commandContext); } catch (Exception e) { throw new ActivitiException("exception while sending signal for event subscription '" + eventSubscription + "':" + e.Message, e); } } Context.Agenda.PlanTriggerExecutionOperation(execution); }
protected internal virtual void DispatchExecutionCancelled(IEventSubscriptionEntity eventSubscription, IExecutionEntity execution, ICommandContext commandContext) { // subprocesses foreach (IExecutionEntity subExecution in execution.Executions) { DispatchExecutionCancelled(eventSubscription, subExecution, commandContext); } // call activities IExecutionEntity subProcessInstance = commandContext.ExecutionEntityManager.FindSubProcessInstanceBySuperExecutionId(execution.Id); if (subProcessInstance != null) { DispatchExecutionCancelled(eventSubscription, subProcessInstance, commandContext); } // activity with message/signal boundary events FlowElement flowElement = execution.CurrentFlowElement; if (flowElement is BoundaryEvent boundaryEvent) { if (boundaryEvent.AttachedToRef != null) { DispatchActivityCancelled(eventSubscription, execution, boundaryEvent.AttachedToRef, commandContext); } } }
protected internal virtual void DispatchActivitiesCanceledIfNeeded(IEventSubscriptionEntity eventSubscription, IExecutionEntity execution, FlowElement currentFlowElement, ICommandContext commandContext) { if (currentFlowElement is BoundaryEvent boundaryEvent) { if (boundaryEvent.CancelActivity) { DispatchExecutionCancelled(eventSubscription, execution, commandContext); } } }
public override void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext) { // As stated in the ActivitiEventType java-doc, the message-event is // thrown before the actual message has been sent if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled) { commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateMessageEvent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, eventSubscription.ActivityId, eventSubscription.EventName, payload, eventSubscription.ExecutionId, eventSubscription.ProcessInstanceId, eventSubscription.Execution.ProcessDefinitionId)); } base.HandleEvent(eventSubscription, payload, commandContext); }
public virtual void Execute(IJobEntity job, string configuration, IExecutionEntity execution, ICommandContext commandContext) { IEventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.EventSubscriptionEntityManager; // lookup subscription: IEventSubscriptionEntity eventSubscriptionEntity = eventSubscriptionEntityManager.FindById <IEventSubscriptionEntity>(new KeyValuePair <string, object>("id", configuration)); // if event subscription is null, ignore if (eventSubscriptionEntity != null) { eventSubscriptionEntityManager.EventReceived(eventSubscriptionEntity, null, false); } }
protected internal virtual void DispatchActivityCancelled(IEventSubscriptionEntity eventSubscription, IExecutionEntity boundaryEventExecution, FlowNode flowNode, ICommandContext commandContext) { // Scope commandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityCancelledEvent(flowNode.Id, flowNode.Name, boundaryEventExecution.Id, boundaryEventExecution.ProcessInstanceId, boundaryEventExecution.ProcessDefinitionId, ParseActivityType(flowNode), eventSubscription)); if (flowNode is SubProcess) { // The parent of the boundary event execution will be the one on which the boundary event is set IExecutionEntity parentExecutionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(boundaryEventExecution.ParentId); if (parentExecutionEntity != null) { DispatchActivityCancelledForChildExecution(eventSubscription, parentExecutionEntity, boundaryEventExecution, commandContext); } } }
public virtual void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext) { string configuration = eventSubscription.Configuration; if (configuration is null) { throw new ActivitiException("Compensating execution not set for compensate event subscription with id " + eventSubscription.Id); } IExecutionEntity compensatingExecution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(configuration); string processDefinitionId = compensatingExecution.ProcessDefinitionId; Process process = ProcessDefinitionUtil.GetProcess(processDefinitionId); if (process == null) { throw new ActivitiException("Cannot start process instance. Process model (id = " + processDefinitionId + ") could not be found"); } FlowElement flowElement = process.GetFlowElement(eventSubscription.ActivityId, true); if (flowElement is SubProcess && !((SubProcess)flowElement).ForCompensation) { // descend into scope: compensatingExecution.IsScope = true; IList <ICompensateEventSubscriptionEntity> eventsForThisScope = commandContext.EventSubscriptionEntityManager.FindCompensateEventSubscriptionsByExecutionId(compensatingExecution.Id); ScopeUtil.ThrowCompensationEvent(eventsForThisScope, compensatingExecution, false); } else { try { if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled) { commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityEvent(ActivitiEventType.ACTIVITY_COMPENSATE, flowElement.Id, flowElement.Name, compensatingExecution.Id, compensatingExecution.ProcessInstanceId, compensatingExecution.ProcessDefinitionId, flowElement)); } compensatingExecution.CurrentFlowElement = flowElement; Context.Agenda.PlanContinueProcessInCompensation(compensatingExecution); } catch (Exception e) { throw new ActivitiException("Error while handling compensation event " + eventSubscription, e); } } }
protected internal virtual void DispatchActivityCancelledForChildExecution(IEventSubscriptionEntity eventSubscription, IExecutionEntity parentExecutionEntity, IExecutionEntity boundaryEventExecution, ICommandContext commandContext) { IList <IExecutionEntity> executionEntities = commandContext.ExecutionEntityManager.FindChildExecutionsByParentExecutionId(parentExecutionEntity.Id); foreach (IExecutionEntity childExecution in executionEntities) { if (!boundaryEventExecution.Id.Equals(childExecution.Id) && childExecution.CurrentFlowElement != null && childExecution.CurrentFlowElement is FlowNode) { FlowNode flowNode = (FlowNode)childExecution.CurrentFlowElement; commandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityCancelledEvent(flowNode.Id, flowNode.Name, childExecution.Id, childExecution.ProcessInstanceId, childExecution.ProcessDefinitionId, ParseActivityType(flowNode), eventSubscription)); if (childExecution.IsScope) { DispatchActivityCancelledForChildExecution(eventSubscription, childExecution, boundaryEventExecution, commandContext); } } } }
public override void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext) { if (eventSubscription.ExecutionId is object) { base.HandleEvent(eventSubscription, payload, commandContext); } else if (eventSubscription.ProcessDefinitionId is object) { // Find initial flow element matching the signal start event string processDefinitionId = eventSubscription.ProcessDefinitionId; IProcessDefinition processDefinition = ProcessDefinitionUtil.GetProcessDefinition(processDefinitionId); if (processDefinition == null) { throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", typeof(IProcessDefinition)); } if (processDefinition.Suspended) { throw new ActivitiException("Could not handle signal: process definition with id: " + processDefinitionId + " is suspended"); } Process process = ProcessDefinitionUtil.GetProcess(processDefinitionId); FlowElement flowElement = process.GetFlowElement(eventSubscription.ActivityId, true); if (flowElement == null) { throw new ActivitiException("Could not find matching FlowElement for activityId " + eventSubscription.ActivityId); } // Start process instance via that flow element IDictionary <string, object> variables = null; if (payload is System.Collections.IDictionary) { variables = (IDictionary <string, object>)payload; } ProcessInstanceHelper processInstanceHelper = commandContext.ProcessEngineConfiguration.ProcessInstanceHelper; processInstanceHelper.CreateAndStartProcessInstanceWithInitialFlowElement(processDefinition, null, null, flowElement, process, variables, null, true); } else { throw new ActivitiException("Invalid signal handling: no execution nor process definition set"); } }
protected internal override object Execute(ICommandContext commandContext, IExecutionEntity execution) { if (messageName is null) { throw new ActivitiIllegalArgumentException("messageName cannot be null"); } IEventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.EventSubscriptionEntityManager; IList <IEventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.FindEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, executionId); if (eventSubscriptions.Count == 0) { throw new ActivitiException("Execution with id '" + executionId + "' does not have a subscription to a message event with name '" + messageName + "'"); } // there can be only one: IEventSubscriptionEntity eventSubscriptionEntity = eventSubscriptions[0]; eventSubscriptionEntityManager.EventReceived(eventSubscriptionEntity, payload, async); return(null); }
public override void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext) { if (!(eventSubscription.ExecutionId is null)) { base.HandleEvent(eventSubscription, payload, commandContext); }