Package com.illumon.modelfarm
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
A multithreaded resource to execute data driven models.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumType of locking used when loading data from the data manager.static enumRun state of the farm. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedModelFarmBase(int nThreads, Model<DATATYPE> model) Create a multithreaded resource to execute data driven models. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanBlocks until all tasks have completed execution after a shutdown request.final booleanawaitTermination(long timeout, TimeUnit unit) Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, whichever happens first.protected abstract voidexecute()Executes the next task in the work queue.protected static FunctionalInterfaces.ThrowingBiConsumer<com.illumon.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,NotificationStepSource, RuntimeException> Returns aThrowingConsumerthat takes aModelFarmBase.QueryDataRetrievalOperation, acquires aLiveTableMonitorlock based on the specifiedlockType, then executes theFitDataPopulatorwith the appropriate value for usePrev.protected final ModelFarmBase.StategetState()Gets the current run state of the model farm.protected abstract booleanReturns true if the model farm queue is empty and false if the queue contains elements to execute.protected abstract voidMethod called after the model farm threads have been started.final voidshutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.final voidShuts down and then awaits termination.final booleanshutdownAndAwaitTermination(long timeout, TimeUnit unit) Shuts down and then awaits termination.final voidstart()Initiates execution.final voidAttempt to terminate the ModelFarm byshutting it downand 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 FunctionalInterfaces.ThrowingBiConsumer<com.illumon.modelfarm.ModelFarmBase.QueryDataRetrievalOperation,NotificationStepSource, getDoLockedConsumerRuntimeException> (ModelFarmBase.GetDataLockType lockType) Returns aThrowingConsumerthat takes aModelFarmBase.QueryDataRetrievalOperation, acquires aLiveTableMonitorlock based on the specifiedlockType, then executes theFitDataPopulatorwith the appropriate value for usePrev.- Parameters:
lockType- The way of acquiring theLiveTableMonitorlock.
-
getState
Gets the current run state of the model farm. The state isnullbefore the model farm has started.- Returns:
- current run state of the model farm.
-
start
public final void start()Description copied from interface:ModelFarmInitiates 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:ModelFarmInitiates 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
awaitTerminationto do that. -
terminate
public final void terminate()Attempt to terminate the ModelFarm byshutting it downand interrupting all worker threads. -
awaitTermination
public final boolean awaitTermination()Description copied from interface:ModelFarmBlocks until all tasks have completed execution after a shutdown request.- Specified by:
awaitTerminationin interfaceModelFarm- Returns:
trueif this executor terminated andfalseif the timeout elapsed before termination
-
awaitTermination
Description copied from interface:ModelFarmBlocks until all tasks have completed execution after a shutdown request, or the timeout occurs, whichever happens first.- Specified by:
awaitTerminationin interfaceModelFarm- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
trueif this executor terminated andfalseif the timeout elapsed before termination
-
shutdownAndAwaitTermination
public final void shutdownAndAwaitTermination()Description copied from interface:ModelFarmShuts down and then awaits termination.- Specified by:
shutdownAndAwaitTerminationin interfaceModelFarm
-
shutdownAndAwaitTermination
Description copied from interface:ModelFarmShuts down and then awaits termination.- Specified by:
shutdownAndAwaitTerminationin interfaceModelFarm- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
trueif this executor terminated andfalseif 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
-