FileDocCategorySizeDatePackage
Sender.javaAPI DocphoneME MR2 API (J2ME)2842Wed May 02 18:00:02 BST 2007com.sun.midp.links

Sender

public class Sender extends Thread
A thread that sends the given message on the given link.

Fields Summary
public static final long
TIMEOUT
Link
link
LinkMessage
msg
boolean
done
Throwable
exception
Constructors Summary
Sender(Link newlink, LinkMessage newmsg)
Constructs a new Sender, starts its thread, and waits to give the new thread a chance to block in send().


                             
        
        link = newlink;
        msg = newmsg;
        done = false;
        exception = null;
        start();
        Utils.sleep(50);
    
Methods Summary
public voidawait()
Waits until the thread finishes or until a timeout has expired.

        long timeout = System.currentTimeMillis() + TIMEOUT;
        synchronized (this) {
            try {
                while (System.currentTimeMillis() < timeout && !done) {
                    wait(TIMEOUT);
                }
            } catch (InterruptedException ignore) { }
        }
    
public voidcompleted(LinkMessage msg, java.lang.Throwable thr)
A completion callback. Called after the thread returns from the send() call. The msg parameter contains the message sent. The thr parameter contains any Throwable caught, or null there was none. This is intended to be overridden by a subclass. The default implementation does nothing.

    
public voidrun()
Sends a message and notifies when done, capturing any exceptions.

        try {
            link.send(msg);
        } catch (Throwable t) {
            exception = t;
        } finally {
            synchronized (this) {
                done = true;
                notifyAll();
            }
        }

        completed(msg, exception);