Search in sources :

Example 6 with ScyllaEvent

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);
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ArrayList(java.util.ArrayList) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) TaskEvent(de.hpi.bpt.scylla.simulation.event.TaskEvent) EventAbstract(desmoj.core.simulator.EventAbstract)

Example 7 with ScyllaEvent

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;
}
Also used : ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) HashSet(java.util.HashSet)

Example 8 with ScyllaEvent

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;
}
Also used : ArrayList(java.util.ArrayList) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Example 9 with ScyllaEvent

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;
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Set(java.util.Set) HashSet(java.util.HashSet) TaskEnableEvent(de.hpi.bpt.scylla.simulation.event.TaskEnableEvent) EventType(de.hpi.bpt.scylla.model.process.node.EventType) ArrayList(java.util.ArrayList) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) BPMNIntermediateEvent(de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) GatewayEvent(de.hpi.bpt.scylla.simulation.event.GatewayEvent) BPMNEndEvent(de.hpi.bpt.scylla.simulation.event.BPMNEndEvent) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant) HashSet(java.util.HashSet)

Example 10 with ScyllaEvent

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);
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)21 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)15 TimeSpan (desmoj.core.simulator.TimeSpan)15 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)7 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)7 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)7 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)6 ArrayList (java.util.ArrayList)6 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)5 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)4 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)4 TimeInstant (desmoj.core.simulator.TimeInstant)4 BPMNStartEvent (de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)2 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)2 TaskBeginEvent (de.hpi.bpt.scylla.simulation.event.TaskBeginEvent)2