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.


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()
           
 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(Runnable runnable)
          Schedule the start of a job that returns no result.
 void setDelegate(IOneTimeScheduler delegate)
           
 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.

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.

Specified by:
scheduleJob in interface IOneTimeScheduler
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.


Copyright © 2012. All Rights Reserved.