Search in sources :

Example 1 with TimeBasedScheduleInfo

use of org.smartdata.model.rule.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method visitTriCycle.

@Override
public TreeNode visitTriCycle(SmartRuleParser.TriCycleContext ctx) {
    timeBasedScheduleInfo = new TimeBasedScheduleInfo();
    List<TimeintvalexprContext> timeExprs = ctx.timeintvalexpr();
    long[] everys = new long[timeExprs.size() + ((timeExprs.size() + 1) % 2)];
    for (int i = 0; i < timeExprs.size(); i++) {
        everys[i] = getLongConstFromTreeNode(visit(timeExprs.get(i)));
    }
    if (timeExprs.size() % 2 == 0) {
        everys[everys.length - 1] = 5000;
    }
    timeBasedScheduleInfo.setEvery(everys);
    if (ctx.duringexpr() != null) {
        visit(ctx.duringexpr());
    } else {
        timeBasedScheduleInfo.setStartTime(getTimeNow());
        timeBasedScheduleInfo.setEndTime(TimeBasedScheduleInfo.FOR_EVER);
    }
    return null;
}
Also used : TimeintvalexprContext(org.smartdata.rule.parser.SmartRuleParser.TimeintvalexprContext) TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 2 with TimeBasedScheduleInfo

use of org.smartdata.model.rule.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class RuleManager method start.

/**
 * Start services.
 */
@Override
public void start() throws IOException {
    LOG.info("Starting ...");
    // after StateManager be ready
    int numLaunched = 0;
    // Submit runnable rules to scheduler
    for (RuleInfoRepo infoRepo : mapRules.values()) {
        RuleInfo rule = infoRepo.getRuleInfoRef();
        if (rule.getState() == RuleState.ACTIVE || rule.getState() == RuleState.DRYRUN) {
            RuleExecutor ruleExecutor = infoRepo.launchExecutor(this);
            TranslateResult tr = ruleExecutor.getTranslateResult();
            TimeBasedScheduleInfo si = tr.getTbScheduleInfo();
            if (rule.getLastCheckTime() != 0) {
                si.setFirstCheckTime(rule.getLastCheckTime());
            }
            boolean sub = submitRuleToScheduler(ruleExecutor);
            numLaunched += sub ? 1 : 0;
        }
    }
    LOG.info("Started. " + numLaunched + " rules launched for execution.");
}
Also used : RuleInfoRepo(org.smartdata.server.engine.rule.RuleInfoRepo) RuleExecutor(org.smartdata.server.engine.rule.RuleExecutor) TranslateResult(org.smartdata.model.rule.TranslateResult) DetailedRuleInfo(org.smartdata.model.DetailedRuleInfo) RuleInfo(org.smartdata.model.RuleInfo) TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 3 with TimeBasedScheduleInfo

use of org.smartdata.model.rule.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method visitTriTimePoint.

@Override
public TreeNode visitTriTimePoint(SmartRuleParser.TriTimePointContext ctx) {
    timeBasedScheduleInfo = new TimeBasedScheduleInfo();
    TreeNode tr = visit(ctx.timepointexpr());
    try {
        long tm = (Long) (tr.eval().getValue());
        // We set it to -1 and its value will be set after the rule is triggered.
        if (ctx.timepointexpr().getStart().getText().equalsIgnoreCase("now") && ctx.timepointexpr().getStop().getText().equalsIgnoreCase("now")) {
            tm = -1L;
        }
        timeBasedScheduleInfo.setStartTime(tm);
        timeBasedScheduleInfo.setEndTime(tm);
        return null;
    } catch (IOException e) {
        throw new RuleParserException("Evaluate 'AT' expression error");
    }
}
Also used : RuleParserException(org.smartdata.rule.exceptions.RuleParserException) IOException(java.io.IOException) TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 4 with TimeBasedScheduleInfo

use of org.smartdata.model.rule.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method setDefaultTimeBasedScheduleInfo.

private void setDefaultTimeBasedScheduleInfo() {
    if (timeBasedScheduleInfo == null) {
        long intval = 5000;
        if (minTimeInverval != Long.MAX_VALUE) {
            intval = Math.max(intval, minTimeInverval / 20);
        }
        timeBasedScheduleInfo = new TimeBasedScheduleInfo(getTimeNow(), TimeBasedScheduleInfo.FOR_EVER, new long[] { intval });
    }
}
Also used : TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 5 with TimeBasedScheduleInfo

use of org.smartdata.model.rule.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class ExecutorScheduler method addPeriodicityTask.

public void addPeriodicityTask(RuleExecutor re) {
    TimeBasedScheduleInfo si = re.getTranslateResult().getTbScheduleInfo();
    long now = System.currentTimeMillis();
    si.setSubScheduleTime(now);
    if (si.getStartTime() == -1L && si.getEndTime() == -1L) {
        si.setStartTime(now);
        si.setEndTime(now);
    }
    // The start time should not earlier than subSchedule time.
    long startDelay = si.getStartTime() - now;
    if (startDelay < 0) {
        startDelay = 0;
    }
    if (si.getFirstCheckTime() == 0) {
        si.setFirstCheckTime(now + startDelay);
    }
    long every = si.getMinimalEvery();
    if (every <= 0) {
        every = 5000;
    }
    service.scheduleAtFixedRate(re, startDelay, every, TimeUnit.MILLISECONDS);
}
Also used : TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Aggregations

TimeBasedScheduleInfo (org.smartdata.model.rule.TimeBasedScheduleInfo)6 IOException (java.io.IOException)2 RuleInfo (org.smartdata.model.RuleInfo)2 ArrayList (java.util.ArrayList)1 DetailedRuleInfo (org.smartdata.model.DetailedRuleInfo)1 RuleState (org.smartdata.model.RuleState)1 RuleExecutorPlugin (org.smartdata.model.rule.RuleExecutorPlugin)1 TranslateResult (org.smartdata.model.rule.TranslateResult)1 RuleParserException (org.smartdata.rule.exceptions.RuleParserException)1 TimeintvalexprContext (org.smartdata.rule.parser.SmartRuleParser.TimeintvalexprContext)1 RuleExecutor (org.smartdata.server.engine.rule.RuleExecutor)1 RuleInfoRepo (org.smartdata.server.engine.rule.RuleInfoRepo)1