Class EntryWatcher<Value extends Storable>

java.lang.Object
com.codingchili.core.storage.EntryWatcher<Value>

public class EntryWatcher<Value extends Storable> extends Object
Periodically executes a reusable query.

May be used as a near-cache.

  • 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 in
      query - the query to be executed
      timer - interval of the query executions
  • Method Details

    • setQuery

      public EntryWatcher<Value> setQuery(QueryBuilder<Value> query)
      Changes the query of the entry watcher.
      Parameters:
      query - the new query to use
      Returns:
      fluent
    • setTimer

      public EntryWatcher<Value> setTimer(TimerSource timer)
      Changes the timer source of the entry watcher.
      Parameters:
      timer - the new timer source to use
      Returns:
      fluent
    • setConsumer

      public EntryWatcher<Value> setConsumer(Consumer<Collection<Value>> consumer)
      Changes the consumer that receives entries.
      Parameters:
      consumer - the new consumer to handle results
      Returns:
      fluent
    • start

      public EntryWatcher<Value> start(Consumer<Collection<Value>> consumer)
      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.