Search in sources :

Example 6 with ScyllaRuntimeException

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);
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) Entity(desmoj.core.simulator.Entity) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 7 with ScyllaRuntimeException

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);
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ZonedDateTime(java.time.ZonedDateTime) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant) HashSet(java.util.HashSet)

Example 8 with ScyllaRuntimeException

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;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskType(de.hpi.bpt.scylla.model.process.node.TaskType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 9 with ScyllaRuntimeException

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());
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) TaskType(de.hpi.bpt.scylla.model.process.node.TaskType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 10 with ScyllaRuntimeException

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;
}
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)

Aggregations

ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)24 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)21 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)18 TimeSpan (desmoj.core.simulator.TimeSpan)13 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)10 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)10 TimeInstant (desmoj.core.simulator.TimeInstant)8 HashSet (java.util.HashSet)8 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)7 Map (java.util.Map)7 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)5 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)5 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)4 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)4 TaskType (de.hpi.bpt.scylla.model.process.node.TaskType)4 ArrayList (java.util.ArrayList)4 EventType (de.hpi.bpt.scylla.model.process.node.EventType)3 BPMNIntermediateEvent (de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent)3 HashMap (java.util.HashMap)3 List (java.util.List)3