本文整理汇总了Java中it.sauronsoftware.cron4j.Predictor类的典型用法代码示例。如果您正苦于以下问题:Java Predictor类的具体用法?Java Predictor怎么用?Java Predictor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Predictor类属于it.sauronsoftware.cron4j包,在下文中一共展示了Predictor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startScheduler
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
public void startScheduler()
{
if (_notifications == null)
{
LOGGER.info("Scheduler without notificator manager: " + _eventManager.getClass().getSimpleName() + " pattern: " + _pattern);
return;
}
final Predictor predictor = new Predictor(_pattern);
final long nextSchedule = predictor.nextMatchingTime();
final long timeSchedule = nextSchedule - System.currentTimeMillis();
if (timeSchedule <= (30 * 1000))
{
LOGGER.warning("Wrong reschedule for " + _eventManager.getClass().getSimpleName() + " end up run in " + (timeSchedule / 1000) + " seconds!");
ThreadPoolManager.getInstance().scheduleEvent(this::startScheduler, timeSchedule + 1000);
return;
}
if (_task != null)
{
_task.cancel(false);
}
_task = ThreadPoolManager.getInstance().scheduleEvent(() ->
{
run();
updateLastRun();
if (isRepeating())
{
ThreadPoolManager.getInstance().scheduleEvent(this::startScheduler, 1000);
}
}, timeSchedule);
}
示例2: assignReplicationTag
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
/**
* Assign a tag to new duplicated task because of a REPLICATE or LOOP.
*
* @param replicatedTask
* the new duplicated task.
* @param initiator
* the initiator of the duplication.
* @param loopAction
* true if the duplication if after a loop or, false if it is a
* replicate.
* @param action
* the duplication action.
*/
private void assignReplicationTag(InternalTask replicatedTask, InternalTask initiator, boolean loopAction,
FlowAction action) {
StringBuilder buf = new StringBuilder();
if (loopAction) {
buf.append("LOOP-");
buf.append(InternalTask.getInitialName(initiator.getName()));
if (initiator.getReplicationIndex() > 0) {
buf.append("*");
buf.append(initiator.getReplicationIndex());
}
} else {
buf.append("REPLICATE-");
buf.append(initiator.getName());
}
buf.append("-");
if (loopAction) {
String cronExpr = action.getCronExpr();
if (cronExpr.isEmpty()) {
buf.append(replicatedTask.getIterationIndex());
} else {
// cron task: the replication index is the next date that
// matches the cron expression
Date resolvedCron = new Predictor(cronExpr).nextMatchingDate();
SimpleDateFormat dt = new SimpleDateFormat("dd_MM_YY_HH_mm");
buf.append(dt.format(resolvedCron));
}
} else {
buf.append(replicatedTask.getReplicationIndex());
}
replicatedTask.setTag(buf.toString());
}
示例3: terminateLoopTask
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
public boolean terminateLoopTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo,
SchedulerStateUpdate frontend) {
// find the target of the loop
InternalTask target = null;
if (action.getTarget().equals(initiator.getName())) {
target = initiator;
} else {
target = internalJob.findTaskUp(action.getTarget(), initiator);
}
boolean replicateForNextLoopIteration = internalJob.replicateForNextLoopIteration(initiator,
target,
changesInfo,
frontend,
action);
if (replicateForNextLoopIteration && action.getCronExpr() != null) {
for (TaskId tid : changesInfo.getNewTasks()) {
InternalTask newTask = internalJob.getIHMTasks().get(tid);
try {
Date startAt = (new Predictor(action.getCronExpr())).nextMatchingDate();
newTask.addGenericInformation(InternalJob.GENERIC_INFO_START_AT_KEY,
ISO8601DateUtil.parse(startAt));
newTask.setScheduledTime(startAt.getTime());
} catch (InvalidPatternException e) {
// this will not happen as the cron expression is
// already being validated in FlowScript class.
LOGGER.debug(e.getMessage());
}
}
}
return replicateForNextLoopIteration;
}
示例4: assignReplicationTag
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
/**
* Assign a tag to new duplicated task because of a REPLICATE or LOOP.
*
* @param replicatedTask
* the new duplicated task.
* @param initiator
* the initiator of the duplication.
* @param loopAction
* true if the duplication if after a loop or, false if it is a
* replicate.
* @param action
* the duplication action.
*/
private void assignReplicationTag(InternalTask replicatedTask, InternalTask initiator, boolean loopAction,
FlowAction action) {
StringBuilder buf = new StringBuilder();
if (loopAction) {
buf.append("LOOP-");
buf.append(InternalTask.getInitialName(initiator.getName()));
if (initiator.getReplicationIndex() > 0) {
buf.append("*");
buf.append(initiator.getReplicationIndex());
}
} else {
buf.append("REPLICATE-");
buf.append(initiator.getName());
}
buf.append("-");
if (loopAction) {
String cronExpr = action.getCronExpr();
if ("".equals(cronExpr)) {
buf.append(replicatedTask.getIterationIndex());
} else {
// cron task: the replication index is the next date that
// matches the cron expression
Date resolvedCron = (new Predictor(cronExpr)).nextMatchingDate();
SimpleDateFormat dt = new SimpleDateFormat("dd_MM_YY_HH_mm");
buf.append(dt.format(resolvedCron));
}
} else {
buf.append(replicatedTask.getReplicationIndex());
}
replicatedTask.setTag(buf.toString());
}
示例5: validate
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
@Override
public String validate(String parameterValue, ModelValidatorContext context) throws ValidationException {
try {
(new Predictor(parameterValue)).nextMatchingDate();
} catch (InvalidPatternException e) {
throw new ValidationException("Expected value should be a valid cron expression, received '" +
parameterValue + "', error: " + e.getMessage(), e);
}
return parameterValue;
}
示例6: getNextScheduledTime
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
public static Date getNextScheduledTime(String cronExp, String timeZone){
Date nextScheduledTime = null;
if (cronExp!=null && SchedulingPattern.validate(cronExp)) {
Predictor predictor = new Predictor(cronExp);
predictor.setTimeZone(TimeZone.getTimeZone(timeZone));
nextScheduledTime = predictor.nextMatchingDate();
}
return nextScheduledTime;
}
示例7: getNextSchedule
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
public long getNextSchedule()
{
final Predictor predictor = new Predictor(_pattern);
return predictor.nextMatchingTime();
}
示例8: next
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
private Instant next(Instant time)
{
Predictor predictor = new Predictor(pattern, Date.from(time));
predictor.setTimeZone(TimeZone.getTimeZone(timeZone));
return Instant.ofEpochMilli(predictor.nextMatchingTime());
}
示例9: logNextRun
import it.sauronsoftware.cron4j.Predictor; //导入依赖的package包/类
private void logNextRun() {
Predictor predictor = new Predictor(cron);
predictor.setTimeZone(timeZone);
log.info("next run: {}", dateFormat.format(predictor.nextMatchingTime()));
}