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;
}
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.");
}
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");
}
}
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 });
}
}
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);
}
Aggregations