net.dontdrinkandroot.utils.jobmanager

## Class JobManager

- java.lang.Object
- - net.dontdrinkandroot.utils.jobmanager.JobManager

    public class JobManager
    extends Object

### Field Summary

Fields
`static int` `DEFAULT_NUM_JOBS`
`static int` `QUEUE_LENGTH_UNLIMITED`

### Constructor Summary

Constructors
Constructor and Description
`JobManager()` Creates a new JobManager with DEFAULT_NUM_JOBS executors.
`JobManager(int maxJobs)` Creates a new JobManager with the given number of executors.

### Method Summary

Methods
`<T> Job<T>` `claimInterest(AbstractJob<T> job, long duration)` Claim interest in the given job for the given duration.
`<T> Job<T>` `claimInterest(AbstractJob<T> job, long duration, int maxQueuePosition)` Claim interest in the given job for the given duration.
`Job<?>` `claimInterest(String jobId, long duration)` Claims interest in the job with the given id for the given duration.
`<T> Job<T>` `getJob(String jobId)` Get the job with the given id or null if not found.
`int` `getMaxQueueLength()`
`int` `getNumFinished()` Get number of finished jobs that can be retrieved.
`int` `getNumQueued()` Get number of queued jobs.
`int` `getNumRunning()`
`net.dontdrinkandroot.utils.progressmonitor.ProgressStatus` `getProgressStatus(String jobId)` Returns the progress status for the job with the given id.
`List<Job<?>>` `getQueuedJobs()` Returns a List of the currently queued jobs.
`Integer` `getQueuePosition(AbstractJob<?> job)` Gets the queue position for the given job.
`Integer` `getQueuePosition(String jobId)` Gets the queue position for the job with the given id.
`<T> T` `getResult(String jobId)`
`Set<Job<?>>` `getRunningJobs()` Returns a Set of the currently processed jobs.
`boolean` `isJobFinished(String jobId)`
`void` `setMaxQueueLength(int maxQueueLength)`
`void` `stop()` Stops the jobManager, MUST be called or the runner threads are not shutdown.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### QUEUE_LENGTH_UNLIMITED

    public static final int QUEUE_LENGTH_UNLIMITED

See Also:
  Constant Field Values

#### DEFAULT_NUM_JOBS

    public static int DEFAULT_NUM_JOBS

### Constructor Detail

#### JobManager

    public JobManager()

Creates a new JobManager with DEFAULT_NUM_JOBS executors.

#### JobManager

    public JobManager(int maxJobs)

Creates a new JobManager with the given number of executors.

Parameters:
  `maxJobs` - Maximum number of jobs to execute in parallel.

### Method Detail

#### setMaxQueueLength

    public void setMaxQueueLength(int maxQueueLength)

#### getMaxQueueLength

    public int getMaxQueueLength()

#### claimInterest

    public <T> Job<T> claimInterest(AbstractJob<T> job,
                           long duration)
                         throws OvercapacityException

Claim interest in the given job for the given duration. If the job doesn't exist yet is is enqueued.

Parameters:
  `job` - The job to claim interest in.
  `duration` - The maximum duration that we want the job to stay alive.
Returns:
  An attached instance of the job.
Throws:
  `OvercapacityException` - Thrown if the job didn't exist yet and the job queue is full.

#### claimInterest

    public <T> Job<T> claimInterest(AbstractJob<T> job,
                           long duration,
                           int maxQueuePosition)
                         throws OvercapacityException

Claim interest in the given job for the given duration. If the job doesn't exist yet is is enqueued.

Parameters:
  `job` - The job to claim interest in.
  `duration` - The maximum duration that we want the job to stay alive.
  `maxQueuePosition` - Only enqueue job if the job's queue position would not be greater than the given position.
Returns:
  An attached instance of the job.
Throws:
  `OvercapacityException` - Thrown if the job didn't exist yet and the job queue is full.

#### claimInterest

    public Job<?> claimInterest(String jobId,
                       long duration)

Claims interest in the job with the given id for the given duration.

Parameters:
  `jobId` - The jobId.
  `duration` - The duration for which one is interested in the job.
Returns:
  Returns the job if it exists or null.

#### getProgressStatus

    public net.dontdrinkandroot.utils.progressmonitor.ProgressStatus getProgressStatus(String jobId)

Returns the progress status for the job with the given id.

Parameters:
  `jobId` - The job id to get the progress status for.
Returns:
  The progress status of the job or null if it was not found.

#### getQueuePosition

    public Integer getQueuePosition(String jobId)

Gets the queue position for the job with the given id.

Parameters:
  `jobId` - The job to get the queue position for.
Returns:
  Returns the queue position (-1 for finished and 0 for running jobs) or null if the job was not found.

#### getQueuePosition

    public Integer getQueuePosition(AbstractJob<?> job)

Gets the queue position for the given job.

Parameters:
  `job` - The job to get the queue position for.
Returns:
  Returns the queue position (-1 for finished and 0 for running jobs) or null if the job was not found.

#### getNumFinished

    public int getNumFinished()

Get number of finished jobs that can be retrieved.

#### getNumQueued

    public int getNumQueued()

Get number of queued jobs.

#### stop

    public void stop()

Stops the jobManager, MUST be called or the runner threads are not shutdown.

#### getRunningJobs

    public Set<Job<?>> getRunningJobs()

Returns a Set of the currently processed jobs.

#### getQueuedJobs

    public List<Job<?>> getQueuedJobs()

Returns a List of the currently queued jobs.

#### getNumRunning

    public int getNumRunning()

#### getJob

    public <T> Job<T> getJob(String jobId)

Get the job with the given id or null if not found.

Parameters:
  `jobId` - The id of the job to find.
Returns:
  The job if found or null.

#### isJobFinished

    public boolean isJobFinished(String jobId)

#### getResult

    public <T> T getResult(String jobId)