Package io.deephaven.modelfarm
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
A multithreaded resource to execute data driven models.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Type of locking used when loading data from the data manager.static enum
Run state of the farm. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ModelFarmBase
(int nThreads, Model<DATATYPE> model) Create a multithreaded resource to execute data driven models. -
Method Summary
Modifier and TypeMethodDescriptionfinal 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
execute()
Executes the next task in the work queue.protected static ThrowingBiConsumer<io.deephaven.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,
Table, RuntimeException> Returns aThrowingConsumer
that takes aModelFarmBase.QueryDataRetrievalOperation
, acquires aPeriodicUpdateGraph
lock based on the specifiedlockType
, then executes theFitDataPopulator
with the appropriate value for usePrev.protected final ModelFarmBase.State
getState()
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
shutdown()
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
shutdownAndAwaitTermination
(long timeout, TimeUnit unit) Shuts down and then awaits termination.final void
start()
Initiates execution.final void
Attempt to terminate the ModelFarm byshutting it down
and interrupting all worker threads.toString()
-
Field Details
-
model
The model to which data should be passed.
-
-
Constructor Details
-
ModelFarmBase
Create a multithreaded resource to execute data driven models.- Parameters:
nThreads
- number of worker threads.model
- model to execute.
-
-
Method Details
-
execute
Executes the next task in the work queue.- Throws:
InterruptedException
- if interrupted while executing
-
getDoLockedConsumer
protected static ThrowingBiConsumer<io.deephaven.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,Table, getDoLockedConsumerRuntimeException> (ModelFarmBase.GetDataLockType lockType) Returns aThrowingConsumer
that takes aModelFarmBase.QueryDataRetrievalOperation
, acquires aPeriodicUpdateGraph
lock based on the specifiedlockType
, then executes theFitDataPopulator
with the appropriate value for usePrev.- Parameters:
lockType
- The way of acquiring thePeriodicUpdateGraph
lock.- Returns:
- A function that runs an operation which accepts a
ModelFarmBase.QueryDataRetrievalOperation
and aTable
.
-
getState
Gets the current run state of the model farm. The state isnull
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. -
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. -
terminate
public final void terminate()Attempt to terminate the ModelFarm byshutting it down
and interrupting all worker threads. -
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 interfaceModelFarm
- Returns:
true
if this executor terminated andfalse
if the timeout elapsed before termination
-
awaitTermination
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 interfaceModelFarm
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
true
if this executor terminated andfalse
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 interfaceModelFarm
-
shutdownAndAwaitTermination
Description copied from interface:ModelFarm
Shuts down and then awaits termination.- Specified by:
shutdownAndAwaitTermination
in interfaceModelFarm
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
true
if this executor terminated andfalse
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
-