use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent in project scylla by bptlab.
the class BatchBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
pluginInstance.logBPMNEventForNonResponsiblePI(event, processInstance);
// Schedule parental end events
ProcessInstance parentProcessInstance = processInstance.getParent();
if (parentProcessInstance != null) {
ProcessModel processModel = processInstance.getProcessModel();
int parentNodeId = processModel.getNodeIdInParent();
BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
if (cluster != null) {
cluster.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 (cluster.areAllProcessInstancesFinished() || cluster.hasExecutionType(BatchClusterExecutionType.PARALLEL)) {
if (pluginInstance.isProcessInstanceCompleted(processInstance)) {
List<TaskTerminateEvent> parentalEndEvents = cluster.getParentalEndEvents();
for (TaskTerminateEvent pee : parentalEndEvents) {
ProcessInstance pi = pee.getProcessInstance();
pee.schedule(pi);
}
parentalEndEvents.clear();
pluginInstance.setClusterToTerminated(parentProcessInstance, parentNodeId);
}
// Prevent parental task terminate event from scheduling, if there is any (from subprocess plugin)
Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
if (!nextEventMap.isEmpty()) {
Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
int indexOfParentalTaskTerminateEvent = 0;
nextEventMap.remove(indexOfParentalTaskTerminateEvent);
timeSpanToNextEventMap.remove(indexOfParentalTaskTerminateEvent);
}
} else if (cluster.hasExecutionType(BatchClusterExecutionType.SEQUENTIAL_CASEBASED)) {
// Schedule the next start event
pluginInstance.scheduleNextCaseInBatchProcess(cluster);
}
}
}
}
use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent 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.ScyllaEvent 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.ScyllaEvent in project scylla by bptlab.
the class BatchTEPlugin method eventRoutine.
@SuppressWarnings("unchecked")
@Override
public void eventRoutine(TaskEnableEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
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();
// 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)) {
// in any case: put taskbeginevent of subprocess container on hold
// String source = desmojEvent.getSource();
int indexOfSubprocessBeginEvent = 0;
Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
// Map<String, TaskBeginEvent> subprocessStartEventsOnHold =
// pluginInstance.getSubprocessStartEventsOnHold();
TaskBeginEvent subprocessBeginEvent = (TaskBeginEvent) nextEventMap.get(indexOfSubprocessBeginEvent);
pluginInstance.assignToBatchCluster(processInstance, nodeId, subprocessBeginEvent);
nextEventMap.remove(indexOfSubprocessBeginEvent);
timeSpanToNextEventMap.remove(indexOfSubprocessBeginEvent);
}
}
use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent in project scylla by bptlab.
the class ExclusiveGatewayEventPlugin method scheduleNextEvent.
private void scheduleNextEvent(GatewayEvent desmojEvent, ProcessInstance processInstance, ProcessModel processModel, Integer nextFlowId) {
Set<Integer> nodeIds = null;
try {
nodeIds = processModel.getTargetObjectIds(nextFlowId);
} catch (NodeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (nodeIds.size() != 1) {
try {
throw new ScyllaValidationException("Flow " + nextFlowId + " does not connect to 1 node, but" + nodeIds.size() + " .");
} catch (ScyllaValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int nextNodeId = nodeIds.iterator().next();
Map<Integer, ScyllaEvent> nextEventMap = desmojEvent.getNextEventMap();
List<Integer> indicesOfEventsToKeep = new ArrayList<Integer>();
for (int index : nextEventMap.keySet()) {
ScyllaEvent eventCandidate = nextEventMap.get(index);
int nodeIdOfCandidate = eventCandidate.getNodeId();
if (nodeIdOfCandidate == nextNodeId) {
indicesOfEventsToKeep.add(index);
break;
}
}
Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
}
Aggregations