org.clazzes.util.sched.impl
public class InterceptedOneTimeScheduler extends Object implements IOneTimeScheduler
A one-time scheduler, which delegates to another scheduler and schedules
Runnable
and Callable
instances intercepted by the provided
ProxyFactory
instance.
This class takes care, that the HasCallback
and ITimedJob
aspects of the passed runnables or callables are passed to the underlying
scheduler. Thereby, the HasCallback
aspect is not intercepted whereas
the ITimedJob
aspect is intercepted based on the setting of
setInterceptNextExecutionDelay(boolean)
.
Constructor and Description |
---|
InterceptedOneTimeScheduler() |
Modifier and Type | Method and Description |
---|---|
IJobStatus |
cancelJob(UUID jobId,
boolean mayInterrupt)
Cancels the given job.
|
List<UUID> |
getAllJobsIds() |
IOneTimeScheduler |
getDelegate() |
IJobStatus |
getJobStatus(UUID jobId)
Query the job status, if the scheduled job implemented
HasCallback ,
the returned status will be an instance of IJobStatusWithCallback . |
org.clazzes.util.aop.ProxyFactory |
getProxyFactory() |
boolean |
isInterceptNextExecutionDelay() |
IJobStatus |
purgeResult(UUID jobId)
Purges the results of the given job.
|
<V> UUID |
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 |
setDelegate(IOneTimeScheduler delegate) |
void |
setInterceptNextExecutionDelay(boolean interceptNextExecutionDelay) |
void |
setProxyFactory(org.clazzes.util.aop.ProxyFactory proxyFactory) |
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.
|
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 idnull
if no such job status existsInterruptedException
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
- timeoutnull
if no such job status existsInterruptedException
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 interruptednull
if no such job status existspublic IJobStatus purgeResult(UUID jobId)
IOneTimeScheduler
purgeResult
in interface IOneTimeScheduler
jobId
- job idnull
if no such job status existspublic IOneTimeScheduler getDelegate()
public void setDelegate(IOneTimeScheduler delegate)
delegate
- the delegate one-time scheduler to set.public org.clazzes.util.aop.ProxyFactory getProxyFactory()
public void setProxyFactory(org.clazzes.util.aop.ProxyFactory proxyFactory)
proxyFactory
- the proxy factory used to intercept Runnables and
Callables to set. It should have an already configured
list of interceptors.public boolean isInterceptNextExecutionDelay()
ITimedJob.getNextExecutionDelay()
is intercepted or not.
This may be set to true
, if you want to schedule
a timed job and the calculation of the next execution delay
needs some resources like database connection or the like.public void setInterceptNextExecutionDelay(boolean interceptNextExecutionDelay)
interceptNextExecutionDelay
- Set whether the method
ITimedJob.getNextExecutionDelay()
is intercepted or not.
This may be set to true
, if you want to schedule
a timed job and the calculation of the next execution delay
needs some resources like database connection or the like.Copyright © 2013 Clazzes.org. All Rights Reserved.