use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class ThrowSignalEventActivityBehavior method execute.
@Override
public void execute(ActivityExecution execution) throws Exception {
String businessKey = signalDefinition.getEventPayload().getBusinessKey(execution);
VariableMap variableMap = signalDefinition.getEventPayload().getInputVariables(execution);
String eventName = signalDefinition.resolveExpressionOfEventName(execution);
// trigger all event subscriptions for the signal (start and intermediate)
List<EventSubscriptionEntity> signalEventSubscriptions = findSignalEventSubscriptions(eventName, execution.getTenantId());
for (EventSubscriptionEntity signalEventSubscription : signalEventSubscriptions) {
if (isActiveEventSubscription(signalEventSubscription)) {
signalEventSubscription.eventReceived(variableMap, businessKey, signalDefinition.isAsync());
}
}
leave(execution);
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class CompensationUtil method createEventScopeExecution.
/**
* creates an event scope for the given execution:
*
* create a new event scope execution under the parent of the given execution
* and move all event subscriptions to that execution.
*
* this allows us to "remember" the event subscriptions after finishing a
* scope
*/
public static void createEventScopeExecution(ExecutionEntity execution) {
// parent execution is a subprocess or a miBody
ActivityImpl activity = execution.getActivity();
ExecutionEntity scopeExecution = (ExecutionEntity) execution.findExecutionForFlowScope(activity.getFlowScope());
List<EventSubscriptionEntity> eventSubscriptions = execution.getCompensateEventSubscriptions();
if (eventSubscriptions.size() > 0 || hasCompensationEventSubprocess(activity)) {
ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
eventScopeExecution.setActivity(execution.getActivity());
eventScopeExecution.activityInstanceStarting();
eventScopeExecution.enterActivityInstance();
eventScopeExecution.setActive(false);
eventScopeExecution.setConcurrent(false);
eventScopeExecution.setEventScope(true);
// copy local variables to eventScopeExecution by value. This way,
// the eventScopeExecution references a 'snapshot' of the local variables
Map<String, Object> variables = execution.getVariablesLocal();
for (Entry<String, Object> variable : variables.entrySet()) {
eventScopeExecution.setVariableLocal(variable.getKey(), variable.getValue());
}
// set event subscriptions to the event scope execution:
for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
EventSubscriptionEntity newSubscription = EventSubscriptionEntity.createAndInsert(eventScopeExecution, EventType.COMPENSATE, eventSubscriptionEntity.getActivity());
newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
// use the original date
newSubscription.setCreated(eventSubscriptionEntity.getCreated());
}
// (ensuring they don't get removed when 'execution' gets removed)
for (PvmExecutionImpl childEventScopeExecution : execution.getEventScopeExecutions()) {
childEventScopeExecution.setParent(eventScopeExecution);
}
ActivityImpl compensationHandler = getEventScopeCompensationHandler(execution);
EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(scopeExecution, EventType.COMPENSATE, compensationHandler);
eventSubscription.setConfiguration(eventScopeExecution.getId());
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class CompensationUtil method throwCompensationEvent.
/**
* we create a separate execution for each compensation handler invocation.
*/
public static void throwCompensationEvent(List<EventSubscriptionEntity> eventSubscriptions, ActivityExecution execution, boolean async) {
// first spawn the compensating executions
for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
// check whether compensating execution is already created
// (which is the case when compensating an embedded subprocess,
// where the compensating execution is created when leaving the subprocess
// and holds snapshot data).
ExecutionEntity compensatingExecution = getCompensatingExecution(eventSubscription);
if (compensatingExecution != null) {
if (compensatingExecution.getParent() != execution) {
// move the compensating execution under this execution if this is not the case yet
compensatingExecution.setParent((PvmExecutionImpl) execution);
}
compensatingExecution.setEventScope(false);
} else {
compensatingExecution = (ExecutionEntity) execution.createExecution();
eventSubscription.setConfiguration(compensatingExecution.getId());
}
compensatingExecution.setConcurrent(true);
}
// signal compensation events in REVERSE order of their 'created' timestamp
Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {
@Override
public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
return o2.getCreated().compareTo(o1.getCreated());
}
});
for (EventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
compensateEventSubscriptionEntity.eventReceived(null, async);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class CompensationUtil method collectCompensateEventSubscriptionsForActivity.
/**
* Collect all compensate event subscriptions for activity on the scope of
* given execution.
*/
public static List<EventSubscriptionEntity> collectCompensateEventSubscriptionsForActivity(ActivityExecution execution, String activityRef) {
final List<EventSubscriptionEntity> eventSubscriptions = collectCompensateEventSubscriptionsForScope(execution);
final String subscriptionActivityId = getSubscriptionActivityId(execution, activityRef);
List<EventSubscriptionEntity> eventSubscriptionsForActivity = new ArrayList<EventSubscriptionEntity>();
for (EventSubscriptionEntity subscription : eventSubscriptions) {
if (subscriptionActivityId.equals(subscription.getActivityId())) {
eventSubscriptionsForActivity.add(subscription);
}
}
return eventSubscriptionsForActivity;
}
use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.
the class EventSubscriptionDeclaration method createSubscriptionForStartEvent.
public EventSubscriptionEntity createSubscriptionForStartEvent(ProcessDefinitionEntity processDefinition) {
EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(eventType);
VariableScope scopeForExpression = StartProcessVariableScope.getSharedInstance();
String eventName = resolveExpressionOfEventName(scopeForExpression);
eventSubscriptionEntity.setEventName(eventName);
eventSubscriptionEntity.setActivityId(activityId);
eventSubscriptionEntity.setConfiguration(processDefinition.getId());
eventSubscriptionEntity.setTenantId(processDefinition.getTenantId());
return eventSubscriptionEntity;
}
Aggregations