Search in sources :

Example 1 with Schedule

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);
}
Also used : CommandContext(io.spine.core.CommandContext) Schedule(io.spine.core.CommandContext.Schedule) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 2 with Schedule

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;
}
Also used : Schedule(io.spine.core.CommandContext.Schedule) Duration(com.google.protobuf.Duration)

Example 3 with Schedule

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;
}
Also used : Schedule(io.spine.core.CommandContext.Schedule) Duration(com.google.protobuf.Duration)

Aggregations

Duration (com.google.protobuf.Duration)3 Schedule (io.spine.core.CommandContext.Schedule)3 CommandContext (io.spine.core.CommandContext)1 Test (org.junit.Test)1