use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.
the class TaskCancelEvent method eventRoutine.
@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
super.eventRoutine(processInstance);
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
try {
ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
TaskType type = processModel.getTasks().get(nodeId);
String message = null;
if (subProcess != null) {
message = "Cancel Subprocess: " + displayName;
} else if (type == TaskType.DEFAULT) {
message = "Cancel Default Task: " + displayName;
} else if (type == TaskType.SERVICE) {
message = "Cancel Service Task: " + displayName;
} else if (type == TaskType.SEND) {
message = "Cancel Send Task: " + displayName;
} else if (type == TaskType.RECEIVE) {
message = "Cancel Receive Task: " + displayName;
} else if (type == TaskType.USER) {
message = "Cancel User Task: " + displayName;
} else if (type == TaskType.MANUAL) {
message = "Cancel Manual Task: " + displayName;
} else if (type == TaskType.BUSINESS_RULE) {
message = "Cancel Business Rule: " + displayName;
} else if (type == TaskType.SCRIPT) {
message = "Cancel Script Task: " + displayName;
} else {
// TODO write to log because element not supported
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
sendTraceNote(message);
TaskCancelEventPluggable.runPlugins(this, processInstance);
// 1: check queues if there are any events waiting, schedule them
QueueManager.releaseResourcesAndScheduleQueuedEvents(model, this);
// by default: cancel -> do not schedule any next event
scheduleNextEvents();
} catch (ScyllaRuntimeException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
}
use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.
the class TaskTerminateEvent method eventRoutine.
@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
super.eventRoutine(processInstance);
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
try {
ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
TaskType type = processModel.getTasks().get(nodeId);
String message = null;
if (subProcess != null) {
message = "End of Subprocess: " + displayName;
} else if (type == TaskType.DEFAULT) {
message = "End of Default Task: " + displayName;
} else if (type == TaskType.SERVICE) {
message = "End of Service Task: " + displayName;
} else if (type == TaskType.SEND) {
message = "End of Send Task: " + displayName;
} else if (type == TaskType.RECEIVE) {
message = "End of Receive Task: " + displayName;
} else if (type == TaskType.USER) {
message = "End of User Task: " + displayName;
} else if (type == TaskType.MANUAL) {
message = "End of Manual Task: " + displayName;
} else if (type == TaskType.BUSINESS_RULE) {
message = "End of Business Rule: " + displayName;
} else if (type == TaskType.SCRIPT) {
message = "End of Script Task: " + displayName;
} else {
// TODO write to log because element not supported
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
sendTraceNote(message);
// 1: check queues if there are any events waiting, schedule them first
// 2: schedule event for next node
QueueManager.releaseResourcesAndScheduleQueuedEvents(model, this);
// get next node(s)
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
// start event must not have more than successor
if (idsOfNextNodes.size() != 1) {
throw new ScyllaValidationException("Task " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
}
Integer nextNodeId = idsOfNextNodes.iterator().next();
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
// next event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
for (ScyllaEvent event : events) {
int index = getNewEventIndex();
nextEventMap.put(index, event);
timeSpanToNextEventMap.put(index, timeSpan);
}
// unless current one is BPMN timer event with timerDuration
TaskTerminateEventPluggable.runPlugins(this, processInstance);
scheduleNextEvents();
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
}
}
use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.
the class SimulationUtils method abort.
/**
* Aborts the simulation of the given process instance.
*
* @param model
* the simulation model
* @param processModel
* the process model
* @param processInstanceId
* the identifier of the process instance
* @param nodeId
* identifier of node at which the simulation is aborted (for logging purposes)
* @param showInTrace
* true if DesmoJ trace logging is enabled
*/
public static void abort(Model model, ProcessInstance processInstance, int nodeId, boolean showInTrace) {
ProcessModel processModel = processInstance.getProcessModel();
int processInstanceId = processInstance.getId();
String name = ScyllaEvent.buildEventName(processModel, processInstanceId, nodeId);
name += "_Exception";
ExternalEventStop abortEvent = new ExternalEventStop(model, name, showInTrace);
abortEvent.schedule();
}
use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.
the class SimulationUtils method createEventsForNextNode.
/**
* Gets type of next node and prepare respective event.
*
* @param model
* the simulation model
* @param processModel
* the process model
* @param processInstanceId
* the identifier of the process instance
* @param nextNodeId
* the identifier of the next node
* @return the DesmoJ representing the next node plus DesmoJ events from plug-ins
* @throws ScyllaRuntimeException
* @throws NodeNotFoundException
* @throws ScyllaValidationException
*/
public static List<ScyllaEvent> createEventsForNextNode(ScyllaEvent currentEvent, ProcessSimulationComponents desmojObjects, ProcessInstance processInstance, int nextNodeId) throws ScyllaRuntimeException, NodeNotFoundException, ScyllaValidationException {
SimulationModel model = (SimulationModel) processInstance.getModel();
TimeInstant currentSimulationTime = model.presentTime();
ProcessModel processModel = processInstance.getProcessModel();
String source = currentEvent.getSource();
List<ScyllaEvent> events = new ArrayList<ScyllaEvent>();
if (processModel.getTasks().containsKey(nextNodeId) || processModel.getSubProcesses().containsKey(nextNodeId)) {
// TaskType tType = processModel.getTasks().get(nextNodeId);
ScyllaEvent event = new TaskEnableEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
} else if (processModel.getGateways().containsKey(nextNodeId)) {
GatewayType gType = processModel.getGateways().get(nextNodeId);
Set<Integer> idsOfNodesBeforeGateway = processModel.getIdsOfPreviousNodes(nextNodeId);
if (gType == GatewayType.PARALLEL && idsOfNodesBeforeGateway.size() > 1) {
Map<Integer, Set<Integer>> referenceToEventsOnHold = processInstance.getNodesAndTriggers();
if (!referenceToEventsOnHold.containsKey(nextNodeId)) {
referenceToEventsOnHold.put(nextNodeId, new HashSet<Integer>());
}
Set<Integer> nodesTriggeredFrom = referenceToEventsOnHold.get(nextNodeId);
int currentNodeId = currentEvent.getNodeId();
nodesTriggeredFrom.add(currentNodeId);
if (idsOfNodesBeforeGateway.equals(nodesTriggeredFrom)) {
ScyllaEvent event = new GatewayEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
// clear list of fired incoming flows
referenceToEventsOnHold.remove(nextNodeId);
}
} else {
ScyllaEvent event = new GatewayEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
}
} else if (processModel.getEventTypes().containsKey(nextNodeId)) {
EventType eType = processModel.getEventTypes().get(nextNodeId);
if (eType == EventType.START) {
throw new ScyllaRuntimeException("Start event " + nextNodeId + " must be at the beginning of the process.");
} else if (eType == EventType.END) {
ScyllaEvent event = new BPMNEndEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
} else {
ScyllaEvent event = new BPMNIntermediateEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
}
} else {
throw new ScyllaRuntimeException("Next node " + nextNodeId + " not found or not supported.");
}
List<ScyllaEvent> eventsFromPlugins = EventCreationPluggable.runPlugins(currentEvent, desmojObjects, processInstance, nextNodeId);
events.addAll(eventsFromPlugins);
return events;
}
use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.
the class SimulationUtils method getProcessScopeNodeId.
/**
* Builds a identifier of a node which is unique across all levels of a BPMN process.
*
* @param processModel
* the (sub-)process model
* @param nodeId
* the identifier of the node
* @return the identifier which is unique across all levels of the BPMN process
*/
public static String getProcessScopeNodeId(ProcessModel processModel, Integer nodeId) {
String processScopeNodeId = nodeId.toString();
ProcessModel parent = processModel.getParent();
while (parent != null) {
Integer nodeIdInParent = processModel.getNodeIdInParent();
processScopeNodeId = nodeIdInParent + "_" + processScopeNodeId;
parent = parent.getParent();
}
return processScopeNodeId;
}
Aggregations