Package tech.ydb.yoj.repository.db.cache
Class DbValueUpdater<V>
java.lang.Object
tech.ydb.yoj.repository.db.cache.DbValueUpdater<V>
Abstract base class for caching rarely updated values, e.g. feature flags.
Each active updater runs a periodic task which retrieves the value and caches it.
Clients should call readCached() to retrieve value cached by an active
updater; implementors should override doReadValue() and choose which super constructor to call.
Lifecycle of ValueUpdater instances should be preferably managed by some external framework, e.g.,
Spring lifecycle. We recommend that you call start() at application start/component test start and
shutdown() at graceful shutdown/component test shutdown.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Durationprotected static final Durationprotected static final Durationprotected static final Durationprotected static final DbValueUpdater.ThreadFactoryCreatorprotected static final org.slf4j.Loggerprotected final Durationprotected final Durationprotected final Stringprotected final Durationprotected final Durationprotected final ThreadFactory -
Constructor Summary
ConstructorsConstructorDescriptionDbValueUpdater(@NonNull String name, @NonNull Duration pollInterval, @NonNull Duration shutdownTimeout, @NonNull Duration maxAge, @NonNull Duration maxReadDuration) DbValueUpdater(@NonNull String name, @NonNull Duration pollInterval, @NonNull Duration shutdownTimeout, @NonNull Duration maxAge, @NonNull Duration maxReadDuration, @NonNull DbValueUpdater.ThreadFactoryCreator threadFactorySupplier) DbValueUpdater(@NonNull Duration pollInterval, @NonNull Duration shutdownTimeout, @NonNull Duration maxAge, @NonNull Duration maxReadDuration) DbValueUpdater(@NonNull Duration pollInterval, @NonNull Duration shutdownTimeout, @NonNull Duration maxAge, @NonNull Duration maxReadDuration, @NonNull Function<DbValueUpdater<V>, String> nameSupplier, @NonNull DbValueUpdater.ThreadFactoryCreator threadFactoryCreator) DbValueUpdater(@NonNull Duration pollInterval, @NonNull Duration shutdownTimeout, @NonNull Duration maxAge, @NonNull Duration maxReadDuration, @NonNull DbValueUpdater.ThreadFactoryCreator threadFactorySupplier) DbValueUpdater(@NonNull ThreadFactory threadFactory) DbValueUpdater(@NonNull DbValueUpdater.ThreadFactoryCreator threadFactorySupplier) -
Method Summary
-
Field Details
-
log
protected static final org.slf4j.Logger log -
DEFAULT_THREAD_FACTORY_CREATOR
-
DEFAULT_CACHE_TIMEOUT
-
DEFAULT_SHUTDOWN_TIMEOUT
-
DEFAULT_MAX_LAG
-
DEFAULT_MAX_READ_DURATION
-
pollInterval
-
shutdownTimeout
-
maxAge
-
maxReadDuration
-
threadFactory
-
name
-
-
Constructor Details
-
DbValueUpdater
public DbValueUpdater() -
DbValueUpdater
-
DbValueUpdater
-
DbValueUpdater
-
DbValueUpdater
-
DbValueUpdater
public DbValueUpdater(@NonNull @NonNull Duration pollInterval, @NonNull @NonNull Duration shutdownTimeout, @NonNull @NonNull Duration maxAge, @NonNull @NonNull Duration maxReadDuration, @NonNull @NonNull DbValueUpdater.ThreadFactoryCreator threadFactorySupplier) -
DbValueUpdater
-
DbValueUpdater
public DbValueUpdater(@NonNull @NonNull Duration pollInterval, @NonNull @NonNull Duration shutdownTimeout, @NonNull @NonNull Duration maxAge, @NonNull @NonNull Duration maxReadDuration, @NonNull @NonNull Function<DbValueUpdater<V>, String> nameSupplier, @NonNull @NonNull DbValueUpdater.ThreadFactoryCreator threadFactoryCreator)
-
-
Method Details
-
doReadValue
- Returns:
- value to cache; must not be
null
-
start
public void start() -
shutdown
public void shutdown() -
isUpdaterActive
public boolean isUpdaterActive()Checks if updater is active- Returns:
- true if updater is active (cachedValue not null), else false
-
readCached
- Returns:
- cached value
- Throws:
IllegalStateException- if value updater is not active
-
forceUpdate
public void forceUpdate()Forces an immediate value update. Will throw if the value cannot be updated.
This method should ONLY be used in tests. -
toString
-
tryReadValue
-