use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent in project scylla by bptlab.
the class ProcessInstance method cancel.
// public double getTimeRelativeToSubProcessStart() {
// return timeRelativeToSubProcessStart;
// }
//
// public void setTimeRelativeToSubProcessStart(double timeRelativeToSubProcessStart) {
// this.timeRelativeToSubProcessStart = timeRelativeToSubProcessStart;
// }
//
// public Double getEndTimeRelativeToSubProcessStart() {
// return endTimeRelativeToSubProcessStart;
// }
//
// public void setEndTimeRelativeToSubProcessStart(Double endTimeRelativeToSubProcessStart) {
// this.endTimeRelativeToSubProcessStart = endTimeRelativeToSubProcessStart;
// }
@Override
public void cancel() {
try {
Iterator<String> iterator = children.keySet().iterator();
while (iterator.hasNext()) {
String name = iterator.next();
ProcessInstance child = children.get(name);
child.cancel();
}
if (isScheduled()) {
List<EventAbstract> scheduledEvents = getScheduledEvents();
List<ScyllaEvent> rescheduledEvents = new ArrayList<ScyllaEvent>();
for (EventAbstract e : scheduledEvents) {
if (e instanceof TaskEvent) {
TaskEvent event = (TaskEvent) e;
TaskCancelEvent cancelEvent = new TaskCancelEvent(event.getModel(), event.getSource(), event.getSimulationTimeOfSource(), event.getDesmojObjects(), this, event.getNodeId());
rescheduledEvents.add(cancelEvent);
}
}
super.cancel();
for (ScyllaEvent event : rescheduledEvents) {
TimeSpan timeSpan = new TimeSpan(0);
SimulationUtils.scheduleEvent(event, timeSpan);
}
}
if (parent != null) {
parent.removeChild(this);
}
} catch (ScyllaRuntimeException e) {
throw new RuntimeException(e);
}
}
use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent in project scylla by bptlab.
the class QueueManager method clearEventQueuesByProcessId.
/**
* Removes all events which are related to the given process model from the event queues.
*
* @param model
* the simulation model
* @param processId
* the identifier of the process model
* @return identifiers of the process instances which are affected by removing
*/
public static Set<Integer> clearEventQueuesByProcessId(SimulationModel model, String processId) {
Set<Integer> idsOfProcessInstancesToAbort = new HashSet<Integer>();
// remove events of process from queues
Map<String, ScyllaEventQueue> eventQueues = model.getEventQueues();
for (String resourceId : eventQueues.keySet()) {
ScyllaEventQueue queue = eventQueues.get(resourceId);
Iterator<ScyllaEvent> iterator = queue.iterator();
Set<ScyllaEvent> eventsToRemove = new HashSet<ScyllaEvent>();
while (iterator.hasNext()) {
ScyllaEvent queuedEvent = iterator.next();
String eventNameOfQueuedEvent = queuedEvent.getName();
if (eventNameOfQueuedEvent.startsWith(processId)) {
eventsToRemove.add(queuedEvent);
ProcessInstance processInstance = queuedEvent.getProcessInstance();
while (processInstance.getParent() != null) {
// we want the id of the process instance, not of any sub process instance
processInstance = processInstance.getParent();
}
int idOfTopProcessInstance = processInstance.getId();
idsOfProcessInstancesToAbort.add(idOfTopProcessInstance);
}
}
queue.removeAll(eventsToRemove);
}
return idsOfProcessInstancesToAbort;
}
use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent in project scylla by bptlab.
the class ScyllaEventQueue method peek.
/**
* Returns the event at the given index in the queue.
*
* @param index
* the index of event in the queue
* @return the event at the given index in the queue
*/
public ScyllaEvent peek(int index) {
if (index < 0 || index >= size()) {
throw new ArrayIndexOutOfBoundsException(index);
}
ScyllaEvent event = null;
int size = size();
List<ScyllaEvent> events = new ArrayList<ScyllaEvent>();
for (int i = 0; i < size; i++) {
if (i == index) {
event = peek();
break;
}
events.add(poll());
}
addAll(events);
return event;
}
use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent 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;
}
use of de.hpi.bpt.scylla.simulation.event.ScyllaEvent in project scylla by bptlab.
the class BPMNEscalationBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
boolean showInTrace = model.traceIsOn();
try {
for (EventDefinitionType definition : definitions.keySet()) {
if (definition == EventDefinitionType.ESCALATION) {
if (processModel.getParent() != null) {
Map<String, String> eventAttributes = processModel.getEventDefinitions().get(nodeId).get(definition);
String escalationRef = eventAttributes.get("escalationRef");
// Map<String, Map<String, String>> escalations =
// model.getCommonProcessElements().getEscalations();
// Map<String, String> escalation = escalations.get("escalationRef");
ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
Integer nextNodeId = null;
// find boundary event of parentModel which has the same escalationRef
List<Integer> referencesToBoundaryEvents = parentModel.getReferencesToBoundaryEvents().get(nodeIdInParent);
for (int nId : referencesToBoundaryEvents) {
Map<EventDefinitionType, Map<String, String>> boundaryEventDefinitions = parentModel.getEventDefinitions().get(nId);
Map<String, String> boundaryEscalationEventDefinition = boundaryEventDefinitions.get(EventDefinitionType.ESCALATION);
if (boundaryEscalationEventDefinition != null) {
if (escalationRef.equals(boundaryEscalationEventDefinition.get("escalationRef"))) {
nextNodeId = nId;
break;
}
}
}
if (nextNodeId == null) {
DebugLogger.error("Could not find referenced escalation " + escalationRef + ".");
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
ProcessInstance parentProcessInstance = processInstance.getParent();
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
TimeSpan timeSpan = new TimeSpan(0);
/**
* first event in the map is the node that comes after the subprocess when normal behavior
* applies, so remove it;
*/
int indexOfTaskTerminateEvent = 0;
desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
processInstance.cancel();
}
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
Aggregations