Package com.codingchili.core.storage
Class EntryWatcher<Value extends Storable>
java.lang.Object
com.codingchili.core.storage.EntryWatcher<Value>
Periodically executes a reusable query.
May be used as a near-cache.
-
Constructor Summary
ConstructorDescriptionEntryWatcher(AsyncStorage<Value> storage, Supplier<QueryBuilder<Value>> query, TimerSource timer)
Creates a new (paused) entry watcher on the given storage by executing the given query at intervals given by the timer. -
Method Summary
Modifier and TypeMethodDescriptionboolean
isActive()
Returns the state of the watcher.void
pause()
Sets the watcher into a paused state.void
resume()
Sets the watcher into the resumed state.setConsumer(Consumer<Collection<Value>> consumer)
Changes the consumer that receives entries.setQuery(QueryBuilder<Value> query)
Changes the query of the entry watcher.setTimer(TimerSource timer)
Changes the timer source of the entry watcher.start(Consumer<Collection<Value>> consumer)
Starts the entry watcher with the given consumer.
-
Constructor Details
-
EntryWatcher
public EntryWatcher(AsyncStorage<Value> storage, Supplier<QueryBuilder<Value>> query, TimerSource timer)Creates a new (paused) entry watcher on the given storage by executing the given query at intervals given by the timer.- Parameters:
storage
- the storage to watch entries inquery
- the query to be executedtimer
- interval of the query executions
-
-
Method Details
-
setQuery
Changes the query of the entry watcher.- Parameters:
query
- the new query to use- Returns:
- fluent
-
setTimer
Changes the timer source of the entry watcher.- Parameters:
timer
- the new timer source to use- Returns:
- fluent
-
setConsumer
Changes the consumer that receives entries.- Parameters:
consumer
- the new consumer to handle results- Returns:
- fluent
-
start
Starts the entry watcher with the given consumer.- Parameters:
consumer
- the consumer that receives the results of the query.- Returns:
- fluent
-
pause
public void pause()Sets the watcher into a paused state. -
resume
public void resume()Sets the watcher into the resumed state. -
isActive
public boolean isActive()Returns the state of the watcher.- Returns:
- true if the watcher is not paused.
-