/** * Create a duration with the specified number of milliseconds. * * @param millis the number of standard milliseconds in this duration * @return the duration, never null * @since 2.0 */ public static Duration millis(long millis) { if (millis == 0) { return ZERO; } return new Duration(millis); }
public DurationWithMillis(long ms) { this.base = new org.joda.time.Duration(ms); }
/** * Create a duration with the specified number of milliseconds. * * @param millis the number of standard milliseconds in this duration * @return the duration, never null * @since 2.0 */ public static Duration millis(long millis) { if (millis == 0) { return ZERO; } return new Duration(millis); }
/** * Creates a new Duration instance with a different millisecond length. * * @param duration the new length of the duration * @return the new duration instance */ public Duration withMillis(long duration) { if (duration == getMillis()) { return this; } return new Duration(duration); }
/** * Creates a new Duration instance with a different millisecond length. * * @param duration the new length of the duration * @return the new duration instance */ public Duration withMillis(long duration) { if (duration == getMillis()) { return this; } return new Duration(duration); }
/** * Returns a new duration with this length negated. * This instance is immutable and is not altered. * * @return the new duration instance */ public Duration negated() { if (getMillis() == Long.MIN_VALUE) { throw new ArithmeticException("Negation of this duration would overflow"); } return new Duration(-getMillis()); }
/** * Returns a new duration with this length negated. * This instance is immutable and is not altered. * * @return the new duration instance */ public Duration negated() { if (getMillis() == Long.MIN_VALUE) { throw new ArithmeticException("Negation of this duration would overflow"); } return new Duration(-getMillis()); }
public Duration getAndIncrementRetryDelay() { if (hasExceededRetryThreshold()) { return null; } Duration retVal = currRetryDelay; currRetryDelay = new Duration(Math.min(currRetryDelay.getMillis() * 2, maxRetryDelay.getMillis())); ++retryCount; return retVal; }
@Config("druid.coordinator.load.timeout") public Duration getLoadTimeoutDelay() { return new Duration(15 * 60 * 1000); }
/** * Parses a {@code Duration} from the specified string. * <p> * This parses the format {@code PTa.bS}, as per {@link #toString()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static Duration parse(String str) { return new Duration(str); }
/** * Get this duration as an immutable <code>Duration</code> object. * * @return a Duration created using the millisecond duration from this instance */ public Duration toDuration() { return new Duration(getMillis()); }
public RunDuration getDuration() { if (!state.completed()) { return RunDuration.IN_PROGRESS_DURATION; } Date start = new Date(createdTime.getTime()); Date end = new Date(lastTransitionedTime.getTime()); return new RunDuration.ActualDuration(new Duration(end.getTime() - start.getTime())); }
/** * Get this duration as an immutable <code>Duration</code> object. * * @return a Duration created using the millisecond duration from this instance */ public Duration toDuration() { return new Duration(getMillis()); }
/** * Parses a {@code Duration} from the specified string. * <p> * This parses the format {@code PTa.bS}, as per {@link #toString()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static Duration parse(String str) { return new Duration(str); }
public RunDuration getDuration() { if (!isCompleted()) { return RunDuration.IN_PROGRESS_DURATION; } Date scheduleStartTime = getStartedDateFor(JobState.Scheduled); Date completedTime = getCompletedDate(); return new RunDuration.ActualDuration(new Duration(completedTime.getTime() - scheduleStartTime.getTime())); }
private boolean hasTaskPendingBeyondThreshold(Collection<? extends TaskRunnerWorkItem> pendingTasks) { long now = System.currentTimeMillis(); for (TaskRunnerWorkItem pendingTask : pendingTasks) { final Duration durationSinceInsertion = new Duration(pendingTask.getQueueInsertionTime().getMillis(), now); final Duration timeoutDuration = config.getPendingTaskTimeout().toStandardDuration(); if (durationSinceInsertion.isEqual(timeoutDuration) || durationSinceInsertion.isLongerThan(timeoutDuration)) { return true; } } return false; }
@Override public Duration getDuration() { if (duration == null) { Duration totalDuration = new Duration(0); for (Interval interval : querySegmentSpec.getIntervals()) { if (interval != null) { totalDuration = totalDuration.plus(interval.toDuration()); } } duration = totalDuration; } return duration; }
@Test public void shouldReturnJobDurationForACompletedJob() { int fiveSeconds = 5000; JobInstance instance = JobInstanceMother.passed("first", new Date(), fiveSeconds); assertThat(instance.getDuration(), is(new RunDuration.ActualDuration(new Duration(5 * fiveSeconds)))); }
public static class TaskNotRunnableException extends RuntimeException { public TaskNotRunnableException(String message) { super(message); } }
@Test public void testMakeRetryPolicy() { RetryPolicyConfig config = new RetryPolicyConfig() .setMinWait(new Period("PT1S")) .setMaxWait(new Period("PT10S")) .setMaxRetryCount(1); RetryPolicyFactory retryPolicyFactory = new RetryPolicyFactory(config); RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy(); Assert.assertEquals(new Duration("PT1S"), retryPolicy.getAndIncrementRetryDelay()); Assert.assertTrue(retryPolicy.hasExceededRetryThreshold()); } }