Class ActiveMQScheduledComponent

  • All Implemented Interfaces:
    java.lang.Runnable, ActiveMQComponent
    Direct Known Subclasses:
    NetworkHealthCheck

    public abstract class ActiveMQScheduledComponent
    extends java.lang.Object
    implements ActiveMQComponent, java.lang.Runnable
    This is for components with a scheduled at a fixed rate.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.Executor executor  
      protected java.util.concurrent.ScheduledExecutorService scheduledExecutorService  
    • Constructor Summary

      Constructors 
      Constructor Description
      ActiveMQScheduledComponent​(long initialDelay, long checkPeriod, java.util.concurrent.TimeUnit timeUnit, boolean onDemand)
      It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
      ActiveMQScheduledComponent​(long checkPeriod, java.util.concurrent.TimeUnit timeUnit, boolean onDemand)
      It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
      ActiveMQScheduledComponent​(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, long initialDelay, long checkPeriod, java.util.concurrent.TimeUnit timeUnit, boolean onDemand)
      It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
      ActiveMQScheduledComponent​(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, java.util.concurrent.Executor executor, long initialDelay, long checkPeriod, java.util.concurrent.TimeUnit timeUnit, boolean onDemand)
      It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
      ActiveMQScheduledComponent​(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, java.util.concurrent.Executor executor, long checkPeriod, java.util.concurrent.TimeUnit timeUnit, boolean onDemand)
      It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
    • Field Detail

      • scheduledExecutorService

        protected java.util.concurrent.ScheduledExecutorService scheduledExecutorService
      • executor

        protected final java.util.concurrent.Executor executor
    • Constructor Detail

      • ActiveMQScheduledComponent

        public ActiveMQScheduledComponent​(java.util.concurrent.ScheduledExecutorService scheduledExecutorService,
                                          java.util.concurrent.Executor executor,
                                          long initialDelay,
                                          long checkPeriod,
                                          java.util.concurrent.TimeUnit timeUnit,
                                          boolean onDemand)
        It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
        Parameters:
        scheduledExecutorService - the ScheduledExecutorService that periodically trigger Runnable.run() on the configured executor
        executor - the Executor that execute Runnable.run() when triggered
        initialDelay - the time to delay first execution
        checkPeriod - the delay between the termination of one execution and the start of the next
        timeUnit - the time unit of the initialDelay and checkPeriod parameters
        onDemand - if true the task won't be scheduled on start(), false otherwise
      • ActiveMQScheduledComponent

        public ActiveMQScheduledComponent​(java.util.concurrent.ScheduledExecutorService scheduledExecutorService,
                                          long initialDelay,
                                          long checkPeriod,
                                          java.util.concurrent.TimeUnit timeUnit,
                                          boolean onDemand)
        It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.
        Parameters:
        scheduledExecutorService - the ScheduledExecutorService that periodically trigger Runnable.run() on the configured executor
        initialDelay - the time to delay first execution
        checkPeriod - the delay between the termination of one execution and the start of the next
        timeUnit - the time unit of the initialDelay and checkPeriod parameters
        onDemand - if true the task won't be scheduled on start(), false otherwise
      • ActiveMQScheduledComponent

        public ActiveMQScheduledComponent​(java.util.concurrent.ScheduledExecutorService scheduledExecutorService,
                                          java.util.concurrent.Executor executor,
                                          long checkPeriod,
                                          java.util.concurrent.TimeUnit timeUnit,
                                          boolean onDemand)
        It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.

        The component created will have initialDelay defaulted to checkPeriod.

        Parameters:
        scheduledExecutorService - the ScheduledExecutorService that periodically trigger Runnable.run() on the configured executor
        executor - the Executor that execute Runnable.run() when triggered
        checkPeriod - the delay between the termination of one execution and the start of the next
        timeUnit - the time unit of the initialDelay and checkPeriod parameters
        onDemand - if true the task won't be scheduled on start(), false otherwise
      • ActiveMQScheduledComponent

        public ActiveMQScheduledComponent​(long initialDelay,
                                          long checkPeriod,
                                          java.util.concurrent.TimeUnit timeUnit,
                                          boolean onDemand)
        It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.

        This is useful for cases where we want our own scheduler executor: on start() it will create a fresh new single-threaded ScheduledExecutorService using getThreadFactory() and getThisClassLoader(), while on stop() it will garbage it.

        Parameters:
        initialDelay - the time to delay first execution
        checkPeriod - the delay between the termination of one execution and the start of the next
        timeUnit - the time unit of the initialDelay and checkPeriod parameters
        onDemand - if true the task won't be scheduled on start(), false otherwise
      • ActiveMQScheduledComponent

        public ActiveMQScheduledComponent​(long checkPeriod,
                                          java.util.concurrent.TimeUnit timeUnit,
                                          boolean onDemand)
        It creates a scheduled component that can trigger Runnable.run() with a fixed checkPeriod on a configured executor.

        This is useful for cases where we want our own scheduler executor. The component created will have initialDelay defaulted to checkPeriod.

        Parameters:
        checkPeriod - the delay between the termination of one execution and the start of the next
        timeUnit - the time unit of the initialDelay and checkPeriod parameters
        onDemand - if true the task won't be scheduled on start(), false otherwise
    • Method Detail

      • delay

        public boolean delay()
        A delay request can succeed only if:
        • there is no other pending delay request
        • there is no pending execution request

        When a delay request succeed it schedule a new execution to happen in getPeriod().

      • getPeriod

        public long getPeriod()
      • getInitialDelay

        public long getInitialDelay()
      • setInitialDelayAndPeriod

        public ActiveMQScheduledComponent setInitialDelayAndPeriod​(long initialDelay,
                                                                   long period)
        Useful to change a running schedule and avoid multiple restarts.
      • setInitialDelayAndPeriod

        public ActiveMQScheduledComponent setInitialDelayAndPeriod​(long initialDelay,
                                                                   long period,
                                                                   java.util.concurrent.TimeUnit timeUnit)
        Useful to change a running schedule and avoid multiple restarts.
      • getTimeUnit

        public java.util.concurrent.TimeUnit getTimeUnit()