KEYTYPE
- unique ID key typeDATATYPE
- data typepublic abstract class ModelFarmBase<KEYTYPE,DATATYPE,ROWDATAMANAGERTYPE extends RowDataManager<KEYTYPE,DATATYPE>> extends Object implements ModelFarm
Modifier and Type | Class and Description |
---|---|
static class |
ModelFarmBase.GetDataLockType
Type of locking used when loading data from the data manager.
|
protected static class |
ModelFarmBase.State
Run state of the farm.
|
Modifier and Type | Field and Description |
---|---|
protected ROWDATAMANAGERTYPE |
dataManager |
protected Model<DATATYPE> |
model |
Constructor and Description |
---|
ModelFarmBase(int nThreads,
Model<DATATYPE> model,
ROWDATAMANAGERTYPE dataManager)
Create a multithreaded resource to execute data driven models.
|
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination()
Blocks until all tasks have completed execution after a shutdown
request.
|
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 com.illumon.modelfarm.ModelFarmBase.MostRecentDataGetter<KEYTYPE,DATATYPE> |
getMostRecentDataFactory(ModelFarmBase.GetDataLockType lockType)
Factory that creates a function to retrieve the most recent row data for a unique identifier.
|
protected ModelFarmBase.State |
getState()
Gets the current run state of the model farm.
|
protected abstract boolean |
isQueueEmpty()
Returns true if the model farm queue is empty and false if the queue contains elements to execute.
|
protected abstract void |
onDataUpdate(Index added,
Index removed,
Index modified)
Process a change to the data table.
|
void |
shutdown()
Initiates an orderly shutdown in which previously submitted
tasks are executed, but no new tasks will be accepted.
|
void |
shutdownAndAwaitTermination()
Shuts down and then awaits termination.
|
boolean |
shutdownAndAwaitTermination(long timeout,
TimeUnit unit)
Shuts down and then awaits termination.
|
void |
start()
Initiates execution.
|
void |
terminate()
Initiates an immediate termination of all tasks.
|
protected final ROWDATAMANAGERTYPE extends RowDataManager<KEYTYPE,DATATYPE> dataManager
public ModelFarmBase(int nThreads, Model<DATATYPE> model, ROWDATAMANAGERTYPE dataManager)
nThreads
- number of worker threads.model
- model to execute.dataManager
- interface for accessing and querying data contained in rows of a dynamic table.protected abstract void onDataUpdate(Index added, Index removed, Index modified)
added
- new indexes added to the data tableremoved
- indexes removed from the data tablemodified
- indexes modified in the data table.protected abstract void execute() throws InterruptedException
InterruptedException
- if interrupted while executingprotected com.illumon.modelfarm.ModelFarmBase.MostRecentDataGetter<KEYTYPE,DATATYPE> getMostRecentDataFactory(ModelFarmBase.GetDataLockType lockType)
lockType
- locking algorithm used to ensure that data read from the table is consistent.protected ModelFarmBase.State getState()
public void start()
ModelFarm
public void shutdown()
ModelFarm
This method does not wait for previously submitted tasks to
complete execution. Use awaitTermination
to do that.
public void terminate()
ModelFarm
public boolean awaitTermination()
ModelFarm
awaitTermination
in interface ModelFarm
true
if this executor terminated and
false
if the timeout elapsed before terminationpublic boolean awaitTermination(long timeout, TimeUnit unit)
ModelFarm
awaitTermination
in interface ModelFarm
timeout
- the maximum time to waitunit
- the time unit of the timeout argumenttrue
if this executor terminated and
false
if the timeout elapsed before terminationpublic void shutdownAndAwaitTermination()
ModelFarm
shutdownAndAwaitTermination
in interface ModelFarm
public boolean shutdownAndAwaitTermination(long timeout, TimeUnit unit)
ModelFarm
shutdownAndAwaitTermination
in interface ModelFarm
timeout
- the maximum time to waitunit
- the time unit of the timeout argumenttrue
if this executor terminated and
false
if the timeout elapsed before terminationprotected abstract boolean isQueueEmpty()