|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.clazzes.util.sched.impl.OneTimeSchedulerImpl
public class OneTimeSchedulerImpl
A bean, which implements IOneTimeScheduler
.
In the context of blueprint, it can be used like this:
<bp:bean id="executorService" class="java.util.concurrent.Executors" factory-method="newFixedThreadPool"> <bp:argument value="3"/> </bp:bean> <bp:bean id="oneTimeScheduler" class="org.clazzes.util.sched.impl.OneTimeSchedulerImpl" init-method="start" destroy-method="shutdownNow"> <bp:property name="executorService" ref="executorService"/> <bp:property name="resultLifeTime" value="10000"/> <bp:property name="gcInterval" value="10000"/> </bp:bean>Then inject the oneTimeScheduler as a bean into your service or servlet, write a Callable or Runnable, and call
scheduleJob
on it.
Probably you also want to write a service for querying the state of your scheduled jobs, using getJobState
.
In that case, transmit the uuid returned by scheduleJob
to the client, and use it as a parameter for the querying
service method lateron.
Constructor Summary | |
---|---|
OneTimeSchedulerImpl()
|
Method Summary | ||
---|---|---|
IJobStatus |
cancelJob(UUID jobId,
boolean mayInterrupt)
Cancels the given job. |
|
List<UUID> |
getAllJobsIds()
|
|
ExecutorService |
getExecutorService()
|
|
long |
getGcInterval()
|
|
IJobStatus |
getJobStatus(UUID jobId)
Query the job status, if the scheduled job implemented HasCallback ,
the returned status will be an instance of IJobStatusWithCallback . |
|
long |
getResultLifeTime()
|
|
Map<String,Object> |
getThreadLocalValues()
|
|
IJobStatus |
purgeResult(UUID jobId)
Purges the results of the given job. |
|
|
scheduleJob(Callable<V> callable)
Schedule the start of a job that returns a result. |
|
UUID |
scheduleJob(org.aopalliance.intercept.Joinpoint joinpoint)
Schedule the start of a job that returns a result. |
|
UUID |
scheduleJob(Runnable runnable)
Schedule the start of a job that returns no result. |
|
void |
setExecutorService(ExecutorService executorService)
|
|
void |
setGcInterval(long gcInterval)
|
|
void |
setResultLifeTime(long resultLifeTime)
|
|
void |
setThreadLocalValues(Map<String,Object> threadLocalValues)
|
|
void |
shutdown()
|
|
void |
shutdownNow()
|
|
void |
start()
|
|
IJobStatus |
waitForFinish(UUID jobId)
Waits until the given job has finished. |
|
IJobStatus |
waitForFinish(UUID jobId,
long timeoutMillis)
Waits until the given job has finished, but no longer than the given timeout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OneTimeSchedulerImpl()
Method Detail |
---|
public void start()
public void shutdown()
public void shutdownNow()
public UUID scheduleJob(Runnable runnable)
IOneTimeScheduler
Schedule the start of a job that returns no result.
The passed instance may implement ITimedJob
in
which case, the job is called repeatedly according to the
results of ITimedJob.getNextExecutionDelay()
.
If runnable
moreover implements HasCallback
,
the job status will be IJobStatusWithCallback
instance,
which bears additional application-specific information.
scheduleJob
in interface IOneTimeScheduler
runnable
- Teh runnbel to schedule.
public UUID scheduleJob(org.aopalliance.intercept.Joinpoint joinpoint)
IOneTimeScheduler
Schedule the start of a job that returns a result.
This method exists in order to schedule AOP instances like
ReflectiveMethodInvocation
. If you have the choice,
please implement Callable
in favor of Joinpoint
,
because this avoids an internal indirection layer.
The passed instance may implement ITimedJob
in
which case, the job is called repeatedly according to the
results of ITimedJob.getNextExecutionDelay()
.
If joinpoint
moreover implements HasCallback
,
the job status will be IJobStatusWithCallback
instance,
which bears additional application-specific information.
scheduleJob
in interface IOneTimeScheduler
public <V> UUID scheduleJob(Callable<V> callable)
IOneTimeScheduler
Schedule the start of a job that returns a result.
The passed instance may implement ITimedJob
in
which case, the job is called repeatedly according to the
results of ITimedJob.getNextExecutionDelay()
.
If callable
moreover implements HasCallback
,
the job status will be IJobStatusWithCallback
instance,
which bears additional application-specific information.
scheduleJob
in interface IOneTimeScheduler
callable
- The callable to be scheduled.
public List<UUID> getAllJobsIds()
getAllJobsIds
in interface IOneTimeScheduler
public IJobStatus getJobStatus(UUID jobId)
IOneTimeScheduler
HasCallback
,
the returned status will be an instance of IJobStatusWithCallback
.
getJobStatus
in interface IOneTimeScheduler
jobId
- The ID of the job as returned by IOneTimeScheduler.scheduleJob(Callable)
or IOneTimeScheduler.scheduleJob(Runnable)
.
null
if no such job status exists (e.g.
because the job has completed and was already garbage collected, or
because the scheduler was shut down)public IJobStatus waitForFinish(UUID jobId) throws InterruptedException, ExecutionException
IOneTimeScheduler
null
if no such job exists, e.g. because the scheduler does no
longer run.
waitForFinish
in interface IOneTimeScheduler
jobId
- job id
null
if no such job status exists
InterruptedException
ExecutionException
public IJobStatus waitForFinish(UUID jobId, long timeoutMillis) throws InterruptedException, ExecutionException, TimeoutException
IOneTimeScheduler
null
if no such job exists,
e.g. because the scheduler does no longer run.
waitForFinish
in interface IOneTimeScheduler
jobId
- job idtimeoutMillis
- timeout
null
if no such job status exists
InterruptedException
ExecutionException
TimeoutException
public IJobStatus cancelJob(UUID jobId, boolean mayInterrupt)
IOneTimeScheduler
null
if no such job exists,
e.g. because the scheduler does no longer run.
cancelJob
in interface IOneTimeScheduler
jobId
- job idmayInterrupt
- true
if and only if the job is allowed to be interrupted
null
if no such job status existspublic IJobStatus purgeResult(UUID jobId)
IOneTimeScheduler
purgeResult
in interface IOneTimeScheduler
jobId
- job id
null
if no such job status existspublic ExecutorService getExecutorService()
public void setExecutorService(ExecutorService executorService)
executorService
- the executorService to setpublic long getGcInterval()
public void setGcInterval(long gcInterval)
gcInterval
- the gcInterval to setpublic long getResultLifeTime()
public void setResultLifeTime(long resultLifeTime)
resultLifeTime
- the lifetime of results after a job has finished in
milliseconds to set.public Map<String,Object> getThreadLocalValues()
public void setThreadLocalValues(Map<String,Object> threadLocalValues)
threadLocalValues
- A list of thread local value to propagate to the
jobs to set. If the value for a given key is null
,
the thread local value for that key of the scheduling thread is
propagated to the asynchronous job.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |