Class ScheduledTriggers

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class ScheduledTriggers
    extends Object
    implements Closeable
    Responsible for scheduling active triggers, starting and stopping them and performing actions when they fire
    • Field Detail

      • DEFAULT_SCHEDULED_TRIGGER_DELAY_SECONDS

        public static final int DEFAULT_SCHEDULED_TRIGGER_DELAY_SECONDS
        See Also:
        Constant Field Values
      • DEFAULT_ACTION_THROTTLE_PERIOD_SECONDS

        public static final int DEFAULT_ACTION_THROTTLE_PERIOD_SECONDS
        See Also:
        Constant Field Values
      • DEFAULT_COOLDOWN_PERIOD_SECONDS

        public static final int DEFAULT_COOLDOWN_PERIOD_SECONDS
        See Also:
        Constant Field Values
      • DEFAULT_TRIGGER_CORE_POOL_SIZE

        public static final int DEFAULT_TRIGGER_CORE_POOL_SIZE
        See Also:
        Constant Field Values
      • RANDOM

        protected static final Random RANDOM
    • Method Detail

      • setAutoScalingConfig

        public void setAutoScalingConfig​(AutoScalingConfig autoScalingConfig)
        Set the current autoscaling config. This is invoked by OverseerTriggerThread when autoscaling.json is updated, and it re-initializes trigger listeners and other properties used by the framework
        Parameters:
        autoScalingConfig - current autoscaling.json
      • add

        public void add​(AutoScaling.Trigger newTrigger)
                 throws Exception
        Adds a new trigger or replaces an existing one. The replaced trigger, if any, is closed before the new trigger is run. If a trigger is replaced with itself then this operation becomes a no-op.
        Parameters:
        newTrigger - the trigger to be managed
        Throws:
        AlreadyClosedException - if this class has already been closed
        Exception
      • pauseTriggers

        public void pauseTriggers()
        Pauses all scheduled trigger invocations without interrupting any that are in progress
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • resumeTriggers

        public void resumeTriggers​(long afterDelayMillis)
        Resumes all previously cancelled triggers to be scheduled after the given initial delay
        Parameters:
        afterDelayMillis - the initial delay in milliseconds after which triggers should be resumed
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • removeAll

        public void removeAll()
        Remove and stop all triggers. Also cleans up any leftover state / events in ZK.
      • remove

        public void remove​(String triggerName)
        Removes and stops the trigger with the given name. Also cleans up any leftover state / events in ZK.
        Parameters:
        triggerName - the name of the trigger to be removed
      • getScheduledTriggerNames

        public Set<String> getScheduledTriggerNames()
        Returns:
        an unmodifiable set of names of all triggers being managed by this class
      • getTrigger

        public AutoScaling.Trigger getTrigger​(String name)
        For use in white/grey box testing: The Trigger returned may be inspected, but should not be modified in any way.
        Parameters:
        name - the name of an existing trigger
        Returns:
        the current scheduled trigger with that name, or null if none exists
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.