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 PausableFixedThreadPoolExecutor
m_Executor
the executor service to use for parallel execution.protected HashSet<JobCompleteListener>
m_JobCompleteListeners
call when job complete.protected List<T>
m_Jobs
all the jobs.protected Map<String,Object>
m_MetaData
optional meta-data.protected int
m_NumThreads
the number of threads to use.protected List<T>
m_Queue
stores Jobs.-
Fields inherited from class adams.multiprocess.AbstractJobRunner
m_FlowContext, m_Paused, m_Running
-
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 void
add(JobList<T> jobs)
Adds the jobs to the execution queue.void
add(T job)
Adds the job to the execution queue.void
addJobCompleteListener(JobCompleteListener l)
Adds the listener.void
cleanUp()
Cleans up data structures, frees up memory.void
clear()
Clears all jobs, but not the meta-data.void
complete(T j, JobResult jr)
Job is complete, so check for more to add..void
defineOptions()
Adds options to the internal list of options.protected String
doStart()
Starts the thread pool and execution of jobs.protected String
doStop()
Stops the execution after all currently queued jobs have been executed.protected String
doTerminate(boolean wait)
Performing actual terminate up.protected boolean
enqueue()
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.int
getNumThreads()
Returns the number of threads being used for execution.String
getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.boolean
isPaused()
Returns whether the object is currently paused.protected void
notifyJobCompleteListeners(JobCompleteEvent e)
Notifies all listeners with the given event.String
numThreadsTipText()
Returns the tip text for this property.void
pauseExecution()
Pauses the execution.protected String
preStart()
Before actual start up.void
removeJobCompleteListener(JobCompleteListener l)
Removes the listener.void
resumeExecution()
Resumes the execution.void
setNumThreads(int value)
Sets the number of threads to use.protected void
waitForComplete()
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:
initialize
in classAbstractJobRunner<T extends Job>
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
setNumThreads
public void setNumThreads(int value)
Sets the number of threads to use.- Specified by:
setNumThreads
in interfaceThreadLimiter
- Parameters:
value
- the number of threads
-
getNumThreads
public int getNumThreads()
Returns the number of threads being used for execution.- Specified by:
getNumThreads
in 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:
getQuickInfo
in interfaceQuickInfoSupporter
- Returns:
- null if no info available, otherwise short string
-
addJobCompleteListener
public void addJobCompleteListener(JobCompleteListener l)
Adds the listener.- Specified by:
addJobCompleteListener
in interfaceJobRunner<T extends Job>
- Parameters:
l
- the listener to add
-
removeJobCompleteListener
public void removeJobCompleteListener(JobCompleteListener l)
Removes the listener.- Specified by:
removeJobCompleteListener
in 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:
preStart
in 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:
doStart
in 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:
doStop
in classAbstractJobRunner<T extends Job>
- Returns:
- null if successful, otherwise error message
-
doTerminate
protected String doTerminate(boolean wait)
Performing actual terminate up.- Specified by:
doTerminate
in 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:
pauseExecution
in interfaceJobRunner<T extends Job>
- Specified by:
pauseExecution
in interfacePausable
- Overrides:
pauseExecution
in classAbstractJobRunner<T extends Job>
-
isPaused
public boolean isPaused()
Returns whether the object is currently paused.
-
resumeExecution
public void resumeExecution()
Resumes the execution.- Specified by:
resumeExecution
in interfaceJobRunner<T extends Job>
- Specified by:
resumeExecution
in interfacePausable
- Overrides:
resumeExecution
in classAbstractJobRunner<T extends Job>
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractJobRunner<T extends Job>
-
-