Package com.illumon.modelfarm
Class ModelFarmOnDemand<KEYTYPE,DATATYPE,ROWDATAMANAGERTYPE extends RowDataManager<KEYTYPE,DATATYPE>>
java.lang.Object
com.illumon.modelfarm.ModelFarmBase<DATATYPE>
com.illumon.modelfarm.ModelFarmOnDemand<KEYTYPE,DATATYPE,ROWDATAMANAGERTYPE>
- Type Parameters:
KEYTYPE
- The type of the keys (e.g.FitScope
).DATATYPE
- The type of the data (e.g.FuturesFitDataOptionPrices
.ROWDATAMANAGERTYPE
- The type of the RowDataManager (e.g.FuturesFitDataManager
).
- All Implemented Interfaces:
ModelFarm
public class ModelFarmOnDemand<KEYTYPE,DATATYPE,ROWDATAMANAGERTYPE extends RowDataManager<KEYTYPE,DATATYPE>> extends ModelFarmBase<DATATYPE>
A ModelFarm implementation for evaluating a model upon request, retrieving a snapshot of data for all keys under a
single
LiveTableMonitor
lock.-
Nested Class Summary
Nested classes/interfaces inherited from class com.illumon.modelfarm.ModelFarmBase
ModelFarmBase.GetDataLockType, ModelFarmBase.State
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ModelFarmOnDemand(int nThreads, Model<DATATYPE> model)
Create a multithreaded resource to execute data driven models on demand. -
Method Summary
Modifier and Type Method Description protected void
execute()
Executes the next task in the work queue.protected boolean
isQueueEmpty()
Returns true if the model farm queue is empty and false if the queue contains elements to execute.protected void
modelFarmStarted()
Method called after the model farm threads have been started.void
requestUpdate(ROWDATAMANAGERTYPE dataManager, Runnable callback)
Submit a request toexecute
theModelFarmBase.model
.void
requestUpdate(ROWDATAMANAGERTYPE dataManager, Runnable callback, Set<KEYTYPE> keys)
Submit a request toexecute
theModelFarmBase.model
.Methods inherited from class com.illumon.modelfarm.ModelFarmBase
awaitTermination, awaitTermination, getDoLockedConsumer, getState, shutdown, shutdownAndAwaitTermination, shutdownAndAwaitTermination, start, terminate, toString
-
Constructor Details
-
ModelFarmOnDemand
Create a multithreaded resource to execute data driven models on demand.- Parameters:
nThreads
- number of worker threads.model
- model to execute.
-
-
Method Details
-
requestUpdate
Submit a request toexecute
theModelFarmBase.model
. Can be called either with or without a LiveTableMonitor lock -- the decision of whether/how to acquire a lock is left to theDO_LOCKED_FUNCTION
. All keys represented by the data in thedataManager
will be processed.- Parameters:
dataManager
- TheRowDataManager
that will provide data for the pricing requests.callback
- A callback function to run after all keys have been processed. Can benull
, in which case it will be ignored.
-
requestUpdate
Submit a request toexecute
theModelFarmBase.model
. Can be called either with or without a LiveTableMonitor lock -- the decision of whether/how to acquire a lock is left to theDO_LOCKED_FUNCTION
.- Parameters:
dataManager
- TheRowDataManager
that will provide data for the pricing requests.callback
- A callback function to run after all keys have been processed. Can benull
, in which case it will be ignored.keys
- They keys for which data should be passed to the model. Ifkeys == null
, then all keys represented by the data in thedataManager
will be processed.
-
execute
Description copied from class:ModelFarmBase
Executes the next task in the work queue.- Specified by:
execute
in classModelFarmBase<DATATYPE>
- Throws:
InterruptedException
- if interrupted while executing
-
modelFarmStarted
protected void modelFarmStarted()Description copied from class:ModelFarmBase
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.- Specified by:
modelFarmStarted
in classModelFarmBase<DATATYPE>
-
isQueueEmpty
protected boolean isQueueEmpty()Description copied from class:ModelFarmBase
Returns true if the model farm queue is empty and false if the queue contains elements to execute.- Specified by:
isQueueEmpty
in classModelFarmBase<DATATYPE>
- Returns:
- true if the model farm queue is empty and false if the queue contains elements to execute.
-