use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class BatchCluster method taskCancelEvent.
public void taskCancelEvent(TaskCancelEvent event) throws ScyllaRuntimeException {
for (TaskTerminateEvent pee : parentalEndEvents) {
TaskCancelEvent cancelEvent = new TaskCancelEvent(pee.getModel(), pee.getSource(), pee.getSimulationTimeOfSource(), pee.getSimulationComponents(), pee.getProcessInstance(), pee.getNodeId());
cancelEvent.schedule(pee.getProcessInstance());
}
parentalEndEvents.clear();
BatchPluginUtils.getInstance().setClusterToTerminated(getResponsibleProcessInstance(), getBatchActivity().getNodeId());
}
use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class BatchCluster method endEvent.
public void endEvent(BPMNEndEvent event) {
ProcessInstance processInstance = event.getProcessInstance();
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
setProcessInstanceToFinished();
// Schedule them only if either all process instances has passed the last event of the batch activity or the execution type is parallel
if (isFinished()) {
if (pluginInstance.isProcessInstanceCompleted(processInstance)) {
List<TaskTerminateEvent> parentalEndEvents = getParentalEndEvents();
for (TaskTerminateEvent pee : parentalEndEvents) {
pee.schedule();
}
parentalEndEvents.clear();
pluginInstance.setClusterToTerminated(getResponsibleProcessInstance(), getBatchActivity().getNodeId());
}
// Prevent parental task terminate event from scheduling, if there is any (from subprocess plugin)
Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
if (!nextEventMap.isEmpty()) {
// TODO this is currently not covered, when is it called?
Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
int indexOfParentalTaskTerminateEvent = 0;
nextEventMap.remove(indexOfParentalTaskTerminateEvent);
timeSpanToNextEventMap.remove(indexOfParentalTaskTerminateEvent);
}
}
}
use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class SubprocessBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
if (processModel.getParent() != null && processInstanceIsCompleted(processInstance)) {
// works
try {
ProcessSimulationComponents simulationComponents = desmojEvent.getSimulationComponents();
ProcessSimulationComponents parentDesmojObjects = simulationComponents.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
ProcessInstance parentProcessInstance = processInstance.getParent();
// behavior when sub-process sends events:
// none -> back to normal flow
// message -> "send it"
// error -> to parent
// escalation -> to parent
// cancel -> nonono!
// compensation -> ... not now
// signal -> ... not now
// terminate -> terminate sub-process (kill all events of sub-process instance (MI sub-process
// not affected))
// ...
// timer -> special treatment
Set<Integer> idsOfNextNodes = parentModel.getIdsOfNextNodes(nodeIdInParent);
// normal flow: must not have more than one successor
if (idsOfNextNodes.size() != 1) {
int nodeId = desmojEvent.getNodeId();
throw new ScyllaValidationException("Subprocess " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
}
Integer nextNodeId = idsOfNextNodes.iterator().next();
// TODO let the parent create the next node, so remove the lines below
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
// next event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
String parentProcessInstanceName = parentProcessInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
TaskTerminateEvent eventOfParent = pluginInstance.getEventsOnHold().get(parentProcessInstanceName).get(nodeIdInParent);
if (eventOfParent != null) {
events.add(eventOfParent);
pluginInstance.getEventsOnHold().get(parentProcessInstanceName).remove(nodeIdInParent);
pluginInstance.getNameOfEventsThatWereOnHold().add(eventOfParent.getName());
}
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = model.traceIsOn();
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
}
use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class SubprocessTBPlugin method eventRoutine.
@Override
public void eventRoutine(TaskBeginEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
if (subProcess != null) {
int indexOfTaskTerminateEvent = 0;
desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
TaskTerminateEvent event = (TaskTerminateEvent) desmojEvent.getNextEventMap().get(indexOfTaskTerminateEvent);
String name = processInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
Map<Integer, TaskTerminateEvent> eventsOnHoldMap = pluginInstance.getEventsOnHold().get(name);
if (eventsOnHoldMap == null) {
pluginInstance.getEventsOnHold().put(name, new HashMap<Integer, TaskTerminateEvent>());
}
pluginInstance.getEventsOnHold().get(name).put(nodeId, event);
desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
String source = desmojEvent.getSource();
ProcessSimulationComponents simulationComponents = desmojEvent.getSimulationComponents();
SimulationModel model = (SimulationModel) desmojEvent.getModel();
TimeInstant currentSimulationTime = model.presentTime();
boolean showInTrace = model.traceIsOn();
int processInstanceId = processInstance.getId();
try {
ProcessSimulationComponents desmojObjectsOfSubProcess = simulationComponents.getChildren().get(nodeId);
Integer startNodeId = subProcess.getStartNode();
ProcessInstance subProcessInstance = new ProcessInstance(model, subProcess, processInstanceId, showInTrace);
subProcessInstance.setParent(processInstance);
ScyllaEvent subProcessEvent = new BPMNStartEvent(model, source, currentSimulationTime, desmojObjectsOfSubProcess, subProcessInstance, startNodeId);
TimeSpan timeSpan = new TimeSpan(0);
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, subProcessEvent);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
} catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
DebugLogger.error(e.getMessage());
DebugLogger.log("Start node of process model " + subProcess.getId() + " not found.");
throw new ScyllaRuntimeException("Start node of process model " + subProcess.getId() + " not found.");
}
}
}
use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class SubprocessTCPlugin method eventRoutine.
@Override
public void eventRoutine(TaskCancelEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
if (processModel.getParent() != null) {
int nodeIdInParent = processModel.getNodeIdInParent();
ProcessInstance parentProcessInstance = processInstance.getParent();
String parentProcessInstanceName = parentProcessInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
Map<Integer, TaskTerminateEvent> eventsOnHoldMap = pluginInstance.getEventsOnHold().get(parentProcessInstanceName);
TaskTerminateEvent event = eventsOnHoldMap.get(nodeIdInParent);
if (event != null) {
SimulationModel model = (SimulationModel) event.getModel();
String source = event.getSource();
TaskCancelEvent cancelEvent = new TaskCancelEvent(model, source, event.getSimulationTimeOfSource(), event.getSimulationComponents(), event.getProcessInstance(), event.getNodeId());
cancelEvent.schedule(parentProcessInstance, new TimeSpan(0));
eventsOnHoldMap.remove(nodeIdInParent);
}
}
}
Aggregations