Class TimeoutFactory


  • public class TimeoutFactory
    extends java.lang.Object
    The timeout factory.
    Version:
    $Revision$
    • Field Detail

      • priorityQueueProperty

        private static final java.lang.String priorityQueueProperty
        The priority queue property
      • priorityQueueName

        private static final java.lang.String priorityQueueName
        The priority queue default
      • singleton

        private static TimeoutFactory singleton
        Our singleton instance
      • timeoutFactoriesCount

        private static int timeoutFactoriesCount
        Number of TimeoutFactories created
      • priorityQueueClass

        private static java.lang.Class<?> priorityQueueClass
        The priority queue class
      • DEFAULT_TP

        private static BasicThreadPool DEFAULT_TP
        The default threadpool used to execute timeouts
      • cancelled

        private java.util.concurrent.atomic.AtomicBoolean cancelled
        Used for graceful exiting
      • workerThread

        private java.lang.Thread workerThread
        The daemon thread that dequeues timeouts tasks and issues them for execution to the thread pool
      • threadPool

        private ThreadPool threadPool
        Per TimeoutFactory thread pool used to execute timeouts
    • Constructor Detail

      • TimeoutFactory

        public TimeoutFactory​(ThreadPool threadPool)
        Constructs a new TimeoutFactory that uses the provided ThreadPool
        Parameters:
        threadPool -
      • TimeoutFactory

        public TimeoutFactory()
        Constructs a new TimeoutFactory that uses the default thread pool
    • Method Detail

      • createTimeout

        public static Timeout createTimeout​(long time,
                                            TimeoutTarget target)
        Schedules a new timeout using the singleton TimeoutFactory
        Parameters:
        time -
        target -
        Returns:
        the timeout
      • schedule

        public Timeout schedule​(long time,
                                TimeoutTarget target)
        Schedules a new timeout.
        Parameters:
        time - absolute time
        target - target to fire
        Returns:
        the timeout
      • schedule

        public Timeout schedule​(long time,
                                java.lang.Runnable run)
        Schedules a new timeout.
        Parameters:
        time - absolute time
        run - runnable to run
        Returns:
        the timeout
      • cancel

        public void cancel()
        Cancels all submitted tasks, stops the worker thread and clean-ups everything except for the thread pool. Scheduling new timeouts after cancel is called results in a IllegalStateException.
      • isCancelled

        public boolean isCancelled()
        Returns:
        true if the TimeoutFactory has been cancelled, false if it is operational (i.e. accepts timeout schedules).
      • doWork

        private void doWork()
        Timeout worker method.