Class IdleJobService

java.lang.Object
com.nomagic.magicdraw.job.IdleJobService

@OpenApiAll public final class IdleJobService extends Object
Idle job service allows to add jobs which can be executed when application is idle.

Application decides when it is the most appropriate to execute the job without getting application into an inconsistent state.

Example usage:

 Job job = new Job()
 {
     public boolean needsExecute()
     {
         return true;
     }

     public void execute(ProgressStatus progressStatus) throws Exception
     {
         // Do necessary work in the session.
     }

     public void finished()
     {
         // Cleanup after job is finished.
     }

     public String getName()
     {
         return "My Job";
     }
 };

 IdleJobService.getInstance().addJob(job);

 // Remove the job when it is no longer necessary.
 IdleJobService.getInstance().removeJob(job);

 For more information please refer to the JobExample in the examples directory.
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addJob(Job job)
    Adds a job to the service to run every two seconds If the same job was added previously, it will be first canceled and then re-added Method is thread safe.
    void
    addJob(Job job, long interval, int sessionCompletionDelay, boolean onIdle)
    Adds a job to the service to repeatedly run on the given interval If the same job was added previously, it will be canceled and re-added
    Gets the singleton job service.
    void
    Removes job from the service.
    void
    runJob(Job job)
    Immediately runs the job, without checking if it needs to run

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static IdleJobService getInstance()
      Gets the singleton job service.
      Returns:
      job service.
    • addJob

      public void addJob(Job job)
      Adds a job to the service to run every two seconds If the same job was added previously, it will be first canceled and then re-added Method is thread safe.
      Parameters:
      job - to add to the service.
    • addJob

      public void addJob(Job job, long interval, int sessionCompletionDelay, boolean onIdle)
      Adds a job to the service to repeatedly run on the given interval If the same job was added previously, it will be canceled and re-added
      Parameters:
      job - a job to execute
      interval - duration between two executions of the same interval seconds.
      sessionCompletionDelay - how many seconds must past from the last session close. See SessionManager
      onIdle - only execute this job when MagicDraw is idle for the provided interval of seconds Method is thread safe.
    • removeJob

      public void removeJob(Job job)
      Removes job from the service. Method is thread safe.
      Parameters:
      job - rule to remove
    • runJob

      public void runJob(Job job)
      Immediately runs the job, without checking if it needs to run
      Parameters:
      job - job that was previously added to the this service