use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class OperatorEvaluatorShould method compare_timestamps_by_GT.
@Test
public void compare_timestamps_by_GT() {
final Duration delta = seconds(5);
final Timestamp small = getCurrentTime();
final Timestamp medium = add(small, delta);
final Timestamp big = add(medium, delta);
assertTrue(eval(medium, GREATER_THAN, small));
assertTrue(eval(big, GREATER_THAN, medium));
assertTrue(eval(big, GREATER_THAN, small));
assertFalse(eval(small, GREATER_THAN, small));
assertFalse(eval(small, GREATER_THAN, big));
assertFalse(eval(nullRef(), GREATER_THAN, small));
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class CommandScheduler method setSchedulingTime.
/**
* Sets a new scheduling time in the {@linkplain CommandContext.Schedule context}
* of the passed command.
*
* @param command a command to update
* @param schedulingTime the time when the command was scheduled by the {@code CommandScheduler}
* @return an updated command
*/
static Command setSchedulingTime(Command command, Timestamp schedulingTime) {
checkNotNull(command);
checkNotNull(schedulingTime);
final Duration delay = command.getContext().getSchedule().getDelay();
final Command result = setSchedule(command, delay, schedulingTime);
return result;
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class ExecutorCommandScheduler method getDelayMilliseconds.
private static long getDelayMilliseconds(Command command) {
final Schedule schedule = command.getContext().getSchedule();
final Duration delay = schedule.getDelay();
final long delaySec = delay.getSeconds();
final long delayMillisFraction = delay.getNanos() / NANOS_IN_MILLISECOND;
/**
* Maximum value of {@link Duration#getSeconds()} is
* <a href="https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto"+315,576,000,000.</a>.
*
* {@link Long.MAX_VALUE} is +9,223,372,036,854,775,807. That's why it is safe to multiply
* {@code delaySec * MILLIS_IN_SECOND}.
*/
final long absoluteMillis = delaySec * MILLIS_IN_SECOND + delayMillisFraction;
return absoluteMillis;
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class Rescheduler method reschedule.
private void reschedule(Command command) {
final Timestamp now = getCurrentTime();
final Timestamp timeToPost = getTimeToPost(command);
if (isLaterThan(now, /*than*/
timeToPost)) {
onScheduledCommandExpired(command);
} else {
final Interval interval = Intervals.between(now, timeToPost);
final Duration newDelay = Intervals.toDuration(interval);
final Command updatedCommand = CommandScheduler.setSchedule(command, newDelay, now);
scheduler().schedule(updatedCommand);
}
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class Commands method isScheduled.
/**
* Checks if the command is scheduled to be delivered later.
*
* @param command a command to check
* @return {@code true} if the command context has a scheduling option set,
* {@code false} otherwise
*/
public static boolean isScheduled(Command command) {
checkNotNull(command);
final Schedule schedule = command.getContext().getSchedule();
final Duration delay = schedule.getDelay();
if (isNotDefault(delay)) {
checkArgument(delay.getSeconds() > 0, "Command delay seconds must be a positive value.");
return true;
}
return false;
}
Aggregations