Class SchedulerClock
- java.lang.Object
-
- java.time.Clock
-
- com.couchbase.client.core.scheduler.SchedulerClock
-
public class SchedulerClock extends Clock
Clock adapter aroundScheduler
. That adoption gives better integration with Java 8 DateTime API.This feature may be useful for testing purpose, especially for integration with
VirtualTimeScheduler
. For example:VirtualTimeScheduler scheduler = VirtualTimeScheduler.create(); SchedulerClock clock = SchedulerClock.of(scheduler); ZonedDateTime beforeAdvance = ZonedDateTime.now(clock); scheduler.advanceTimeBy(Duration.ofSeconds(1)); ZonedDateTime afterAdvance = ZonedDateTime.now(clock); Assert.assertTrue(beforeAdvance.isBefore(afterAdvance));
- Since:
- 3.1.4
- Author:
- Oleh Dokuka, Peter Royal
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Scheduler
getScheduler()
Return wrapped Scheduler instanceZoneId
getZone()
int
hashCode()
Instant
instant()
Gets the current instant of the clock.long
millis()
static SchedulerClock
of(Scheduler scheduler)
static SchedulerClock
of(Scheduler scheduler, ZoneId zoneId)
String
toString()
SchedulerClock
withScheduler(Scheduler scheduler)
Builder method that returns new instance ofSchedulerClock
which is constructed from oldZoneId
and passedScheduler
instanceSchedulerClock
withZone(ZoneId zone)
-
Methods inherited from class java.time.Clock
fixed, offset, system, systemDefaultZone, systemUTC, tick, tickMillis, tickMinutes, tickSeconds
-
-
-
-
Method Detail
-
withZone
@NonNull public SchedulerClock withZone(ZoneId zone)
-
getScheduler
@NonNull public Scheduler getScheduler()
Return wrapped Scheduler instance- Returns:
Scheduler
instance
-
withScheduler
@NonNull public SchedulerClock withScheduler(Scheduler scheduler)
Builder method that returns new instance ofSchedulerClock
which is constructed from oldZoneId
and passedScheduler
instance- Returns:
SchedulerClock
instance
-
instant
@NonNull public Instant instant()
Gets the current instant of the clock.This returns an instant representing the current instant as defined by the clock.
Note: If scheduler does not support time in nanoseconds the returned
Instant
will be limited by milliseconds
-
of
@NonNull public static SchedulerClock of(@NonNull Scheduler scheduler)
- Parameters:
scheduler
-Scheduler
instance- Returns:
- new
SchedulerClock
-
of
@NonNull public static SchedulerClock of(@NonNull Scheduler scheduler, @NonNull ZoneId zoneId)
- Parameters:
scheduler
-Scheduler
instance- Returns:
- new
SchedulerClock
-
-