Package org.jboss.util.timeout
Class TimeoutFactory
- java.lang.Object
-
- org.jboss.util.timeout.TimeoutFactory
-
public class TimeoutFactory extends java.lang.Object
The timeout factory.- Version:
- $Revision$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TimeoutFactory.TimeoutTargetImpl
Simple TimeoutTarget implementation that wraps a Runnableprivate static class
TimeoutFactory.TimeoutWorker
A runnable that fires the timeout callback
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
cancelled
Used for graceful exitingprivate static BasicThreadPool
DEFAULT_TP
The default threadpool used to execute timeoutsprivate static java.lang.Class<?>
priorityQueueClass
The priority queue classprivate static java.lang.String
priorityQueueName
The priority queue defaultprivate static java.lang.String
priorityQueueProperty
The priority queue propertyprivate TimeoutPriorityQueue
queue
The priority queueprivate static TimeoutFactory
singleton
Our singleton instanceprivate ThreadPool
threadPool
Per TimeoutFactory thread pool used to execute timeoutsprivate static int
timeoutFactoriesCount
Number of TimeoutFactories createdprivate java.lang.Thread
workerThread
The 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 void
cancel()
Cancels all submitted tasks, stops the worker thread and clean-ups everything except for the thread pool.static Timeout
createTimeout(long time, TimeoutTarget target)
Schedules a new timeout using the singleton TimeoutFactoryprivate void
doWork()
Timeout worker method.static TimeoutFactory
getSingleton()
boolean
isCancelled()
Timeout
schedule(long time, java.lang.Runnable run)
Schedules a new timeout.Timeout
schedule(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.
-
-