Class BaseUpdateGraph

All Implemented Interfaces:
LogOutputAppendable, NotificationQueue, NotificationQueue.Dependency, UpdateGraph, UpdateSourceRegistrar
Direct Known Subclasses:
EventDrivenUpdateGraph, PeriodicUpdateGraph

public abstract class BaseUpdateGraph extends Object implements UpdateGraph, LogOutputAppendable
The BaseUpdateGraph contains common code for other UpdateGraph implementations and a map of named UpdateGraph instances.
  • Field Details


      public static final String DEFAULT_UPDATE_GRAPH_NAME
      See Also:

      public static final String MINIMUM_CYCLE_DURATION_TO_LOG_MILLIS_PROP
      See Also:

    • accumulatedCycleStats

      public final BaseUpdateGraph.AccumulatedCycleStats accumulatedCycleStats
  • Constructor Details

    • BaseUpdateGraph

      public BaseUpdateGraph(String name, boolean allowUnitTestMode, Logger log, long minimumCycleDurationToLogNanos)
      The BaseUpdateGraph is an abstract class that is suitable for extension by UpdateGraphs that process a set of sources and then the resulting Notifications using a BaseUpdateGraph.NotificationProcessor.
      name - the name of the update graph, which must be unique
      allowUnitTestMode - is unit test mode allowed, used for configuring the lock
      log - the logger for this update graph
      minimumCycleDurationToLogNanos - the minimum cycle time, in nanoseconds, that results in cycle times being logged to at an INFO level
  • Method Details

    • createUpdatePerformanceEntry

      @Nullable public static @Nullable PerformanceEntry createUpdatePerformanceEntry(@Nullable @Nullable UpdateGraph updateGraph, @Nullable @Nullable String description)
      If the provided update graph is a BaseUpdateGraph then create a PerformanceEntry using the given description. Otherwise, return null.
      updateGraph - The update graph to create a performance entry for.
      description - The description for the performance entry.
      The performance entry, or null if the update graph is not a BaseUpdateGraph.
    • getName

      public String getName()
      Specified by:
      getName in interface UpdateGraph
      The name of this UpdateGraph
    • getUpdateGraph

      public UpdateGraph getUpdateGraph()
      Specified by:
      getUpdateGraph in interface NotificationQueue.Dependency
      the update graph that this dependency is a part of
    • toString

      public String toString()
      toString in class Object
    • clock

      public LogicalClock clock()
      Specified by:
      clock in interface UpdateGraph
      The LogicalClock to use with this update graph
    • sharedLock

      public AwareFunctionalLock sharedLock()

      Get the shared lock for this UpdateGraph.

      Using this lock will prevent run processing from proceeding concurrently, but will allow other read-only processing to proceed.

      The shared lock implementation is expected to support reentrance.

      This lock does not support Lock.newCondition(). Use the exclusive lock if you need to wait on events that are driven by run processing.

      Specified by:
      sharedLock in interface UpdateGraph
      The shared lock for this UpdateGraph
    • exclusiveLock

      public AwareFunctionalLock exclusiveLock()

      Get the exclusive lock for this UpdateGraph.

      Using this lock will prevent run or read-only processing from proceeding concurrently.

      The exclusive lock implementation is expected to support reentrance.

      Note that using the exclusive lock while the shared lock is held by the current thread will result in exceptions, as lock upgrade is not supported.

      This lock does support Lock.newCondition().

      Specified by:
      exclusiveLock in interface UpdateGraph
      The exclusive lock for this UpdateGraph
    • currentThreadProcessesUpdates

      public boolean currentThreadProcessesUpdates()
      Test if this thread is part of our run thread executor service.
      Specified by:
      currentThreadProcessesUpdates in interface UpdateGraph
      whether this is one of our run threads.
    • serialTableOperationsSafe

      public boolean serialTableOperationsSafe()
      Description copied from interface: UpdateGraph
      Test if engine code executing on the current thread should assume safety for serial table operations. Operations annotated as concurrent are always safe.
      Specified by:
      serialTableOperationsSafe in interface UpdateGraph
      Whether code on this thread should assume serial table operation safety
      See Also:
    • setSerialTableOperationsSafe

      public boolean setSerialTableOperationsSafe(boolean newValue)
      Description copied from interface: UpdateGraph
      User or engine code that makes its own determination about the safety of initiating serial table operations on the current thread may use this method to override default behavior. The previous value should be restored immediately after use, typically with the following pattern:
       boolean oldValue = assumeSerialTableOperations(true);
       try {
           // ... safe table operations here
       } finally {
      Specified by:
      setSerialTableOperationsSafe in interface UpdateGraph
      newValue - the new value
      the old value
      See Also:
    • addSource

      public void addSource(@NotNull @NotNull Runnable updateSource)
      Add a table to the list of tables to run and mark it as refreshing if it was a DynamicNode.
      Specified by:
      addSource in interface UpdateSourceRegistrar
      updateSource - The table to be added to the run list
    • removeSource

      public void removeSource(@NotNull @NotNull Runnable updateSource)
      Description copied from interface: UpdateSourceRegistrar
      Remove a source from this registrar.
      Specified by:
      removeSource in interface UpdateSourceRegistrar
      updateSource - The table to remove
    • removeSources

      public void removeSources(Collection<Runnable> sourcesToRemove)
      Remove a collection of sources from the list of refreshing sources.
      Specified by:
      removeSources in interface UpdateSourceRegistrar
      sourcesToRemove - The sources to remove from the list of refreshing sources
      This will not set the sources as non-refreshing.
    • sourceCount

      public int sourceCount()
      Return the number of valid sources.
      the number of valid sources
    • addNotification

      public void addNotification(@NotNull @NotNull NotificationQueue.Notification notification)
      Enqueue a notification to be flushed according to its priority. Non-terminal notifications should only be enqueued during the updating phase of a cycle. That is, they should be enqueued from an update source or subsequent notification delivery.
      Specified by:
      addNotification in interface NotificationQueue
      notification - The notification to enqueue
      See Also:
    • maybeAddNotification

      public boolean maybeAddNotification(@NotNull @NotNull NotificationQueue.Notification notification, long deliveryStep)
      Description copied from interface: NotificationQueue
      Add a notification for this NotificationQueue to deliver (by invoking its run() method), iff the delivery step is the current step and the update cycle for that step is still in process. This is only supported for non-terminal notifications.
      Specified by:
      maybeAddNotification in interface NotificationQueue
      notification - The notification to add
      deliveryStep - The step to deliver this notification on
    • satisfied

      public boolean satisfied(long step)
      Description copied from interface: NotificationQueue.Dependency
      Is this ancestor satisfied? Note that this method must be safe to call on any thread.
      Specified by:
      satisfied in interface NotificationQueue.Dependency
      step - The step for which we are testing satisfaction
      Whether the dependency is satisfied on step (and will not fire subsequent notifications)
    • addNotifications

      public void addNotifications(@NotNull @NotNull Collection<? extends NotificationQueue.Notification> notifications)
      Enqueue a collection of notifications to be flushed.
      Specified by:
      addNotifications in interface NotificationQueue
      notifications - The notification to enqueue
      See Also:
    • supportsRefreshing

      public boolean supportsRefreshing()
      Specified by:
      supportsRefreshing in interface UpdateGraph
      Whether this UpdateGraph has a mechanism that supports refreshing
    • isCycleOnBudget

      public boolean isCycleOnBudget(long cycleTimeNanos)
      Is the provided cycle time on budget?
      cycleTimeNanos - the cycle time, in nanoseconds
      true if the cycle time is within the desired budget
    • resetNextFlushTime

      @TestUseOnly public void resetNextFlushTime()
      In unit tests it can be convenient to force the update performance tracker to flush, without waiting for the complete REPORT_INTERVAL_MILLIS to elapse.
    • logDependencies

      public LogEntry logDependencies()
      Specified by:
      logDependencies in interface UpdateGraph
      A LogEntry that may be prefixed with UpdateGraph information
    • takeAccumulatedCycleStats

      public void takeAccumulatedCycleStats(BaseUpdateGraph.AccumulatedCycleStats updateGraphAccumCycleStats)
    • getInstance

      public static UpdateGraph getInstance(String name)
    • removeInstance

      public static boolean removeInstance(String name)
      Remove a named UpdateGraph.

      In addition to removing the UpdateGraph from the instances, an attempt is made to UpdateGraph.stop() it.

      name - the name of the UpdateGraph to remove
      true if the update graph was found
    • buildOrThrow

      public static <T extends UpdateGraph> T buildOrThrow(String name, Supplier<T> construct)
      Builds and caches a new UpdateGraph named name and provided by construct. It is an error if there is already an UpdateGraph with the same name.
      name - the name of the new update graph
      construct - A Supplier to construct an UpdateGraph if no update graph with the name already exists. The Supplier must provide an update graph with the given name.
      IllegalStateException - if an UpdateGraph with the provided name already exists
    • existingOrBuild

      public static <T extends UpdateGraph> T existingOrBuild(String name, Supplier<T> construct)
      Returns an existing UpdateGraph with the provided name if one exists, else returns a new named UpdateGraph supplied by construct.
      construct - A Supplier to construct an UpdateGraph if no update graph with the name already exists. The Supplier must provide an update graph with the given name.
      the UpdateGraph