Package io.github.ai4ci.flow
Class SimulationFactory
java.lang.Object
java.lang.Thread
io.github.ai4ci.util.PauseableThread
io.github.ai4ci.flow.SimulationFactory
- All Implemented Interfaces:
Runnable
Configuration, setup and baselining of simulations in this batch. This runs as a
daemon thread and caches
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
doLoop()
Repeatedly called while the thread is not paused or halting.boolean
finished()
There are no more simulations available.void
increaseCacheSize
(int items) Increase simulation queue if loads of memory and risk simulation waiting for factory.boolean
Signify the thread loop is complete and proceed to shutdown.boolean
ready()
void
setup()
Run on thread once at the start.void
shutdown
(boolean completedNormally) Shutdown the thread.static SimulationFactory
startFactory
(List<SetupConfiguration> setups, List<ExecutionConfiguration> executions, String urnBase, SimulationMonitor mon) status()
void
unpause()
Non blocking unpause a thread.Methods inherited from class io.github.ai4ci.util.PauseableThread
halt, isWaiting, pause, run
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
CACHE_SIZE
public static int CACHE_SIZE
-
-
Method Details
-
startFactory
public static SimulationFactory startFactory(List<SetupConfiguration> setups, List<ExecutionConfiguration> executions, String urnBase, SimulationMonitor mon) -
setup
public void setup()Description copied from class:PauseableThread
Run on thread once at the start. Can setup thread local resources. Constructor can be used to set up shared resources.- Specified by:
setup
in classPauseableThread
-
unpause
public void unpause()Description copied from class:PauseableThread
Non blocking unpause a thread. Nothing happens if the thread is not paused. Otherwise the thread will be woken up and resume executing doLoop() repeatedly, until isComplete() is true, or told to halt.- Overrides:
unpause
in classPauseableThread
-
cacheFull
public boolean cacheFull() -
doLoop
public void doLoop()Description copied from class:PauseableThread
Repeatedly called while the thread is not paused or halting. This can interact with resources shared with other threads but needs to be synchronised on them (or use non blocking). This operates equivalent to a `while (!isComplete()) {doLoop();}`- Specified by:
doLoop
in classPauseableThread
-
isComplete
public boolean isComplete()Description copied from class:PauseableThread
Signify the thread loop is complete and proceed to shutdown. This is checked even if the thread is paused.- Specified by:
isComplete
in classPauseableThread
-
shutdown
public void shutdown(boolean completedNormally) Description copied from class:PauseableThread
Shutdown the thread. This must close down any resources and exit without error.- Specified by:
shutdown
in classPauseableThread
- Parameters:
completedNormally
- did the loop complete or was the thread halted?
-
finished
public boolean finished()There are no more simulations available.- Returns:
- true if all the simulations have been created and consumed.
-
ready
public boolean ready()- Returns:
- true if the factory is ready to deliver a configured simulation for execution
-
increaseCacheSize
public void increaseCacheSize(int items) Increase simulation queue if loads of memory and risk simulation waiting for factory.
TODO: Parallelise the simulation factory. The cache being part of the factory is a problem because we can't parallelise it. Increasing the cache size probably wont improve performance if the factory is the limiting factor in the overall speed. -
getSimulationSize
- Returns:
- the rough size of a configured simulation (before it is executed) if we know it yet.
-
status
- Overrides:
status
in classPauseableThread
-