Class ModelFarmBase<DATATYPE>

java.lang.Object
io.deephaven.modelfarm.ModelFarmBase<DATATYPE>
Type Parameters:
DATATYPE - data type
All Implemented Interfaces:
ModelFarm
Direct Known Subclasses:
ModelFarmOnDemand, RDMModelFarm

public abstract class ModelFarmBase<DATATYPE> extends Object implements ModelFarm
A multithreaded resource to execute data driven models.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Type of locking used when loading data from the data manager.
    static enum 
    Run state of the farm.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Model<DATATYPE>
    The model to which data should be passed.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ModelFarmBase(int nThreads, Model<DATATYPE> model)
    Create a multithreaded resource to execute data driven models.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Blocks until all tasks have completed execution after a shutdown request.
    final boolean
    awaitTermination(long timeout, TimeUnit unit)
    Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, whichever happens first.
    protected abstract void
    Executes the next task in the work queue.
    protected static ThrowingBiConsumer<io.deephaven.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,Table,RuntimeException>
    Returns a ThrowingConsumer that takes a ModelFarmBase.QueryDataRetrievalOperation, acquires a PeriodicUpdateGraph lock based on the specified lockType, then executes the FitDataPopulator with the appropriate value for usePrev.
    protected final ModelFarmBase.State
    Gets the current run state of the model farm.
    protected abstract boolean
    Returns true if the model farm queue is empty and false if the queue contains elements to execute.
    protected abstract void
    Method called after the model farm threads have been started.
    final void
    Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
    final void
    Shuts down and then awaits termination.
    final boolean
    Shuts down and then awaits termination.
    final void
    Initiates execution.
    final void
    Attempt to terminate the ModelFarm by shutting it down and interrupting all worker threads.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • model

      protected final Model<DATATYPE> model
      The model to which data should be passed.
  • Constructor Details

    • ModelFarmBase

      protected ModelFarmBase(int nThreads, Model<DATATYPE> model)
      Create a multithreaded resource to execute data driven models.
      Parameters:
      nThreads - number of worker threads.
      model - model to execute.
  • Method Details

    • execute

      protected abstract void execute() throws InterruptedException
      Executes the next task in the work queue.
      Throws:
      InterruptedException - if interrupted while executing
    • getDoLockedConsumer

      protected static ThrowingBiConsumer<io.deephaven.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,Table,RuntimeException> getDoLockedConsumer(ModelFarmBase.GetDataLockType lockType)
      Returns a ThrowingConsumer that takes a ModelFarmBase.QueryDataRetrievalOperation, acquires a PeriodicUpdateGraph lock based on the specified lockType, then executes the FitDataPopulator with the appropriate value for usePrev.
      Parameters:
      lockType - The way of acquiring the PeriodicUpdateGraph lock.
      Returns:
      A function that runs an operation which accepts a ModelFarmBase.QueryDataRetrievalOperation and a Table.
    • getState

      protected final ModelFarmBase.State getState()
      Gets the current run state of the model farm. The state is null before the model farm has started.
      Returns:
      current run state of the model farm.
    • start

      public final void start()
      Description copied from interface: ModelFarm
      Initiates execution.
      Specified by:
      start in interface ModelFarm
    • modelFarmStarted

      protected abstract void modelFarmStarted()
      Method called after the model farm threads have been started. Implementing classes can override this to perform additional setup (e.g. creating and starting listeners). The default implementation does nothing.
    • shutdown

      public final void shutdown()
      Description copied from interface: ModelFarm
      Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

      This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

      Specified by:
      shutdown in interface ModelFarm
    • terminate

      public final void terminate()
      Attempt to terminate the ModelFarm by shutting it down and interrupting all worker threads.
      Specified by:
      terminate in interface ModelFarm
    • awaitTermination

      public final boolean awaitTermination()
      Description copied from interface: ModelFarm
      Blocks until all tasks have completed execution after a shutdown request.
      Specified by:
      awaitTermination in interface ModelFarm
      Returns:
      true if this executor terminated and false if the timeout elapsed before termination
    • awaitTermination

      public final boolean awaitTermination(long timeout, TimeUnit unit)
      Description copied from interface: ModelFarm
      Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, whichever happens first.
      Specified by:
      awaitTermination in interface ModelFarm
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      true if this executor terminated and false if the timeout elapsed before termination
    • shutdownAndAwaitTermination

      public final void shutdownAndAwaitTermination()
      Description copied from interface: ModelFarm
      Shuts down and then awaits termination.
      Specified by:
      shutdownAndAwaitTermination in interface ModelFarm
    • shutdownAndAwaitTermination

      public final boolean shutdownAndAwaitTermination(long timeout, TimeUnit unit)
      Description copied from interface: ModelFarm
      Shuts down and then awaits termination.
      Specified by:
      shutdownAndAwaitTermination in interface ModelFarm
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      true if this executor terminated and false if the timeout elapsed before termination
    • isQueueEmpty

      protected abstract boolean isQueueEmpty()
      Returns true if the model farm queue is empty and false if the queue contains elements to execute.
      Returns:
      true if the model farm queue is empty and false if the queue contains elements to execute.
    • toString

      public String toString()
      Overrides:
      toString in class Object