Search in sources :

Example 1 with ProcessSimulationStopEvent

use of de.hpi.bpt.scylla.simulation.event.ProcessSimulationStopEvent in project scylla by bptlab.

the class SimulationModel method doInitialSchedules.

@Override
public void doInitialSchedules() {
    TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
    for (String processId : pSimMap.keySet()) {
        ProcessSimulationComponents desmojObj = pSimMap.get(processId);
        // schedule for end of simulation (if defined), aligned to global start time
        ZonedDateTime endDateOfSimulationConf = desmojObj.getSimulationConfiguration().getEndDateTime();
        Long endTimeRelativeToGlobalStart = Long.MAX_VALUE;
        if (endDateOfSimulationConf != null) {
            endTimeRelativeToGlobalStart = DateTimeUtils.getDuration(startDateTime, endDateOfSimulationConf);
            ProcessSimulationStopEvent endEvent = new ProcessSimulationStopEvent(this, processId, traceIsOn());
            // java.util.Date getTime() returns milliseconds
            endEvent.schedule(new TimeSpan(endTimeRelativeToGlobalStart, timeUnit));
        }
        // schedule for start of simulation, aligned to global start time
        ZonedDateTime startDateOfSimulationConf = desmojObj.getSimulationConfiguration().getStartDateTime();
        long startTimeRelativeToGlobalStart = DateTimeUtils.getDuration(startDateTime, startDateOfSimulationConf);
        ProcessModel processModel = desmojObj.getProcessModel();
        int processInstanceId = desmojObj.incrementProcessInstancesStarted();
        ProcessInstance firstProcessInstance = new ProcessInstance(this, processModel, processInstanceId, traceIsOn());
        ProcessInstanceGenerationEvent startEvent = new ProcessInstanceGenerationEvent(this, processId, endTimeRelativeToGlobalStart, traceIsOn());
        startEvent.schedule(firstProcessInstance, new TimeSpan(startTimeRelativeToGlobalStart, timeUnit));
    }
    if (endDateTime != null) {
        // / java.util.Date getTime() returns milliseconds
        long simulationDuration = DateTimeUtils.getDuration(startDateTime, endDateTime);
        TimeInstant timeInstant = new TimeInstant(simulationDuration, DateTimeUtils.getReferenceTimeUnit());
        for (String processId : pSimMap.keySet()) {
            ProcessSimulationStopEvent abortEvent = new ProcessSimulationStopEvent(this, processId, traceIsOn());
            abortEvent.schedule(timeInstant);
        }
    }
}
Also used : ProcessInstanceGenerationEvent(de.hpi.bpt.scylla.simulation.event.ProcessInstanceGenerationEvent) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessSimulationStopEvent(de.hpi.bpt.scylla.simulation.event.ProcessSimulationStopEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ZonedDateTime(java.time.ZonedDateTime) TimeUnit(java.util.concurrent.TimeUnit) TimeInstant(desmoj.core.simulator.TimeInstant)

Aggregations

ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)1 ProcessInstanceGenerationEvent (de.hpi.bpt.scylla.simulation.event.ProcessInstanceGenerationEvent)1 ProcessSimulationStopEvent (de.hpi.bpt.scylla.simulation.event.ProcessSimulationStopEvent)1 TimeInstant (desmoj.core.simulator.TimeInstant)1 TimeSpan (desmoj.core.simulator.TimeSpan)1 ZonedDateTime (java.time.ZonedDateTime)1 TimeUnit (java.util.concurrent.TimeUnit)1