Class PeriodicRunnable

  • All Implemented Interfaces:
    TaskRunnable, Runnable
    Direct Known Subclasses:
    PeriodicGroupRunnable

    public class PeriodicRunnable
    extends GeneralTaskRunnable
    Periodic task (task will be run periodically) which has handler integrated (implements ScheduleableAction) can be scheduled to Timer or TimerPool by using PeriodicRunnable. All the elements in the same PeriodicRunnable must have the same timeout period and run period. Elements will be grouped by using the time they enter PeriodicRunnable. Elements which entered PeriodicRunnable excess the timeout time will be checked 1 by 1 and ScheduleableAction (doAction()) will be invoked.
    • Field Detail

      • thisTurn

        protected Set thisTurn
      • nextTurn

        protected Set[] nextTurn
      • runPeriod

        protected long runPeriod
      • timeoutPeriod

        protected long timeoutPeriod
      • containerNeeded

        protected int containerNeeded
      • removeElementAfterAction

        protected boolean removeElementAfterAction
    • Constructor Detail

      • PeriodicRunnable

        public PeriodicRunnable​(long runPeriod,
                                long timeoutPeriod,
                                boolean removeElementAfterAction)
                         throws IllegalArgumentException
        Constructor of PeriodicRunnable.
        Parameters:
        runPeriod - The period of running this PeriodicRunnable
        timeoutPeriod - The timeout period of the objects in this PeriodicRunnable
        removeElementAfterAction - Whether to remove the elements after running the ScheduleableAction on the objects
        Throws:
        IllegalArgumentException
    • Method Detail

      • addElement

        public boolean addElement​(Object obj)
        Adds an element to this PeriodicRunnable.
        Parameters:
        obj - Element to be added to this PeriodicRunnable
        Returns:
        a boolean to indicate whether the add success
      • removeElement

        public boolean removeElement​(Object obj)
        Removes an element from this PeriodicRunnable.
        Parameters:
        obj - Element to be removed from this PeriodicRunnable
        Returns:
        A boolean to indicate whether the remove success
      • getTimeoutPeriod

        public long getTimeoutPeriod()
        Returns the timeout period of this PeriodicRunnable.
        Returns:
        A long value to indicate the timeout period
      • isEmpty

        public boolean isEmpty()
        Indicates whether this PeriodicRunnable is empty.
        Returns:
        A boolean to indicate whether this PeriodicRunnable is empty
      • getRunPeriod

        public long getRunPeriod()
        Returns the run period of this PeriodicRunnable.
        Returns:
        A long value to indicate the run period
      • run

        public void run()
        Implements for TaskRunnable. Run the function of ScheduleableAction on all the objects in thisTurn 1 by 1, and interchange thisTurn and nextTurn.