Search in sources :

Example 6 with Predictor

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());
}
Also used : Predictor(it.sauronsoftware.cron4j.Predictor) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Predictor (it.sauronsoftware.cron4j.Predictor)6 Date (java.util.Date)3 InvalidPatternException (it.sauronsoftware.cron4j.InvalidPatternException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 SchedulingPattern (it.sauronsoftware.cron4j.SchedulingPattern)1 Timestamp (java.sql.Timestamp)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)1 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)1 ScriptResult (org.ow2.proactive.scripting.ScriptResult)1