use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class ProcessSimulationStopEvent method eventRoutine.
@Override
public void eventRoutine() throws SuspendExecution {
SimulationModel model = (SimulationModel) getModel();
Set<Integer> idsOfProcessInstancesToAbort = QueueManager.clearEventQueuesByProcessId(model, processId);
try {
ProcessSimulationStopEventPluggable.runPlugins(this);
// we do not have any submodels
boolean includeSubmodels = false;
List<Entity> entities = model.getEntities(includeSubmodels);
for (Entity entity : entities) {
if (entity instanceof ProcessInstance) {
ProcessInstance processInstance = (ProcessInstance) entity;
if (processInstance.isScheduled() && processId.equals(processInstance.getProcessModel().getId())) {
processInstance.cancel();
idsOfProcessInstancesToAbort.add(processInstance.getId());
}
} else {
DebugLogger.log("Found unsupported DesmoJ entity: " + entity.getName());
}
}
for (Integer id : idsOfProcessInstancesToAbort) {
DebugLogger.log("Abort process instance " + id + " of process " + processId + ".");
}
if (idsOfProcessInstancesToAbort.size() > 0) {
DebugLogger.log("End time of process " + processId + " reached.");
}
if (model.getEndDateTime() != null) {
long currentTime = model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit());
long simulationEndTime = DateTimeUtils.getDuration(model.getStartDateTime(), model.getEndDateTime());
if (simulationEndTime == currentTime) {
model.getExperiment().stop(new TimeInstant(currentTime + 1));
}
}
} catch (ScyllaRuntimeException e) {
throw new RuntimeException(e);
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class ResourceAvailabilityEvent method eventRoutine.
@Override
public void eventRoutine() throws SuspendExecution {
SimulationModel model = (SimulationModel) getModel();
TimeInstant currentSimulationTime = model.presentTime();
Set<String> resourceQueuesUpdated = new HashSet<String>();
String resourceType = resourceObject.getResourceType();
resourceQueuesUpdated.add(resourceType);
try {
ScyllaEvent eventFromQueue = QueueManager.getEventFromQueueReadyForSchedule(model, resourceQueuesUpdated);
while (eventFromQueue != null) {
SimulationUtils.scheduleEvent(eventFromQueue, new TimeSpan(0));
eventFromQueue = QueueManager.getEventFromQueueReadyForSchedule(model, resourceQueuesUpdated);
}
ResourceAvailabilityEventPluggable.runPlugins(this);
// schedule next ResourceAvailableEvent
ZonedDateTime currentDateTime = DateTimeUtils.getDateTime(currentSimulationTime);
boolean currentlyInTimetableItem = true;
SimulationUtils.scheduleNextResourceAvailableEvent(model, resourceObject, currentDateTime, currentlyInTimetableItem);
} catch (ScyllaRuntimeException e) {
throw new RuntimeException(e);
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel 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 de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class TaskBeginEvent method addToLog.
@Override
protected void addToLog(ProcessInstance processInstance) {
long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
String taskName = displayName;
Set<String> resources = new HashSet<String>();
Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
for (ResourceObject res : resourceObjects) {
String resourceName = res.getResourceType() + "_" + res.getId();
resources.add(resourceName);
}
ProcessNodeTransitionType transition = ProcessNodeTransitionType.BEGIN;
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, transition);
model.addNodeInfo(processModel, processInstance, info);
}
use of de.hpi.bpt.scylla.simulation.SimulationModel 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;
}
}
Aggregations