use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent 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.TaskTerminateEvent in project scylla by bptlab.
the class BatchTCPlugin method eventRoutine.
@Override
public void eventRoutine(TaskCancelEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
pluginInstance.logTaskEventForNonResponsiblePI(event, processInstance);
ProcessInstance parentProcessInstance = processInstance.getParent();
if (parentProcessInstance != null) {
ProcessModel processModel = processInstance.getProcessModel();
int parentNodeId = processModel.getNodeIdInParent();
BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
if (cluster != null) {
List<TaskTerminateEvent> parentalEndEvents = cluster.getParentalEndEvents();
for (TaskTerminateEvent pee : parentalEndEvents) {
TaskCancelEvent cancelEvent = new TaskCancelEvent(pee.getModel(), pee.getSource(), pee.getSimulationTimeOfSource(), pee.getDesmojObjects(), pee.getProcessInstance(), pee.getNodeId());
cancelEvent.schedule(pee.getProcessInstance());
}
parentalEndEvents.clear();
pluginInstance.setClusterToTerminated(parentProcessInstance, parentNodeId);
}
}
}
use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class ParallelBatchCluster method logTaskEventForNonResponsiblePI.
private void logTaskEventForNonResponsiblePI(TaskEvent event) throws ScyllaRuntimeException {
ProcessInstance processInstance = event.getProcessInstance();
ProcessModel processModel = processInstance.getProcessModel();
SimulationModel model = (SimulationModel) event.getModel();
long timestamp = Math.round(model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
String taskName = event.getDisplayName();
int nodeId = event.getNodeId();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
String source = event.getSource();
ProcessNodeTransitionType transition;
if (event instanceof TaskEnableEvent) {
transition = ProcessNodeTransitionType.ENABLE;
} else if (event instanceof TaskBeginEvent) {
transition = ProcessNodeTransitionType.BEGIN;
ResourceObjectTuple commonResources = event.getProcessInstance().getAssignedResources().get(source);
getParentalStartEvents().stream().forEach(each -> each.getProcessInstance().getAssignedResources().put(each.getSource(), commonResources));
} else if (event instanceof TaskCancelEvent) {
transition = ProcessNodeTransitionType.CANCEL;
} else if (event instanceof TaskTerminateEvent) {
transition = ProcessNodeTransitionType.TERMINATE;
} else {
throw new ScyllaRuntimeException("Task event type not supported.");
}
for (TaskBeginEvent beginEvent : getParentalStartEvents()) {
if (!getResponsibleProcessInstance().equals(beginEvent.getProcessInstance())) {
ResourceObjectTuple commonResources = beginEvent.getProcessInstance().getAssignedResources().get(beginEvent.getSource());
Set<String> resourceStrings = commonResources.getResourceObjects().stream().map(res -> res.getResourceType() + "_" + res.getId()).collect(Collectors.toSet());
ProcessNodeInfo info;
info = new ProcessNodeInfo(nodeId, processScopeNodeId, beginEvent.getSource(), timestamp, taskName, resourceStrings, transition);
model.addNodeInfo(processModel, beginEvent.getProcessInstance(), info);
}
}
}
use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.
the class BatchTBPlugin method eventRoutine.
@Override
public void eventRoutine(TaskBeginEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
if (BatchPluginUtils.isBatchActivityEvent(event))
return;
// System.out.println(event + " with display name " + event.getDisplayName() + " || " + event.getNextEventMap() + " and source " + event.getSource());
BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
ProcessSimulationComponents simulationComponents = event.getSimulationComponents();
// SimulationModel model = (SimulationModel) desmojEvent.getModel();
int nodeId = event.getNodeId();
ProcessModel processModel = processInstance.getProcessModel();
BatchCluster cluster = pluginInstance.getCluster(processInstance);
if (cluster == null)
cluster = pluginInstance.getCluster(event);
if (cluster != null) {
ProcessInstance parentProcessInstance = processInstance.getParent();
// If we are the representative (first executed) process instance we add the setUp time for this task
if (parentProcessInstance == cluster.getResponsibleProcessInstance()) {
// therefore we fist take a sample of the setUp distribution
double setUpTimeToAdd = simulationComponents.getSetUpDistributionSample(nodeId);
TimeUnit unit = simulationComponents.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);
}
cluster.taskBeginEvent(event);
}
// SimulationConfiguration simulationConfiguration = desmojObjects.getSimulationConfiguration();
/*Map<Integer, BatchActivity> batchActivities = (Map<Integer, BatchActivity>) simulationConfiguration
.getExtensionValue(getName(), "batchActivities");*/
Map<Integer, BatchActivity> batchActivities = BatchPluginUtils.getBatchActivities(processModel);
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.TaskTerminateEvent in project scylla by bptlab.
the class BatchPluginUtils method setClusterToRunning.
void setClusterToRunning(BatchCluster bc) {
// BatchActivity activity = bc.getBatchActivity();
// String processId = activity.getProcessModel().getId();
// int nodeId = activity.getNodeId();
// List<BatchCluster> clusters= batchClusters.get(processId).get(nodeId);
// // remove from not started
// BatchActivity activity = bc.getBatchActivity();
// String processId = activity.getProcessModel().getId();
// int nodeId = activity.getNodeId();
// batchClustersNotStarted.get(processId).get(nodeId).remove(bc);
//
// // move to running
//
bc.setState(BatchClusterState.RUNNING);
bc.setStartTime(bc.presentTime());
//
// Map<Integer, List<BatchCluster>> batchClustersOfProcess = batchClustersRunning.get(processId);
// if (batchClustersOfProcess == null) {
// batchClustersOfProcess = batchClustersRunning.put(processId, new HashMap<Integer, List<BatchCluster>>());
// List<BatchCluster> clusters = batchClustersOfProcess.get(nodeId);
// if (clusters == null) {
// clusters = batchClustersOfProcess.put(nodeId, new ArrayList<BatchCluster>());
// }
// }
// create parental subprocess end events and put them on hold
List<TaskBeginEvent> parentalStartEvents = bc.getParentalStartEvents();
for (TaskBeginEvent pse : parentalStartEvents) {
TaskTerminateEvent taskTerminateEvent = new TaskTerminateEvent(pse.getModel(), pse.getSource(), pse.getSimulationTimeOfSource(), pse.getSimulationComponents(), pse.getProcessInstance(), pse.getNodeId());
bc.getParentalEndEvents().add(taskTerminateEvent);
}
// parentalStartEvents.clear();
// batchClustersOfProcess.get(nodeId).add(bc);
}
Aggregations