org.gcube.application.enm.service.concurrent
Class JobMonitor

java.lang.Object
  extended by org.gcube.application.enm.service.concurrent.JobMonitor

public class JobMonitor
extends Object

Coordinates the access to the jobs from several different threads. Instead of using blocking collections (thread-free), this class implements a monitor to guarantee that no duplicates occur in the PriorityQueue of pending jobs, and no collisions occur with the Map of submitted jobs. Even though, a ConcurrentMap is used to store jobs, because of its possible use in other classes.

Author:
Erik Torres

Field Summary
protected  org.gcube.common.core.utils.logging.GCUBELog logger
           
 
Method Summary
 void cancelJob(UUID uuid)
          Cancels a job.
 void clean()
           
static JobMonitor get()
          Get the singleton instance of the monitor.
 GenericJob getJob(UUID uuid)
          Returns the job to which the specified uuid is mapped, or null if this map contains no mapping for the uuid.
 void init(ConcurrentMap<UUID,GenericJob> jobsMap)
          Initializes the job monitor, scheduling the execution of those jobs with the status pending.
 GenericJob nextPendingJob()
          Retrieves the next job from the queue, waiting if necessary until a job becomes available.
 int numPendingJobs()
           
 boolean registerNewJob(GenericJob job)
          Register a new job.
 void removeJob(UUID uuid)
          Removes a job from the map and the persistent storage.
 void schedulePendingJob(GenericJob job)
          Inserts the specified job into the priority queue.
 void updateJob(GenericJob job, JobUpdate updates)
          Call this method any time that a job receives an update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.gcube.common.core.utils.logging.GCUBELog logger
Method Detail

get

public static JobMonitor get()
Get the singleton instance of the monitor.

Returns:
The singleton instance.

init

public void init(ConcurrentMap<UUID,GenericJob> jobsMap)
          throws IllegalArgumentException
Initializes the job monitor, scheduling the execution of those jobs with the status pending.

Parameters:
jobsMap - Holds the list of all jobs.
Throws:
IllegalArgumentException

numPendingJobs

public int numPendingJobs()

nextPendingJob

public GenericJob nextPendingJob()
Retrieves the next job from the queue, waiting if necessary until a job becomes available.

Returns:
The next job of the queue.

schedulePendingJob

public void schedulePendingJob(GenericJob job)
Inserts the specified job into the priority queue.

Parameters:
job - The job to add.

registerNewJob

public boolean registerNewJob(GenericJob job)
Register a new job.

Parameters:
uuid - Unequally identifies the job.
job - The job to add.

getJob

public GenericJob getJob(UUID uuid)
Returns the job to which the specified uuid is mapped, or null if this map contains no mapping for the uuid. In the case that the job is not contained in the map loaded in memory, the method uses the persistence client to retrieve the job from the persistent storage and puts the job in the map, before returning it to the caller.

Parameters:
uuid - Unequally identifies the job.
Returns:
The job to which the specified uuid is mapped, or null if this map contains no mapping for the uuid.

cancelJob

public void cancelJob(UUID uuid)
Cancels a job.

Parameters:
uuid - Unequally identifies the job.

updateJob

public void updateJob(GenericJob job,
                      JobUpdate updates)
Call this method any time that a job receives an update.

Parameters:
job - The job to update.

removeJob

public void removeJob(UUID uuid)
Removes a job from the map and the persistent storage. This effectively removes the job from the service. This method does not cancels the job on the remote execution resource. If you want to cancel the job, call the method cancelJob(UUID) wait until the status of the job change to cancelled, and then call this method.

Parameters:
job - The job to remove.

clean

public void clean()


Copyright © 2012. All Rights Reserved.