Package com.levigo.jadice.server.core
Class ThreadPoolJobScheduler
- java.lang.Object
-
- com.levigo.jadice.server.core.ThreadPoolJobScheduler
-
- All Implemented Interfaces:
JobScheduler,ThreadFactory,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.jmx.export.naming.SelfNaming
@ManagedResource(description="A job scheduler") public class ThreadPoolJobScheduler extends Object implements JobScheduler, ThreadFactory, org.springframework.jmx.export.naming.SelfNaming, org.springframework.context.ApplicationContextAware
A default implementation of theJobSchedulerinterface which schedules and executes jobs using aThreadPoolExecutor.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanshutdownRequested
-
Constructor Summary
Constructors Constructor Description ThreadPoolJobScheduler(TempFileReaper tempFileReaper, NodeWorkerFactory nodeWorkerFactory, ExecutionStrategyFactory executionStrategyFactory, WorkingDirectory workingDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawaitFreeCapacity()Wait for free slots for the execution of jobs.voidexecute(ServerJob serverJob)Execute the given job.intgetActiveCount()Get the number of currently active (executing) jobs.longgetCompletedTaskCount()intgetCorePoolSize()ExecutionStrategyFactorygetExecutionStrategyFactory()StringgetInstanceName()intgetMaximumPoolSize()NodeWorkerFactorygetNodeWorkerFactory()TheNodeWorkerFactorywhich is responsible to instantiateNodeWorkers from a givenNodefor jobs that run on jadice server.ObjectNamegetObjectName()ServerStatisticsgetStatisticsRecorder()TempFileReapergetTempFileReaper()Get a reaper for temporaryFilesintgetThreadPriority()WorkingDirectorygetWorkingDirectory()Get the working directory to be used for temporary files for this instance.booleanisApplicationContextShutdownActive()booleanisRunning()Return whether the scheduler is running.ThreadnewThread(Runnable r)voidnotifyStateChanged(ServerJob serverJob, Job.State state)voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetApplicationContextShutdownActive(boolean applicationContextShutdownActive)voidsetConcurrentJobs(int size)voidsetConcurrentJobsPerProcessor(int n)voidsetExecutionStrategyFactory(ExecutionStrategyFactory executionTypeFactory)voidsetInstanceName(String name)The scheduler's name (used for JMX naming purposes only)voidsetNodeWorkerFactory(NodeWorkerFactory workerFactory)voidsetStatisticsRecorder(ServerStatistics statistics)voidsetTempFileReaper(TempFileReaper tempFileReaper)voidsetThreadPriority(int threadPriority)voidsetWorkingDirectory(WorkingDirectory workingDirectory)voidshutdown()Stop scheduling jobs.voidstart(RequestEndpoint<?> requestEndpoint)Start scheduling jobs listening on the given request endpoint.
-
-
-
Constructor Detail
-
ThreadPoolJobScheduler
public ThreadPoolJobScheduler(TempFileReaper tempFileReaper, NodeWorkerFactory nodeWorkerFactory, ExecutionStrategyFactory executionStrategyFactory, WorkingDirectory workingDirectory)
-
-
Method Detail
-
setConcurrentJobs
public void setConcurrentJobs(int size)
-
setConcurrentJobsPerProcessor
public void setConcurrentJobsPerProcessor(int n)
-
isApplicationContextShutdownActive
public boolean isApplicationContextShutdownActive()
-
setApplicationContextShutdownActive
public void setApplicationContextShutdownActive(boolean applicationContextShutdownActive)
-
start
public void start(RequestEndpoint<?> requestEndpoint) throws Exception
Description copied from interface:JobSchedulerStart scheduling jobs listening on the given request endpoint.- Specified by:
startin interfaceJobScheduler- Throws:
Exception- in case of startup failure
-
shutdown
public void shutdown()
Description copied from interface:JobSchedulerStop scheduling jobs. This method may not return immediately, but wait for any outstanding jobs to be finished first.- Specified by:
shutdownin interfaceJobScheduler
-
newThread
public Thread newThread(Runnable r)
- Specified by:
newThreadin interfaceThreadFactory
-
getActiveCount
@ManagedAttribute(description="Number of actively executing jobs") public int getActiveCount()
Description copied from interface:JobSchedulerGet the number of currently active (executing) jobs.- Specified by:
getActiveCountin interfaceJobScheduler- Returns:
- the number of executing jobss.
-
getCompletedTaskCount
@ManagedAttribute(description="Number of completed jobs") public long getCompletedTaskCount()
-
getMaximumPoolSize
@ManagedAttribute(description="Maximum number of concurrently executing jobs") public int getMaximumPoolSize()
-
getCorePoolSize
@ManagedAttribute(description="Number of idle threads in the pool") public int getCorePoolSize()
-
getThreadPriority
@ManagedAttribute(description="Priority for executor threads") public int getThreadPriority()
-
setThreadPriority
public void setThreadPriority(int threadPriority)
-
getObjectName
public ObjectName getObjectName() throws MalformedObjectNameException
- Specified by:
getObjectNamein interfaceorg.springframework.jmx.export.naming.SelfNaming- Throws:
MalformedObjectNameException
-
setInstanceName
public void setInstanceName(String name)
Description copied from interface:JobSchedulerThe scheduler's name (used for JMX naming purposes only)- Specified by:
setInstanceNamein interfaceJobScheduler- Parameters:
name- the name of thisJobSchedulerinstance
-
isRunning
@ManagedAttribute public boolean isRunning()
Description copied from interface:JobSchedulerReturn whether the scheduler is running.- Specified by:
isRunningin interfaceJobScheduler- Returns:
trueiff the scheduler is running
-
awaitFreeCapacity
public void awaitFreeCapacity()
Description copied from interface:JobSchedulerWait for free slots for the execution of jobs.- Specified by:
awaitFreeCapacityin interfaceJobScheduler
-
getInstanceName
public String getInstanceName()
- Specified by:
getInstanceNamein interfaceJobScheduler- Returns:
- the name of this server instance.
-
execute
public void execute(ServerJob serverJob)
Description copied from interface:JobSchedulerExecute the given job.- Specified by:
executein interfaceJobScheduler- Parameters:
serverJob- theServerJobto execute
-
notifyStateChanged
public void notifyStateChanged(ServerJob serverJob, Job.State state)
Description copied from interface:JobSchedulerNotifies informally the Job Scheduler that the viewer side'sJob.Stateof aServerJobhas changed. No mission critical component must rely on this information.- Specified by:
notifyStateChangedin interfaceJobScheduler- Parameters:
serverJob- The job that has changed the statestate- the new state
-
getTempFileReaper
public TempFileReaper getTempFileReaper()
Description copied from interface:JobSchedulerGet a reaper for temporaryFiles- Specified by:
getTempFileReaperin interfaceJobScheduler- Returns:
- a
TempFileReaper
-
setTempFileReaper
public void setTempFileReaper(TempFileReaper tempFileReaper)
-
getNodeWorkerFactory
public NodeWorkerFactory getNodeWorkerFactory()
TheNodeWorkerFactorywhich is responsible to instantiateNodeWorkers from a givenNodefor jobs that run on jadice server.- Returns:
- The
NodeWorkerFactoryto use
-
setNodeWorkerFactory
public void setNodeWorkerFactory(NodeWorkerFactory workerFactory)
-
getStatisticsRecorder
public ServerStatistics getStatisticsRecorder()
-
setStatisticsRecorder
public void setStatisticsRecorder(ServerStatistics statistics)
-
getExecutionStrategyFactory
public ExecutionStrategyFactory getExecutionStrategyFactory()
-
setExecutionStrategyFactory
public void setExecutionStrategyFactory(ExecutionStrategyFactory executionTypeFactory)
-
getWorkingDirectory
public WorkingDirectory getWorkingDirectory()
Description copied from interface:JobSchedulerGet the working directory to be used for temporary files for this instance.- Specified by:
getWorkingDirectoryin interfaceJobScheduler- Returns:
- the working directory that jobs should use
-
setWorkingDirectory
public void setWorkingDirectory(WorkingDirectory workingDirectory)
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
-