Package adams.multiprocess
Class LocalJobRunner<T extends Job>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.multiprocess.AbstractJobRunner<T>
-
- adams.multiprocess.LocalJobRunner<T>
-
- Type Parameters:
T- the type of job to handle
- All Implemented Interfaces:
CleanUpHandler,Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,Pausable,QuickInfoSupporter,SizeOfHandler,ThreadLimiter,JobRunner<T>,Serializable
public class LocalJobRunner<T extends Job> extends AbstractJobRunner<T> implements ThreadLimiter
Executes the jobs on the local machine.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-num-threads <int> (property: numThreads) The number of threads to use for executing the branches; -1 = number of CPUs/cores; 0 or 1 = sequential execution. default: -1 minimum: -1
- Author:
- dale (dale at cs dot waikato dot ac dot nz), FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PausableFixedThreadPoolExecutorm_Executorthe executor service to use for parallel execution.protected HashSet<JobCompleteListener>m_JobCompleteListenerscall when job complete.protected List<T>m_Jobsall the jobs.protected Map<String,Object>m_MetaDataoptional meta-data.protected intm_NumThreadsthe number of threads to use.protected List<T>m_Queuestores Jobs. add to job queue when dependencies complete.-
Fields inherited from class adams.multiprocess.AbstractJobRunner
m_FlowContext, m_Paused, m_Running, m_Terminating
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description LocalJobRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(JobList<T> jobs)Adds the jobs to the execution queue.voidadd(T job)Adds the job to the execution queue.voidaddJobCompleteListener(JobCompleteListener l)Adds the listener.voidcleanUp()Cleans up data structures, frees up memory.voidclear()Clears all jobs, but not the meta-data.voidcomplete(T j, JobResult jr)Job is complete, so check for more to add..voiddefineOptions()Adds options to the internal list of options.protected StringdoStart()Starts the thread pool and execution of jobs.protected StringdoStop()Stops the execution after all currently queued jobs have been executed.protected StringdoTerminate(boolean wait)Performing actual terminate up.protected booleanenqueue()Enqueues any jobs still waiting in the queue in the executor service.List<T>getJobs()Returns the list of all jobs.Map<String,Object>getMetaData()Returns the meta-data.intgetNumThreads()Returns the number of threads being used for execution.StringgetQuickInfo()Returns a quick info about the object, which can be displayed in the GUI.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.booleanisPaused()Returns whether the object is currently paused.protected voidnotifyJobCompleteListeners(JobCompleteEvent e)Notifies all listeners with the given event.StringnumThreadsTipText()Returns the tip text for this property.voidpauseExecution()Pauses the execution.protected StringpreStart()Before actual start up.voidremoveJobCompleteListener(JobCompleteListener l)Removes the listener.voidresumeExecution()Resumes the execution.voidsetNumThreads(int value)Sets the number of threads to use.protected voidwaitForComplete()Wait until Jobs are completed.-
Methods inherited from class adams.multiprocess.AbstractJobRunner
getFlowContext, isRunning, postStart, postStop, postTerminate, preStop, preTerminate, setFlowContext, start, stop, terminate, terminate
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
Field Detail
-
m_NumThreads
protected int m_NumThreads
the number of threads to use.
-
m_JobCompleteListeners
protected transient HashSet<JobCompleteListener> m_JobCompleteListeners
call when job complete.
-
m_Queue
protected List<T extends Job> m_Queue
stores Jobs. add to job queue when dependencies complete.
-
m_Executor
protected PausableFixedThreadPoolExecutor m_Executor
the executor service to use for parallel execution.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractJobRunner<T extends Job>
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
setNumThreads
public void setNumThreads(int value)
Sets the number of threads to use.- Specified by:
setNumThreadsin interfaceThreadLimiter- Parameters:
value- the number of threads
-
getNumThreads
public int getNumThreads()
Returns the number of threads being used for execution.- Specified by:
getNumThreadsin interfaceThreadLimiter- Returns:
- the number of threads
-
numThreadsTipText
public String numThreadsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Returns:
- null if no info available, otherwise short string
-
addJobCompleteListener
public void addJobCompleteListener(JobCompleteListener l)
Adds the listener.- Specified by:
addJobCompleteListenerin interfaceJobRunner<T extends Job>- Parameters:
l- the listener to add
-
removeJobCompleteListener
public void removeJobCompleteListener(JobCompleteListener l)
Removes the listener.- Specified by:
removeJobCompleteListenerin interfaceJobRunner<T extends Job>- Parameters:
l- the listener to remove
-
notifyJobCompleteListeners
protected void notifyJobCompleteListeners(JobCompleteEvent e)
Notifies all listeners with the given event.- Parameters:
e- the event to send to the listeners
-
clear
public void clear()
Clears all jobs, but not the meta-data.
-
add
public void add(T job)
Adds the job to the execution queue.
-
enqueue
protected boolean enqueue()
Enqueues any jobs still waiting in the queue in the executor service.- Returns:
- true if jobs were queued
-
preStart
protected String preStart()
Before actual start up.- Overrides:
preStartin classAbstractJobRunner<T extends Job>- Returns:
- null if successful, otherwise error message
-
doStart
protected String doStart()
Starts the thread pool and execution of jobs. Only gets executed ifpreStart()was successful.- Specified by:
doStartin classAbstractJobRunner<T extends Job>- Returns:
- null if successful, otherwise error message
- See Also:
AbstractJobRunner.preStart()
-
doStop
protected String doStop()
Stops the execution after all currently queued jobs have been executed.- Specified by:
doStopin classAbstractJobRunner<T extends Job>- Returns:
- null if successful, otherwise error message
-
doTerminate
protected String doTerminate(boolean wait)
Performing actual terminate up.- Specified by:
doTerminatein classAbstractJobRunner<T extends Job>- Parameters:
wait- whether to wait for the jobs to finish- Returns:
- null if successful, otherwise error message
-
waitForComplete
protected void waitForComplete()
Wait until Jobs are completed.
-
pauseExecution
public void pauseExecution()
Pauses the execution.- Specified by:
pauseExecutionin interfaceJobRunner<T extends Job>- Specified by:
pauseExecutionin interfacePausable- Overrides:
pauseExecutionin classAbstractJobRunner<T extends Job>
-
isPaused
public boolean isPaused()
Returns whether the object is currently paused.
-
resumeExecution
public void resumeExecution()
Resumes the execution.- Specified by:
resumeExecutionin interfaceJobRunner<T extends Job>- Specified by:
resumeExecutionin interfacePausable- Overrides:
resumeExecutionin classAbstractJobRunner<T extends Job>
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceCleanUpHandler- Overrides:
cleanUpin classAbstractJobRunner<T extends Job>
-
-