LiveTraceCallbackpublic class LiveTraceCallback extends Object implements LiveTraceListenerProvides a rendezvous point and synchronous callback within a
LiveTraceListener. An instance of LiveTraceCallback is installed into a
LiveTracer tracepoint like any other LiveTraceListener. Once installed, the
LiveTrace code calls a listener here, which synchronously calls a callback
established by a test making a call to await(). If a callback isn't
available, the trace listener blocks until one becomes available. After the
callback returns, it is removed. Therefore, while the listener is active,
every trace point must be matched by a call to await(). Otherwise,
the thread being traced will block and all the tests will timeout.
Sample usage from an i3test:
tcb = new LiveTraceCallback();
targetObject.liveTracer.add(TRACE_TAG, tcb);
// initiate some operation that will eventually hit TRACE_TAG
assertTrue(
"trace point was hit",
tcb.await(
new Runnable() {
public void run() {
// stuff executed by the traced thread
}
})
);
|
Fields Summary |
---|
public static final long | DEFAULT_TIMEOUTThe default timeout period, in milliseconds. | boolean | active | Runnable | callback | Runnable | doNothing |
Methods Summary |
---|
public synchronized boolean | await(java.lang.Runnable r, long timeout)Blocks until a tracepoint is reached, causes r.run() to be called
synchronously by the traced thraed, and then lets both the traced
thread and the caller continue. Times out after the indicated timeout
period. If a timeout or interrupt occurs, the callback is cleared
without being called.
long deadline = System.currentTimeMillis() + timeout;
long remain = timeout;
boolean retval = true;
callback = r;
notifyAll();
try {
while (callback != null && remain > 0) {
wait(remain);
remain = deadline - System.currentTimeMillis();
}
if (callback != null) {
System.out.println("LiveTraceCallback.await: timed out");
retval = false;
}
} catch (InterruptedException ie) {
System.out.println("LiveTraceCallback.await: interrupted");
retval = false;
} finally {
callback = null;
}
return retval;
| public boolean | await(java.lang.Runnable r)Same as await(r, DEFAULT_TIMEOUT).
return await(r, DEFAULT_TIMEOUT);
| public boolean | await()Same as await(do nothing, DEFAULT_TIMEOUT).
return await(doNothing, DEFAULT_TIMEOUT);
| public synchronized void | call(java.lang.String tag)Called by Display's LiveTracer object after a screen change occurs.
if (!active) {
return;
}
while (active && callback == null) {
try {
wait();
} catch (InterruptedException ignore) { }
}
if (active) {
callback.run();
}
callback = null;
notifyAll();
| public synchronized void | shutdown()Shuts down this trace listener by arranging for any listener not to
block and instead to be ignored. Any blocked listener is unblocked
and returns without calling the callback, even if one was currently
installed.
active = false;
notifyAll();
|
|