RequestListenerImplpublic class RequestListenerImpl extends Object implements RunnableThread to monitor pending invocations and notify a listener
when a matching one is present. |
Fields Summary |
---|
private final ContentHandlerImpl | handlerContenHandlerImpl for which this is listening. | private Thread | threadThe active thread processing the run method. |
Methods Summary |
---|
public void | run()The run method checks for pending invocations for a
desired ContentHandler or application.
When an invocation is available the listener is
notified.
Thread mythread = Thread.currentThread();
while (mythread == thread) {
// Wait for a matching invocation
boolean pending =
InvocationStore.listen(handler.storageId,
handler.classname,
true, true);
if (pending) {
handler.requestNotify();
}
}
| void | setListener(javax.microedition.content.RequestListener listener)Set the listener to be notified and start/stop the monitoring
thread as necesary.
If the listener is non-null make sure there is a thread active
to monitor it.
If there is no listener, then stop the monitor thread.
Unblock any blocked threads so they can get the updated listener.
if (listener != null) {
// Ensure a thread is running to watch for it
if (thread == null || !thread.isAlive()) {
thread = new Thread(this);
thread.start();
}
} else {
// Forget the thread doing the listening; it will exit
thread = null;
}
/*
* Reset notified flags on pending requests.
* Unblock any threads waiting to notify current listeners
*/
InvocationStore.setListenNotify(handler.storageId,
handler.classname, true);
InvocationStore.cancel();
|
|