TrueTimeEngine constructor
TrueTimeEngine({
- required List<
TimeSource> sources, - MonotonicClock? clock,
- TrueTimeConfig config = const TrueTimeConfig(),
- AnchorStore? store,
- BootEpochProvider epochProvider = const UnknownBootEpochProvider(),
- TimeScheduler? scheduler,
- Random? random,
- bool autoRefresh = true,
- WallClockReader? wallClock,
- Duration diagnosticInterval = const Duration(seconds: 30),
- Duration wallClockJumpThreshold = const Duration(seconds: 2),
- bool foreground = true,
Implementation
TrueTimeEngine({
required List<TimeSource> sources,
MonotonicClock? clock,
this.config = const TrueTimeConfig(),
AnchorStore? store,
this.epochProvider = const UnknownBootEpochProvider(),
TimeScheduler? scheduler,
Random? random,
this.autoRefresh = true,
this.wallClock,
this.diagnosticInterval = const Duration(seconds: 30),
this.wallClockJumpThreshold = const Duration(seconds: 2),
bool foreground = true,
}) : sources = List.unmodifiable(sources),
clock = clock ?? createPlatformClock(),
store = store == null ? null : SerializingAnchorStore.wrap(store),
_scheduler = scheduler ?? TimerScheduler(),
_random = random ?? Random(),
_foreground = foreground,
_pool = _QueryPool(config.maxConcurrentSources) {
config.validate();
if (sources.length > maximumSources) {
throw ArgumentError.value(
sources.length,
'sources',
'At most $maximumSources sources are supported',
);
}
if (diagnosticInterval <= Duration.zero ||
wallClockJumpThreshold <= Duration.zero) {
throw ArgumentError('Diagnostic durations must be positive');
}
final ids = <String>{}, endpoints = <String>{};
for (final source in sources) {
if (source.id.isEmpty ||
source.endpoint.isEmpty ||
source.configurationKey.isEmpty ||
!ids.add(source.id) ||
!endpoints.add(source.endpoint.toLowerCase())) {
throw ArgumentError(
'Source ids, endpoints, and configuration identities must be valid and unique',
);
}
}
}