org.clazzes.util.sched.impl
Class InterceptedOneTimeScheduler

java.lang.Object
  extended by org.clazzes.util.sched.impl.InterceptedOneTimeScheduler
All Implemented Interfaces:
IOneTimeScheduler

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 Summary
InterceptedOneTimeScheduler()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterceptedOneTimeScheduler

public InterceptedOneTimeScheduler()
Method Detail

scheduleJob

public UUID scheduleJob(Runnable runnable)
Description copied from interface: 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.

Specified by:
scheduleJob in interface IOneTimeScheduler
Parameters:
runnable - Teh runnbel to schedule.
Returns:
the uuid of the new job

scheduleJob

public UUID scheduleJob(org.aopalliance.intercept.Joinpoint joinpoint)
Description copied from interface: 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.

Specified by:
scheduleJob in interface IOneTimeScheduler
Returns:
the uuid of the new job

scheduleJob

public <V> UUID scheduleJob(Callable<V> callable)
Description copied from interface: 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.

Specified by:
scheduleJob in interface IOneTimeScheduler
Parameters:
callable - The callable to be scheduled.
Returns:
the uuid of the new job

getAllJobsIds

public List<UUID> getAllJobsIds()
Specified by:
getAllJobsIds in interface IOneTimeScheduler
Returns:
a list of all currently existing job ids. This may include jobs that are already completed.

getJobStatus

public IJobStatus getJobStatus(UUID jobId)
Description copied from interface: IOneTimeScheduler
Query the job status, if the scheduled job implemented HasCallback, the returned status will be an instance of IJobStatusWithCallback.

Specified by:
getJobStatus in interface IOneTimeScheduler
Parameters:
jobId - The ID of the job as returned by IOneTimeScheduler.scheduleJob(Callable) or IOneTimeScheduler.scheduleJob(Runnable).
Returns:
a job status or 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)

waitForFinish

public IJobStatus waitForFinish(UUID jobId)
                         throws InterruptedException,
                                ExecutionException
Description copied from interface: IOneTimeScheduler
Waits until the given job has finished. Returns the status of the job, or null if no such job exists, e.g. because the scheduler does no longer run.

Specified by:
waitForFinish in interface IOneTimeScheduler
Parameters:
jobId - job id
Returns:
job status as described, null if no such job status exists
Throws:
InterruptedException
ExecutionException

waitForFinish

public IJobStatus waitForFinish(UUID jobId,
                                long timeoutMillis)
                         throws InterruptedException,
                                ExecutionException,
                                TimeoutException
Description copied from interface: IOneTimeScheduler
Waits until the given job has finished, but no longer than the given timeout. Returns the status of the job, or null if no such job exists, e.g. because the scheduler does no longer run.

Specified by:
waitForFinish in interface IOneTimeScheduler
Parameters:
jobId - job id
timeoutMillis - timeout
Returns:
job status as described, null if no such job status exists
Throws:
InterruptedException
ExecutionException
TimeoutException

cancelJob

public IJobStatus cancelJob(UUID jobId,
                            boolean mayInterrupt)
Description copied from interface: IOneTimeScheduler
Cancels the given job. Returns the status of the job, or null if no such job exists, e.g. because the scheduler does no longer run.

Specified by:
cancelJob in interface IOneTimeScheduler
Parameters:
jobId - job id
mayInterrupt - true if and only if the job is allowed to be interrupted
Returns:
job status as described, null if no such job status exists

purgeResult

public IJobStatus purgeResult(UUID jobId)
Description copied from interface: IOneTimeScheduler
Purges the results of the given job.

Specified by:
purgeResult in interface IOneTimeScheduler
Parameters:
jobId - job id
Returns:
job status, null if no such job status exists

getDelegate

public IOneTimeScheduler getDelegate()
Returns:
the delegate one-time scheduler.

setDelegate

public void setDelegate(IOneTimeScheduler delegate)
Parameters:
delegate - the delegate one-time scheduler to set.

getProxyFactory

public org.clazzes.util.aop.ProxyFactory getProxyFactory()
Returns:
the proxy factory used to intercept Runnables and Callables.

setProxyFactory

public void setProxyFactory(org.clazzes.util.aop.ProxyFactory proxyFactory)
Parameters:
proxyFactory - the proxy factory used to intercept Runnables and Callables to set. It should have an already configured list of interceptors.

isInterceptNextExecutionDelay

public boolean isInterceptNextExecutionDelay()
Returns:
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.

setInterceptNextExecutionDelay

public void setInterceptNextExecutionDelay(boolean interceptNextExecutionDelay)
Parameters:
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. All Rights Reserved.