org.clazzes.util.sched
Interface IOneTimeScheduler

All Known Implementing Classes:
InterceptedOneTimeScheduler, OneTimeSchedulerImpl

public interface IOneTimeScheduler

An scheduler, which is based on an Executor and executes one-time tasks.


Method Summary
 IJobStatus cancelJob(UUID jobId, boolean mayInterrupt)
          Cancels the given job.
 List<UUID> getAllJobsIds()
           
 IJobStatus getJobStatus(UUID jobId)
          Query the job status, if the scheduled job implemented HasCallback, the returned status will be an instance of IJobStatusWithCallback.
 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.
 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.
 

Method Detail

scheduleJob

UUID scheduleJob(Runnable runnable)
Schedule the start of a job that returns no result.

Parameters:
runnable -
Returns:
the uuid of the new job

scheduleJob

<V> UUID scheduleJob(Callable<V> callable)
Schedule the start of a job that returns a result.

Parameters:
callable -
Returns:
the uuid of the new job

getAllJobsIds

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

getJobStatus

IJobStatus getJobStatus(UUID jobId)
Query the job status, if the scheduled job implemented HasCallback, the returned status will be an instance of IJobStatusWithCallback.

Parameters:
jobId - The ID of the job as returned by scheduleJob(Callable) or 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

IJobStatus waitForFinish(UUID jobId)
                         throws InterruptedException,
                                ExecutionException
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.

Parameters:
jobId - job id
Returns:
job status as described, null if no such job status exists
Throws:
InterruptedException
ExecutionException

waitForFinish

IJobStatus waitForFinish(UUID jobId,
                         long timeoutMillis)
                         throws InterruptedException,
                                ExecutionException,
                                TimeoutException
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.

Parameters:
jobId - job id
timeoutMillis - timeout
Returns:
job status as described, null if no such job status exists
Throws:
InterruptedException
ExecutionException
TimeoutException

cancelJob

IJobStatus cancelJob(UUID jobId,
                     boolean mayInterrupt)
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.

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

IJobStatus purgeResult(UUID jobId)
Purges the results of the given job.

Parameters:
jobId - job id
Returns:
job status, null if no such job status exists


Copyright © 2012. All Rights Reserved.