Package org.jboss.util.timeout
Class TimeoutFactory
- java.lang.Object
-
- org.jboss.util.timeout.TimeoutFactory
-
public class TimeoutFactory extends java.lang.ObjectThe timeout factory.- Version:
- $Revision$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTimeoutFactory.TimeoutTargetImplSimple TimeoutTarget implementation that wraps a Runnableprivate static classTimeoutFactory.TimeoutWorkerA runnable that fires the timeout callback
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleancancelledUsed for graceful exitingprivate static BasicThreadPoolDEFAULT_TPThe default threadpool used to execute timeoutsprivate static java.lang.Class<?>priorityQueueClassThe priority queue classprivate static java.lang.StringpriorityQueueNameThe priority queue defaultprivate static java.lang.StringpriorityQueuePropertyThe priority queue propertyprivate TimeoutPriorityQueuequeueThe priority queueprivate static TimeoutFactorysingletonOur singleton instanceprivate ThreadPoolthreadPoolPer TimeoutFactory thread pool used to execute timeoutsprivate static inttimeoutFactoriesCountNumber of TimeoutFactories createdprivate java.lang.ThreadworkerThreadThe daemon thread that dequeues timeouts tasks and issues them for execution to the thread pool
-
Constructor Summary
Constructors Constructor Description TimeoutFactory()Constructs a new TimeoutFactory that uses the default thread poolTimeoutFactory(ThreadPool threadPool)Constructs a new TimeoutFactory that uses the provided ThreadPool
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels all submitted tasks, stops the worker thread and clean-ups everything except for the thread pool.static TimeoutcreateTimeout(long time, TimeoutTarget target)Schedules a new timeout using the singleton TimeoutFactoryprivate voiddoWork()Timeout worker method.static TimeoutFactorygetSingleton()booleanisCancelled()Timeoutschedule(long time, java.lang.Runnable run)Schedules a new timeout.Timeoutschedule(long time, TimeoutTarget target)Schedules a new timeout.
-
-
-
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
-
queue
private TimeoutPriorityQueue queue
The priority queue
-
-
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
-
getSingleton
public static TimeoutFactory getSingleton()
-
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 timetarget- target to fire- Returns:
- the timeout
-
schedule
public Timeout schedule(long time, java.lang.Runnable run)
Schedules a new timeout.- Parameters:
time- absolute timerun- 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.
-
-