Search in sources :

Example 11 with SimulationModel

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);
    }
}
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 12 with SimulationModel

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);
    }
}
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 13 with SimulationModel

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();
}
Also used : ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) TimeSpan(desmoj.core.simulator.TimeSpan) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 14 with SimulationModel

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);
}
Also used : ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 15 with SimulationModel

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

Aggregations

SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)48 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)41 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)21 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)17 TimeSpan (desmoj.core.simulator.TimeSpan)17 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)15 Map (java.util.Map)15 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)13 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)12 HashSet (java.util.HashSet)12 TimeInstant (desmoj.core.simulator.TimeInstant)11 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)10 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)8 HashMap (java.util.HashMap)8 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)7 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)6 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)6 ResourceObject (de.hpi.bpt.scylla.simulation.ResourceObject)6 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)5 TimeUnit (java.util.concurrent.TimeUnit)5