Class ModelFarmBase<DATATYPE>

java.lang.Object
com.illumon.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.
  • Field Details

  • 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 FunctionalInterfaces.ThrowingBiConsumer<com.illumon.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,​NotificationStepSource,​RuntimeException> getDoLockedConsumer​(ModelFarmBase.GetDataLockType lockType)
      Returns a ThrowingConsumer that takes a ModelFarmBase.QueryDataRetrievalOperation, acquires a LiveTableMonitor lock based on the specified lockType, then executes the FitDataPopulator with the appropriate value for usePrev.
      Parameters:
      lockType - The way of acquiring the LiveTableMonitor lock.
      Returns:
      A function that runs a
    • 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