FileDocCategorySizeDatePackage
ProxyListener.javaAPI DocJ2ME CLDC 1.17213Wed Feb 05 15:56:04 GMT 2003kdp

ProxyListener

public abstract class ProxyListener extends Thread

Fields Summary
int
verbose
static int
method_index_base
final int
METHOD_BASE_SHIFT
final int
METHOD_BASE_BITS
final int
METHOD_BASE_ONE_FLAG
final int
MAJOR_VERSION
final int
MINOR_VERSION
Map
waitingQueue
private List
packetQueue
boolean
timeToQuit
String[]
VMcmds
String[]
DBGcmds
String[]
VENcmds
Constructors Summary
public ProxyListener()


      
        packetQueue = Collections.synchronizedList(new LinkedList());
    
Methods Summary
protected voiddisp(Packet p)

        String[][] cmds;
    int cmdSet = p.cmdSet;
    int cmd = p.cmd;
    int cmdSetIndex = cmdSet;
    int cmdIndex = cmd;

        if ( cmdSet < 64 ) {
            cmds = VMcmds;
        } else if ( cmdSet < 128 ) {
            cmds = DBGcmds;
            cmdSetIndex -= 64;
/*
 * THIS IS LIKELY TO CAUSE PROBLEMS IN THE FUTURE
 */
            cmdIndex -= 99;
        } else {
            cmds = VENcmds;
            cmdSetIndex = cmdIndex = 0;
        }

        try {
            Log.LOGN(3, "Sending through: " +
                    cmds[ cmdSetIndex ][ 0  ] + "(" + cmdSet + ")/" +
                    cmds[ cmdSetIndex ][ cmdIndex ] + "(" + cmd    + ")" );
        Log.LOGN(8, "Packet: " + p);
        } catch ( ArrayIndexOutOfBoundsException e ) {
            System.out.println( "UNKNOWN COMMAND: " + cmdSet + "/" + cmd );
        }
    
public voidnewPacket(Packet p)


    if (p == null) {
        quit();
        synchronized(packetQueue) {
            packetQueue.notify();
        }
        return;
    }
    synchronized(packetQueue) {
        packetQueue.add(p);
        packetQueue.notify();
    }
    
public abstract voidquit()

voidreplyReceived(Packet p)

        Packet p2;
        if (p == null) {
            quit();
            synchronized(waitingQueue) {
                Iterator iter = waitingQueue.values().iterator();
                while (iter.hasNext()) {
                p2 = (Packet)iter.next();
                p2.notify();
                }
            }
            return;
        }
            
        String idString = String.valueOf(p.id);
        synchronized(waitingQueue) {
            p2 = (Packet)waitingQueue.get(idString);
            if (p2 != null)
                waitingQueue.remove(idString);
        }
        if (p2 == null) {
            System.err.println("Received reply with no sender!");
            return;
        }
        p2.errorCode = p.errorCode;
        p2.data = p.data;
        p2.replied = true;
        synchronized(p2) {
            p2.notify();
        }

    
public abstract voidsend(Packet p)

public voidverbose(int lvl)

        verbose = lvl;
    
protected voidvp(int vlevel, java.lang.String str)

        if ( verbose >= vlevel )
            System.out.print( str );
    
protected voidvpe(int vlevel, java.lang.String str)

        if ( verbose == vlevel )
            vp( vlevel, str );
    
public PacketwaitForPacket()


    synchronized(packetQueue) {
        while (!timeToQuit && packetQueue.size() == 0) {
            try {
                packetQueue.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    if (timeToQuit)
        return null;
    return ((Packet)packetQueue.remove(0));
    
public voidwaitForReply(Packet p)


        synchronized(p) {
            while (!timeToQuit && !p.replied) {
                try { p.wait();
                } catch (InterruptedException e) {
                }
            }
            if (!p.replied)
                throw new RuntimeException();
        }