use of it.sauronsoftware.cron4j.Predictor in project scheduling by ow2-proactive.
the class TerminateReplicateTaskHandler method assignReplicationTag.
/**
* 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());
}
Aggregations