Class IdleJobService


  • @OpenApiAll
    public final class IdleJobService
    extends java.lang.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:
    Job
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static IdleJobService idleJobService  
      private java.util.Map<Job,​com.nomagic.magicdraw.job.JobScheduler> jobs  
      private java.util.concurrent.ScheduledThreadPoolExecutor taskScheduler  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private IdleJobService()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      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
      static IdleJobService getInstance()
      Gets the singleton job service.
      (package private) java.util.Collection<java.lang.String> getRunningJobs()  
      void removeJob​(Job job)
      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
    • Field Detail

      • jobs

        private final java.util.Map<Job,​com.nomagic.magicdraw.job.JobScheduler> jobs
      • taskScheduler

        private final java.util.concurrent.ScheduledThreadPoolExecutor taskScheduler
    • Constructor Detail

      • IdleJobService

        private IdleJobService()
    • Method Detail

      • 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
      • getRunningJobs

        java.util.Collection<java.lang.String> getRunningJobs()