Search in sources :

Example 1 with TimeTask

use of org.yakindu.sct.simulation.core.engine.scheduling.ITimeTaskScheduler.TimeTask in project statecharts by Yakindu.

the class CycleBasedSimulationEngine method scheduleCycleEvent.

private void scheduleCycleEvent() {
    Long cyclePeriod = DEFAULT_CYCLE_PERIOD;
    ArgumentedAnnotation cycleBased = (ArgumentedAnnotation) getStatechart().getAnnotationOfType(CYCLE_BASED_ANNOTATION);
    if (cycleBased != null) {
        cyclePeriod = (Long) statementInterpreter.evaluate(cycleBased.getExpressions().get(0), SRuntimeFactory.eINSTANCE.createExecutionContext());
    }
    TimeTask cycleTask = new TimeTask("$cycle", () -> {
        try {
            interpreter.runCycle();
        } catch (Exception e) {
            handleException(e);
        }
    }, Priority.LOW);
    timeTaskScheduler.scheduleTimeTask(cycleTask, true, cyclePeriod);
}
Also used : ArgumentedAnnotation(org.yakindu.sct.model.stext.stext.ArgumentedAnnotation) TimeTask(org.yakindu.sct.simulation.core.engine.scheduling.ITimeTaskScheduler.TimeTask)

Aggregations

ArgumentedAnnotation (org.yakindu.sct.model.stext.stext.ArgumentedAnnotation)1 TimeTask (org.yakindu.sct.simulation.core.engine.scheduling.ITimeTaskScheduler.TimeTask)1