use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException 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.exception.ScyllaRuntimeException 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.exception.ScyllaRuntimeException 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;
}
}
use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException 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 de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.
the class SimulationUtils method createEventsForNextNode.
/**
* Gets type of next node and prepare respective event.
*
* @param model
* the simulation model
* @param processModel
* the process model
* @param processInstanceId
* the identifier of the process instance
* @param nextNodeId
* the identifier of the next node
* @return the DesmoJ representing the next node plus DesmoJ events from plug-ins
* @throws ScyllaRuntimeException
* @throws NodeNotFoundException
* @throws ScyllaValidationException
*/
public static List<ScyllaEvent> createEventsForNextNode(ScyllaEvent currentEvent, ProcessSimulationComponents desmojObjects, ProcessInstance processInstance, int nextNodeId) throws ScyllaRuntimeException, NodeNotFoundException, ScyllaValidationException {
SimulationModel model = (SimulationModel) processInstance.getModel();
TimeInstant currentSimulationTime = model.presentTime();
ProcessModel processModel = processInstance.getProcessModel();
String source = currentEvent.getSource();
List<ScyllaEvent> events = new ArrayList<ScyllaEvent>();
if (processModel.getTasks().containsKey(nextNodeId) || processModel.getSubProcesses().containsKey(nextNodeId)) {
// TaskType tType = processModel.getTasks().get(nextNodeId);
ScyllaEvent event = new TaskEnableEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
} else if (processModel.getGateways().containsKey(nextNodeId)) {
GatewayType gType = processModel.getGateways().get(nextNodeId);
Set<Integer> idsOfNodesBeforeGateway = processModel.getIdsOfPreviousNodes(nextNodeId);
if (gType == GatewayType.PARALLEL && idsOfNodesBeforeGateway.size() > 1) {
Map<Integer, Set<Integer>> referenceToEventsOnHold = processInstance.getNodesAndTriggers();
if (!referenceToEventsOnHold.containsKey(nextNodeId)) {
referenceToEventsOnHold.put(nextNodeId, new HashSet<Integer>());
}
Set<Integer> nodesTriggeredFrom = referenceToEventsOnHold.get(nextNodeId);
int currentNodeId = currentEvent.getNodeId();
nodesTriggeredFrom.add(currentNodeId);
if (idsOfNodesBeforeGateway.equals(nodesTriggeredFrom)) {
ScyllaEvent event = new GatewayEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
// clear list of fired incoming flows
referenceToEventsOnHold.remove(nextNodeId);
}
} else {
ScyllaEvent event = new GatewayEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
}
} else if (processModel.getEventTypes().containsKey(nextNodeId)) {
EventType eType = processModel.getEventTypes().get(nextNodeId);
if (eType == EventType.START) {
throw new ScyllaRuntimeException("Start event " + nextNodeId + " must be at the beginning of the process.");
} else if (eType == EventType.END) {
ScyllaEvent event = new BPMNEndEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
} else {
ScyllaEvent event = new BPMNIntermediateEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
}
} else {
throw new ScyllaRuntimeException("Next node " + nextNodeId + " not found or not supported.");
}
List<ScyllaEvent> eventsFromPlugins = EventCreationPluggable.runPlugins(currentEvent, desmojObjects, processInstance, nextNodeId);
events.addAll(eventsFromPlugins);
return events;
}
Aggregations