use of io.spine.core.CommandContext.Schedule in project core-java by SpineEventEngine.
the class GivenCommandContextShould method create_with_scheduled_delay.
@Test
public void create_with_scheduled_delay() {
final Duration delay = Durations2.fromHours(42);
final Schedule expectedSchedule = Schedule.newBuilder().setDelay(delay).build();
final CommandContext context = GivenCommandContext.withScheduledDelayOf(delay);
checkValid(context);
final Schedule actualSchedule = context.getSchedule();
assertEquals(expectedSchedule, actualSchedule);
}
use of io.spine.core.CommandContext.Schedule 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 io.spine.core.CommandContext.Schedule 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