public class TimeoutFactory
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
TimeoutFactory.TimeoutTargetImpl
Simple TimeoutTarget implementation that wraps a Runnable
|
private static class |
TimeoutFactory.TimeoutWorker
A runnable that fires the timeout callback
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicBoolean |
cancelled
Used for graceful exiting
|
private static BasicThreadPool |
DEFAULT_TP
The default threadpool used to execute timeouts
|
private static java.lang.Class<?> |
priorityQueueClass
The priority queue class
|
private static java.lang.String |
priorityQueueName
The priority queue default
|
private static java.lang.String |
priorityQueueProperty
The priority queue property
|
private TimeoutPriorityQueue |
queue
The priority queue
|
private static TimeoutFactory |
singleton
Our singleton instance
|
private ThreadPool |
threadPool
Per TimeoutFactory thread pool used to execute timeouts
|
private static int |
timeoutFactoriesCount
Number of TimeoutFactories created
|
private java.lang.Thread |
workerThread
The daemon thread that dequeues timeouts tasks and issues
them for execution to the thread pool
|
| Constructor and Description |
|---|
TimeoutFactory()
Constructs a new TimeoutFactory that uses the default thread pool
|
TimeoutFactory(ThreadPool threadPool)
Constructs a new TimeoutFactory that uses the provided ThreadPool
|
| Modifier and Type | Method and 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 TimeoutFactory
|
private 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.
|
private static final java.lang.String priorityQueueProperty
private static final java.lang.String priorityQueueName
private static TimeoutFactory singleton
private static int timeoutFactoriesCount
private static java.lang.Class<?> priorityQueueClass
private static BasicThreadPool DEFAULT_TP
private java.util.concurrent.atomic.AtomicBoolean cancelled
private java.lang.Thread workerThread
private ThreadPool threadPool
private TimeoutPriorityQueue queue
public TimeoutFactory(ThreadPool threadPool)
threadPool - public TimeoutFactory()
public static TimeoutFactory getSingleton()
public static Timeout createTimeout(long time, TimeoutTarget target)
time - target - public Timeout schedule(long time, TimeoutTarget target)
time - absolute timetarget - target to firepublic Timeout schedule(long time, java.lang.Runnable run)
time - absolute timerun - runnable to runpublic void cancel()
public boolean isCancelled()
private void doWork()