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 theJobScheduler
interface which schedules and executes jobs using aThreadPoolExecutor
.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
shutdownRequested
-
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 void
awaitFreeCapacity()
Wait for free slots for the execution of jobs.void
execute(ServerJob serverJob)
Execute the given job.int
getActiveCount()
Get the number of currently active (executing) jobs.long
getCompletedTaskCount()
int
getCorePoolSize()
ExecutionStrategyFactory
getExecutionStrategyFactory()
String
getInstanceName()
int
getMaximumPoolSize()
NodeWorkerFactory
getNodeWorkerFactory()
TheNodeWorkerFactory
which is responsible to instantiateNodeWorker
s from a givenNode
for jobs that run on jadice server.ObjectName
getObjectName()
ServerStatistics
getStatisticsRecorder()
TempFileReaper
getTempFileReaper()
Get a reaper for temporaryFile
sint
getThreadPriority()
WorkingDirectory
getWorkingDirectory()
Get the working directory to be used for temporary files for this instance.boolean
isApplicationContextShutdownActive()
boolean
isRunning()
Return whether the scheduler is running.Thread
newThread(Runnable r)
void
notifyStateChanged(ServerJob serverJob, Job.State state)
void
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
void
setApplicationContextShutdownActive(boolean applicationContextShutdownActive)
void
setConcurrentJobs(int size)
void
setConcurrentJobsPerProcessor(int n)
void
setExecutionStrategyFactory(ExecutionStrategyFactory executionTypeFactory)
void
setInstanceName(String name)
The scheduler's name (used for JMX naming purposes only)void
setNodeWorkerFactory(NodeWorkerFactory workerFactory)
void
setStatisticsRecorder(ServerStatistics statistics)
void
setTempFileReaper(TempFileReaper tempFileReaper)
void
setThreadPriority(int threadPriority)
void
setWorkingDirectory(WorkingDirectory workingDirectory)
void
shutdown()
Stop scheduling jobs.void
start(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:JobScheduler
Start scheduling jobs listening on the given request endpoint.- Specified by:
start
in interfaceJobScheduler
- Throws:
Exception
- in case of startup failure
-
shutdown
public void shutdown()
Description copied from interface:JobScheduler
Stop scheduling jobs. This method may not return immediately, but wait for any outstanding jobs to be finished first.- Specified by:
shutdown
in interfaceJobScheduler
-
newThread
public Thread newThread(Runnable r)
- Specified by:
newThread
in interfaceThreadFactory
-
getActiveCount
@ManagedAttribute(description="Number of actively executing jobs") public int getActiveCount()
Description copied from interface:JobScheduler
Get the number of currently active (executing) jobs.- Specified by:
getActiveCount
in 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:
getObjectName
in interfaceorg.springframework.jmx.export.naming.SelfNaming
- Throws:
MalformedObjectNameException
-
setInstanceName
public void setInstanceName(String name)
Description copied from interface:JobScheduler
The scheduler's name (used for JMX naming purposes only)- Specified by:
setInstanceName
in interfaceJobScheduler
- Parameters:
name
- the name of thisJobScheduler
instance
-
isRunning
@ManagedAttribute public boolean isRunning()
Description copied from interface:JobScheduler
Return whether the scheduler is running.- Specified by:
isRunning
in interfaceJobScheduler
- Returns:
true
iff the scheduler is running
-
awaitFreeCapacity
public void awaitFreeCapacity()
Description copied from interface:JobScheduler
Wait for free slots for the execution of jobs.- Specified by:
awaitFreeCapacity
in interfaceJobScheduler
-
getInstanceName
public String getInstanceName()
- Specified by:
getInstanceName
in interfaceJobScheduler
- Returns:
- the name of this server instance.
-
execute
public void execute(ServerJob serverJob)
Description copied from interface:JobScheduler
Execute the given job.- Specified by:
execute
in interfaceJobScheduler
- Parameters:
serverJob
- theServerJob
to execute
-
notifyStateChanged
public void notifyStateChanged(ServerJob serverJob, Job.State state)
Description copied from interface:JobScheduler
Notifies informally the Job Scheduler that the viewer side'sJob.State
of aServerJob
has changed. No mission critical component must rely on this information.- Specified by:
notifyStateChanged
in interfaceJobScheduler
- Parameters:
serverJob
- The job that has changed the statestate
- the new state
-
getTempFileReaper
public TempFileReaper getTempFileReaper()
Description copied from interface:JobScheduler
Get a reaper for temporaryFile
s- Specified by:
getTempFileReaper
in interfaceJobScheduler
- Returns:
- a
TempFileReaper
-
setTempFileReaper
public void setTempFileReaper(TempFileReaper tempFileReaper)
-
getNodeWorkerFactory
public NodeWorkerFactory getNodeWorkerFactory()
TheNodeWorkerFactory
which is responsible to instantiateNodeWorker
s from a givenNode
for jobs that run on jadice server.- Returns:
- The
NodeWorkerFactory
to 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:JobScheduler
Get the working directory to be used for temporary files for this instance.- Specified by:
getWorkingDirectory
in 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:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
-
-