Example usage for org.joda.time ReadablePeriod toPeriod

List of usage examples for org.joda.time ReadablePeriod toPeriod

Introduction

In this page you can find the example usage for org.joda.time ReadablePeriod toPeriod.

Prototype

Period toPeriod();

Source Link

Document

Get this period as an immutable Period object.

Usage

From source file:azkaban.execapp.TriggerManager.java

License:Apache License

@SuppressWarnings("FutureReturnValueIgnored")
public void addTrigger(final int execId, final List<SlaOption> slaOptions) {
    for (final SlaOption sla : slaOptions) {
        final Condition triggerCond = createCondition(sla, execId, "slaFailChecker", "isSlaFailed()");

        // if whole flow finish before violating sla, just expire the checker
        final Condition expireCond = createCondition(sla, execId, "slaPassChecker", "isSlaPassed()");

        final List<TriggerAction> actions = createActions(sla, execId);
        final Trigger trigger = new Trigger(execId, triggerCond, expireCond, actions);
        final ReadablePeriod duration = Utils
                .parsePeriodString((String) sla.getInfo().get(SlaOption.INFO_DURATION));
        final long durationInMillis = duration.toPeriod().toStandardDuration().getMillis();

        logger.info("Adding sla trigger " + sla.toString() + " to execution " + execId
                + ", scheduled to trigger in " + durationInMillis / 1000 + " seconds");
        this.scheduledService.schedule(trigger, durationInMillis, TimeUnit.MILLISECONDS);
    }//from   w  w  w  .j  ava 2 s.co m
}

From source file:net.cpollet.jixture.fixtures.generator.field.DateSequence.java

License:Apache License

/**
 * Build a sequence that will return values between {@code start} and {@code end} (inclusive) with an increment of
 * {@code increment}. For instance, in:/* w  w  w.j  ava  2s. c  o m*/
 * <pre>
 *     s1 = new DateSequence(
 *        new DateTime(1, 1, 1, 0, 0, 0),
 *        new DateTime(1, 1, 3, 0, 0, 0),
 *        new Period.days(1)
 *     );
 *     s1 = new DateSequence(
 *        new DateTime(1, 1, 1, 0, 0, 0),
 *        new DateTime(1, 1, 5, 0, 0, 0),
 *        new Period.days(1)
 *     );
 * </pre>
 * {@code s1} will generate the following dates: {@code 1-1-1T0:0:0}, {@code 1-1-2T0:0:0}, {@code 1-1-3T0:0:0} and
 * {@code s2} will generate {@code 1-1-1T0:0:0}, {@code 1-1-3T0:0:0}, {@code 1-1-5T0:0:0}.
 *
 * @param start first value in sequence, inclusive.
 * @param stop last element in sequence, inclusive.
 * @param period increment.
 *
 * @throws java.lang.IllegalArgumentException if start is less than stop or if increment is less than or equal to
 * 0ms.
 */
public DateSequence(DateTime start, DateTime stop, ReadablePeriod period) {
    AssertionUtils.assertTrue(period.toPeriod().toStandardDuration().isLongerThan(Duration.ZERO),
            "period must be > 0ms");
    AssertionUtils.assertTrue(!stop.isBefore(start), "stop must be >= start");

    this.start = start;
    this.stop = stop;
    this.period = period;

    reset();
}