|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.Thread
com.samskivert.util.LoopingThread
com.samskivert.util.Invoker
public class Invoker
The invoker is used to invoke self-contained units of code on an invoking thread. Each invoker is associated with its own thread and that thread is used to invoke all of the units posted to that invoker in the order in which they were posted. The invoker also provides a convenient mechanism for processing the result of an invocation back on the main thread.
The invoker is a useful tool for services that need to block and therefore cannot be run on the main thread. For example, an interactive application might provide an invoker on which to run database queries.
Bear in mind that each invoker instance runs units on its own thread and care must be taken to ensure that code running on separate invokers properly synchronizes access to shared information. Where possible, complete isolation of the services provided by a particular invoker is desirable.
| Nested Class Summary | |
|---|---|
static class |
Invoker.Unit
The unit encapsulates a unit of executable code that will be run on the invoker thread. |
protected static class |
Invoker.UnitProfile
Used to track profile information on invoked units. |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
protected static long |
_defaultLongThreshold
The duration of time after which we consider a unit to be delinquent and log a warning. |
protected Queue<Invoker.Unit> |
_queue
The invoker's queue of units to be executed. |
protected RunQueue |
_receiver
The result receiver with which we're working. |
protected HashMap<Object,Invoker.UnitProfile> |
_tracker
Tracks the counts of invocations by unit's class. |
protected int |
_unitsRun
The total number of invoker units run since the last report. |
protected static boolean |
PERF_TRACK
Whether or not to track invoker unit performance. |
| Fields inherited from class com.samskivert.util.LoopingThread |
|---|
_running |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Fields inherited from interface com.samskivert.util.RunQueue |
|---|
AWT |
| Constructor Summary | |
|---|---|
Invoker(String name,
RunQueue resultReceiver)
Creates an invoker that will post results to the supplied result receiver. |
|
| Method Summary | |
|---|---|
protected void |
didInvokeUnit(Invoker.Unit unit,
long start)
Called before we process an invoker unit. |
boolean |
isDispatchThread()
|
void |
iterate()
This is the main body of the loop. |
void |
postRunnable(Runnable r)
Post the specified Runnable to be run on the RunQueue. |
void |
postUnit(Invoker.Unit unit)
Posts a unit to this invoker for subsequent invocation on the invoker's thread. |
protected void |
recordMetrics(Object key,
long duration)
|
static void |
setDefaultLongThreshold(long millis)
Configures the default duration (in milliseconds) for an invoker unit to be reported as "long". |
void |
shutdown()
Shuts down the invoker thread by queueing up a unit that will cause the thread to exit after all currently queued units are processed. |
protected void |
willInvokeUnit(Invoker.Unit unit,
long start)
Called before we process an invoker unit. |
| Methods inherited from class com.samskivert.util.LoopingThread |
|---|
didShutdown, handleIterateFailure, isRunning, kick, run, willStart |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected Queue<Invoker.Unit> _queue
protected RunQueue _receiver
protected HashMap<Object,Invoker.UnitProfile> _tracker
protected int _unitsRun
protected static long _defaultLongThreshold
protected static final boolean PERF_TRACK
| Constructor Detail |
|---|
public Invoker(String name,
RunQueue resultReceiver)
| Method Detail |
|---|
public static void setDefaultLongThreshold(long millis)
public void postUnit(Invoker.Unit unit)
public void postRunnable(Runnable r)
RunQueue
postRunnable in interface RunQueuepublic boolean isDispatchThread()
isDispatchThread in interface RunQueuepublic void iterate()
LoopingThreadLoopingThread.shutdown(). At minimum, a derived class must override this function
and do something useful.
iterate in class LoopingThreadpublic void shutdown()
shutdown in class LoopingThread
protected void willInvokeUnit(Invoker.Unit unit,
long start)
unit - the unit about to be invoked.start - a timestamp recorded immediately before invocation if PERF_TRACK is
enabled, 0L otherwise.
protected void didInvokeUnit(Invoker.Unit unit,
long start)
unit - the unit about to be invoked.start - a timestamp recorded immediately before invocation if PERF_TRACK is
enabled, 0L otherwise.
protected void recordMetrics(Object key,
long duration)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||