Class BasicExecutionEngine

  • All Implemented Interfaces:
    ExecutionManager

    public class BasicExecutionEngine
    extends java.lang.Object
    implements ExecutionManager
    The ExecutionEngine is a wrapper around a scheduled executor service. Callers are able to create named tasks, and this class keeps track of associating those names with the ScheduledFutures that represent the actual execution tasks.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void executeOnce​(java.lang.Runnable command)
      Executes a runnable one time as soon as possible.
      void executeOnce​(java.lang.Runnable command, long delay)
      Excutes a runnable one time after a delay, specified in milliseconds
      java.util.concurrent.ScheduledFuture<?> executeOnce​(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
      Executes a runnable after a fixed delay
      java.lang.String getName()  
      java.util.List<java.lang.String> getTaskOwners()  
      java.util.List<TaskStats> getTasks​(java.lang.String owner)  
      void modify​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int newRate, java.util.concurrent.TimeUnit newUnit)
      Modifies the execution rate of the given execution unit.
      void modifyFixedRate​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int newRate, java.util.concurrent.TimeUnit newUnit)  
      void register​(java.lang.String owner, java.lang.String name, SelfSchedulingRunnable command)
      Registers a self scheduling command to be executed.
      void register​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int rate)
      Registers a command to be executing repeatedly at the specified rate.
      void register​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int rate, java.util.concurrent.TimeUnit unit)
      Registers a command to be executing repeatedly at the specified rate.
      void registerAtFixedRate​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int rate, java.util.concurrent.TimeUnit unit)
      Registers a command to be executed with a fixed rate rather than a fixed delay.
      void registerAtFixedRateWithInitialDelay​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int rate, java.util.concurrent.TimeUnit unit, int initialDelay)
      Registers a command to be executed with a fixed rate after some initial delay.
      void registerWithInitialDelay​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int rate, int initialDelay)
      Registers a command to be executing repeatedly at the specified rate with an initial delay.
      void registerWithInitialDelay​(java.lang.String owner, java.lang.String name, java.lang.Runnable command, int rate, java.util.concurrent.TimeUnit unit, int initialDelay)
      Registers a command to be executing repeatedly at the specified rate with an initial delay.
      java.lang.String schedule​(java.lang.String taskName, java.lang.Runnable task, java.lang.String cronPattern)  
      protected void scheduleNext​(BasicExecutionEngine.SelfSchedulingRunner ssr)  
      java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay​(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
      Schedules a runnable to execute with a fixed delay, and after an initial delay, much like ExecutionManager.registerWithInitialDelay(String, String, Runnable, int, TimeUnit, int).
      void shutdown()
      Stops all execution gracefully.
      protected void synchedUpdateTaskMap​(java.lang.String owner, java.lang.String name, java.util.concurrent.ScheduledFuture<?> future)
      Updates the task map.
      java.lang.String toString()  
      void unRegister​(java.lang.String owner, java.lang.String name)
      De-registers the execution unit.
      void unRegister​(java.lang.String owner, java.lang.String name, boolean interrupt)
      De-registers the execution unit.
      void unRegisterAll​(java.lang.String owner)
      Unregisters all tasks for a given owner.
      void unSchedule​(java.lang.String taskId)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BasicExecutionEngine

        public BasicExecutionEngine()
      • BasicExecutionEngine

        public BasicExecutionEngine​(int threadCount,
                                    java.lang.String name)
      • BasicExecutionEngine

        public BasicExecutionEngine​(int threadCount,
                                    java.lang.String name,
                                    boolean daemon)
      • BasicExecutionEngine

        public BasicExecutionEngine​(int threadCount,
                                    java.lang.String name,
                                    java.util.concurrent.ThreadFactory threadFactory)
    • Method Detail

      • getName

        public java.lang.String getName()
      • schedule

        public java.lang.String schedule​(java.lang.String taskName,
                                         java.lang.Runnable task,
                                         java.lang.String cronPattern)
                                  throws it.sauronsoftware.cron4j.InvalidPatternException
        Throws:
        it.sauronsoftware.cron4j.InvalidPatternException
      • unSchedule

        public void unSchedule​(java.lang.String taskId)
      • register

        public void register​(java.lang.String owner,
                             java.lang.String name,
                             java.lang.Runnable command,
                             int rate)
        Description copied from interface: ExecutionManager
        Registers a command to be executing repeatedly at the specified rate. If the name is already registered, the existing execution unit will be modified.
        Specified by:
        register in interface ExecutionManager
        Parameters:
        owner - name of the "owner"- just a string qualifier for the command name.
        name - identifier used in conjunction with the owner to identify the command.
        command - Runnable to be called at the specified rate.
        rate - The amount of time to wait in between invocations of the command, in milliseconds.
      • register

        public void register​(java.lang.String owner,
                             java.lang.String name,
                             java.lang.Runnable command,
                             int rate,
                             java.util.concurrent.TimeUnit unit)
        Description copied from interface: ExecutionManager
        Registers a command to be executing repeatedly at the specified rate. If the name is already registered, the existing execution unit will be modified.
        Specified by:
        register in interface ExecutionManager
        Parameters:
        owner - name of the "owner"- just a string qualifier for the command name.
        name - identifier used in conjunction with the owner to identify the command.
        command - Runnable to be called at the specified rate.
      • registerAtFixedRate

        public void registerAtFixedRate​(java.lang.String owner,
                                        java.lang.String name,
                                        java.lang.Runnable command,
                                        int rate,
                                        java.util.concurrent.TimeUnit unit)
        Description copied from interface: ExecutionManager
        Registers a command to be executed with a fixed rate rather than a fixed delay.
        Specified by:
        registerAtFixedRate in interface ExecutionManager
      • registerAtFixedRateWithInitialDelay

        public void registerAtFixedRateWithInitialDelay​(java.lang.String owner,
                                                        java.lang.String name,
                                                        java.lang.Runnable command,
                                                        int rate,
                                                        java.util.concurrent.TimeUnit unit,
                                                        int initialDelay)
        Description copied from interface: ExecutionManager
        Registers a command to be executed with a fixed rate after some initial delay.
        Specified by:
        registerAtFixedRateWithInitialDelay in interface ExecutionManager
      • synchedUpdateTaskMap

        protected void synchedUpdateTaskMap​(java.lang.String owner,
                                            java.lang.String name,
                                            java.util.concurrent.ScheduledFuture<?> future)
        Updates the task map. Task map MUST be synchronized before calling this.
      • registerWithInitialDelay

        public void registerWithInitialDelay​(java.lang.String owner,
                                             java.lang.String name,
                                             java.lang.Runnable command,
                                             int rate,
                                             int initialDelay)
        Description copied from interface: ExecutionManager
        Registers a command to be executing repeatedly at the specified rate with an initial delay.
        Specified by:
        registerWithInitialDelay in interface ExecutionManager
      • registerWithInitialDelay

        public void registerWithInitialDelay​(java.lang.String owner,
                                             java.lang.String name,
                                             java.lang.Runnable command,
                                             int rate,
                                             java.util.concurrent.TimeUnit unit,
                                             int initialDelay)
        Description copied from interface: ExecutionManager
        Registers a command to be executing repeatedly at the specified rate with an initial delay.
        Specified by:
        registerWithInitialDelay in interface ExecutionManager
      • modify

        public void modify​(java.lang.String owner,
                           java.lang.String name,
                           java.lang.Runnable command,
                           int newRate,
                           java.util.concurrent.TimeUnit newUnit)
        Modifies the execution rate of the given execution unit. Basically just unregisters and registers. Can also be used to modify the Runnable associated with the name.
      • modifyFixedRate

        public void modifyFixedRate​(java.lang.String owner,
                                    java.lang.String name,
                                    java.lang.Runnable command,
                                    int newRate,
                                    java.util.concurrent.TimeUnit newUnit)
      • unRegister

        public void unRegister​(java.lang.String owner,
                               java.lang.String name)
        De-registers the execution unit. If the unit is in the process of running, it will be interrupted.
        Specified by:
        unRegister in interface ExecutionManager
      • unRegister

        public void unRegister​(java.lang.String owner,
                               java.lang.String name,
                               boolean interrupt)
        De-registers the execution unit.
        Specified by:
        unRegister in interface ExecutionManager
        Parameters:
        interrupt - Interrupts the execution if it is currently occurring. If false, waits for completion.
      • unRegisterAll

        public void unRegisterAll​(java.lang.String owner)
        Unregisters all tasks for a given owner.
        Specified by:
        unRegisterAll in interface ExecutionManager
      • executeOnce

        public void executeOnce​(java.lang.Runnable command)
        Executes a runnable one time as soon as possible.
        Specified by:
        executeOnce in interface ExecutionManager
      • executeOnce

        public void executeOnce​(java.lang.Runnable command,
                                long delay)
        Description copied from interface: ExecutionManager
        Excutes a runnable one time after a delay, specified in milliseconds
        Specified by:
        executeOnce in interface ExecutionManager
      • executeOnce

        public java.util.concurrent.ScheduledFuture<?> executeOnce​(java.lang.Runnable command,
                                                                   long delay,
                                                                   java.util.concurrent.TimeUnit unit)
                                                            throws java.util.concurrent.RejectedExecutionException
        Executes a runnable after a fixed delay
        Specified by:
        executeOnce in interface ExecutionManager
        Throws:
        java.util.concurrent.RejectedExecutionException
      • register

        public void register​(java.lang.String owner,
                             java.lang.String name,
                             SelfSchedulingRunnable command)
        Description copied from interface: ExecutionManager
        Registers a self scheduling command to be executed. Self scheduling commands provide their own execution delay, which can change from exec to exec.
        Specified by:
        register in interface ExecutionManager
      • getTaskOwners

        public java.util.List<java.lang.String> getTaskOwners()
      • getTasks

        public java.util.List<TaskStats> getTasks​(java.lang.String owner)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object