FileDocCategorySizeDatePackage
SerialCallback.javaAPI DocphoneME MR2 API (J2ME)3450Wed May 02 18:00:00 BST 2007com.sun.midp.util

SerialCallback

public class SerialCallback extends Object implements Runnable
An adaptor class that lets a caller synchronize with the event thread. The invokeAndWait() method enqueues an event using Display.callSerially() and blocks the caller. When the event reaches the front of the queue, it calls this object's run() method on the event thread, and unblocks the caller. Clients may override the run() method if they wish to provide specialized behavior that must be run on the event thread. If run() is not overridden, invokeAndWait() simply blocks until the event thread has processed the event. This is useful for callers that need to wait until after an event has been processed. The invokeAndWait() method must not be called on the event thread, otherwise the system will deadlock.

Fields Summary
javax.microedition.lcdui.Display
dpy
Callback
callback
boolean
done
Constructors Summary
public SerialCallback(javax.microedition.lcdui.Display dpy)
Constructs this callback object. Requires a Display object upon which the callSerially() method is to be invoked.

        this.dpy = dpy;
        callback = new Callback();
    
Methods Summary
synchronized voidcalled()
Called on the event thread when the callSerially event reaches the front of the queue. Calls the client's run() method and awakens the thread that had called invokeAndWait().

        run();
        done = true;
        notifyAll();
    
public synchronized voidinvokeAndWait()
Blocks the caller until the events currently in the event queue have been processed, calls the run() method on the event thread, then unblocks the caller.

        dpy.callSerially(callback);
        done = false;

        try {
            while (!done) {
                wait();
            }
        } catch (InterruptedException ignore) { }
    
public voidrun()
Subclassers may override this if they wish to provide any specialized behavior. The default implementation does nothing.