use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.
the class ScyllaEvent method scheduleNextEvents.
public void scheduleNextEvents() throws ScyllaRuntimeException, SuspendExecution {
for (int i : nextEventMap.keySet()) {
ScyllaEvent nextEvent = nextEventMap.get(i);
SimulationModel model = (SimulationModel) nextEvent.getModel();
TimeSpan timeSpanToNextEvent = timeSpanToNextEventMap.get(i);
// if this is known as canceld don't schedule outgoing Elements of this
boolean alreadyCanceled = false;
Collection<Map<Integer, List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
for (ProcessNodeInfo task : currentProcess) {
if (task.getId().equals(nodeId) && task.getTransition().equals(ProcessNodeTransitionType.CANCEL)) {
alreadyCanceled = true;
}
}
}
if (!alreadyCanceled) {
SimulationUtils.scheduleEvent(nextEvent, timeSpanToNextEvent);
}
}
// to make sure that one will not schedule events twice
nextEventMap.clear();
timeSpanToNextEventMap.clear();
}
use of desmoj.core.simulator.TimeSpan 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 desmoj.core.simulator.TimeSpan in project scylla by bptlab.
the class BPMNEscalationBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
boolean showInTrace = model.traceIsOn();
try {
for (EventDefinitionType definition : definitions.keySet()) {
if (definition == EventDefinitionType.ESCALATION) {
if (processModel.getParent() != null) {
Map<String, String> eventAttributes = processModel.getEventDefinitions().get(nodeId).get(definition);
String escalationRef = eventAttributes.get("escalationRef");
// Map<String, Map<String, String>> escalations =
// model.getCommonProcessElements().getEscalations();
// Map<String, String> escalation = escalations.get("escalationRef");
ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
Integer nextNodeId = null;
// find boundary event of parentModel which has the same escalationRef
List<Integer> referencesToBoundaryEvents = parentModel.getReferencesToBoundaryEvents().get(nodeIdInParent);
for (int nId : referencesToBoundaryEvents) {
Map<EventDefinitionType, Map<String, String>> boundaryEventDefinitions = parentModel.getEventDefinitions().get(nId);
Map<String, String> boundaryEscalationEventDefinition = boundaryEventDefinitions.get(EventDefinitionType.ESCALATION);
if (boundaryEscalationEventDefinition != null) {
if (escalationRef.equals(boundaryEscalationEventDefinition.get("escalationRef"))) {
nextNodeId = nId;
break;
}
}
}
if (nextNodeId == null) {
DebugLogger.error("Could not find referenced escalation " + escalationRef + ".");
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
ProcessInstance parentProcessInstance = processInstance.getParent();
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
TimeSpan timeSpan = new TimeSpan(0);
/**
* first event in the map is the node that comes after the subprocess when normal behavior
* applies, so remove it;
*/
int indexOfTaskTerminateEvent = 0;
desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
processInstance.cancel();
}
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.
the class BPMNTimerBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
Map<Integer, ScyllaEvent> nextEvents = desmojEvent.getNextEventMap();
for (int index : nextEvents.keySet()) {
ScyllaEvent event = nextEvents.get(index);
int nextNodeId = event.getNodeId();
TimeSpan timeSpan = BPMNTimerPluginUtils.getTimeSpanUntilNextEvent(processModel, nextNodeId);
if (timeSpan != null) {
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
}
}
use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.
the class BPMNTimerBPMNEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNIntermediateEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
Map<Integer, ScyllaEvent> nextEvents = desmojEvent.getNextEventMap();
for (int index : nextEvents.keySet()) {
ScyllaEvent event = nextEvents.get(index);
int nextNodeId = event.getNodeId();
TimeSpan timeSpan = BPMNTimerPluginUtils.getTimeSpanUntilNextEvent(processModel, nextNodeId);
if (timeSpan != null) {
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
}
}
Aggregations