use of de.hpi.bpt.scylla.simulation.event.BPMNStartEvent in project scylla by bptlab.
the class BatchClusterStartEvent method eventRoutine.
@Override
public void eventRoutine(BatchCluster cluster) throws SuspendExecution {
BatchActivity activity = cluster.getBatchActivity();
int nodeId = activity.getNodeId();
List<TaskBeginEvent> parentalStartEvents = cluster.getParentalStartEvents();
// Schedule all task begin events of the process instance
for (TaskBeginEvent pse : parentalStartEvents) {
ProcessInstance pi = pse.getProcessInstance();
pse.schedule(pi);
}
// schedule subprocess start events for all process instances in parent
// processInstances and parentalStartEvents are ordered the same way
// Set the responsible process instance in the batch cluster, first one by default
cluster.setResponsibleProcessInstance(parentalStartEvents.get(0).getProcessInstance());
// Go through all process instances. If it's the first one, schedule it. If not, save it to be scheduled later on
for (int j = 0; j < parentalStartEvents.size(); j++) {
TaskBeginEvent startEvent = parentalStartEvents.get(j);
ProcessInstance responsibleProcessInstance = startEvent.getProcessInstance();
int processInstanceId = responsibleProcessInstance.getId();
boolean showInTrace = responsibleProcessInstance.traceIsOn();
SimulationModel model = (SimulationModel) responsibleProcessInstance.getModel();
String source = startEvent.getSource();
TimeInstant currentSimulationTime = cluster.presentTime();
ProcessSimulationComponents pSimComponentsOfSubprocess = cluster.getProcessSimulationComponents().getChildren().get(nodeId);
ProcessModel subprocess = pSimComponentsOfSubprocess.getProcessModel();
try {
Integer startNodeId = subprocess.getStartNode();
ProcessInstance subprocessInstance = new ProcessInstance(model, subprocess, processInstanceId, showInTrace);
subprocessInstance.setParent(responsibleProcessInstance);
ScyllaEvent subprocessEvent = new BPMNStartEvent(model, source, currentSimulationTime, pSimComponentsOfSubprocess, subprocessInstance, startNodeId);
System.out.println("Created BPMNStartEvent for PI " + subprocessInstance.getId() + " / " + responsibleProcessInstance.getId() + " in Batch Cluster");
if (j == 0) {
// If it is the first process instance, schedule it...
subprocessEvent.schedule(subprocessInstance);
cluster.setStartNodeId(startNodeId);
} else {
// ...if not, save them for later
cluster.addPIEvent(startNodeId, subprocessEvent, subprocessInstance);
}
} catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
DebugLogger.log("Start node of process model " + subprocess.getId() + " not found.");
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, responsibleProcessInstance, nodeId, traceIsOn());
return;
}
}
// move batch cluster from list of not started ones to running ones
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
pluginInstance.setClusterToRunning(cluster);
// next node and timespan to next event determined by responsible process instance
// tasks resources only assigned to responsible subprocess instance
// only responsible subprocess instance is simulated
// other subprocess instances of batch are covered in process logs
}
use of de.hpi.bpt.scylla.simulation.event.BPMNStartEvent in project scylla by bptlab.
the class BatchTBPlugin method eventRoutine.
@SuppressWarnings("unchecked")
@Override
public void eventRoutine(TaskBeginEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
// System.out.println(event + " with display name " + event.getDisplayName() + " || " + event.getNextEventMap() + " and source " + event.getSource());
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
pluginInstance.logTaskEventForNonResponsiblePI(event, processInstance);
ProcessSimulationComponents desmojObjects = event.getDesmojObjects();
// SimulationModel model = (SimulationModel) desmojEvent.getModel();
int nodeId = event.getNodeId();
ProcessModel processModel = processInstance.getProcessModel();
ProcessInstance parentProcessInstance = processInstance.getParent();
if (parentProcessInstance != null) {
int parentNodeId = processModel.getNodeIdInParent();
BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
// If we are the representative (first executed) process instance we add the setUp time for this task
if (cluster != null && parentProcessInstance == cluster.getResponsibleProcessInstance()) {
// therefore we fist take a sample of the setUp distribution
double setUpTimeToAdd = desmojObjects.getSetUpDistributionSample(nodeId);
TimeUnit unit = desmojObjects.getSetUpDistributionTimeUnit(nodeId);
TimeSpan setUpTimeToAddAsTimeSpan = new TimeSpan(setUpTimeToAdd, unit);
// get the old value (this will always be the entry 0 in our map, because it's always the next)
double standardTime = event.getTimeSpanToNextEventMap().get(0).getTimeAsDouble(TimeUnit.SECONDS);
// and overwrite the time to the next task in the timeSpanToNextEventMap (=set the calculated time as the new time)
TimeSpan timeForTaskWithSetUp = new TimeSpan(standardTime + setUpTimeToAddAsTimeSpan.getTimeAsDouble(TimeUnit.SECONDS), TimeUnit.SECONDS);
event.getTimeSpanToNextEventMap().put(0, timeForTaskWithSetUp);
}
}
// SimulationConfiguration simulationConfiguration = desmojObjects.getSimulationConfiguration();
/*Map<Integer, BatchActivity> batchActivities = (Map<Integer, BatchActivity>) simulationConfiguration
.getExtensionValue(getName(), "batchActivities");*/
Map<Integer, BatchActivity> batchActivities = processModel.getBatchActivities();
if (batchActivities.containsKey(nodeId) && processModel.getSubProcesses().containsKey(nodeId)) {
// subprocess plugin wants to schedule BPMNStartEvents for subprocess
// we prevent it
Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
for (Integer indexOfSubprocessBPMNStartEvent : nextEventMap.keySet()) {
ScyllaEvent eventToSchedule = nextEventMap.get(indexOfSubprocessBPMNStartEvent);
if (eventToSchedule instanceof BPMNStartEvent || eventToSchedule instanceof TaskTerminateEvent) {
nextEventMap.remove(indexOfSubprocessBPMNStartEvent);
timeSpanToNextEventMap.remove(indexOfSubprocessBPMNStartEvent);
break;
}
}
}
}
use of de.hpi.bpt.scylla.simulation.event.BPMNStartEvent 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 desmojObjects = desmojEvent.getDesmojObjects();
SimulationModel model = (SimulationModel) desmojEvent.getModel();
TimeInstant currentSimulationTime = model.presentTime();
boolean showInTrace = model.traceIsOn();
int processInstanceId = processInstance.getId();
try {
ProcessSimulationComponents desmojObjectsOfSubProcess = desmojObjects.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.");
}
}
}
Aggregations