public abstract class ModelFarmBase<DATATYPE,ROWDATAMANAGERTYPE extends RowDataManager<DATATYPE>> extends Object implements ModelFarm
| Modifier and Type | Class and Description |
|---|---|
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 DATATYPE |
getData(long uid,
boolean lockLiveTableMonitor)
Gets the most recent row data for an 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<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 DATATYPE getData(long uid, boolean lockLiveTableMonitor)
uid - unique identifierlockLiveTableMonitor - true if a LiveTableMonitor lock should be acquired before loading the data.
This lock should be acquired if this function is called outside of onDataUpdate.protected ModelFarmBase.State getState()
public void start()
ModelFarmpublic void shutdown()
ModelFarm
This method does not wait for previously submitted tasks to
complete execution. Use awaitTermination
to do that.
public void terminate()
ModelFarmpublic boolean awaitTermination()
ModelFarmawaitTermination in interface ModelFarm
true if this executor terminated and
false if the timeout elapsed before terminationpublic boolean awaitTermination(long timeout,
TimeUnit unit)
ModelFarmawaitTermination 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()
ModelFarmshutdownAndAwaitTermination in interface ModelFarm
public boolean shutdownAndAwaitTermination(long timeout,
TimeUnit unit)
ModelFarmshutdownAndAwaitTermination 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()