FileDocCategorySizeDatePackage
IsolateSynch.javaAPI DocphoneME MR2 API (J2ME)4188Wed May 02 18:00:00 BST 2007com.sun.midp.i3test

IsolateSynch

public class IsolateSynch extends Object
A simple cross-isolate synchronization mechanism. Handles the simple case of synchronizing between two isolates, performing "master" and "slave" roles. This is useful for cross-isolate unit testing. This is a utility class, containing only static methods. No instances of this class are ever created.

This class must be initialized once (presumably the by master), by calling init(), before starting the slave isolate. The master isolate can call awaitReady() to wait for the slave isolate to become ready. The slave isolate performs whatever initialization and testing it wants and then calls pause(). This blocks the slave and unblocks the master's call to awaitReady(), giving the master the opportunity to inspect the slave's state. The master can then call signalContinue() to unblock the slave. Finally, the fini() call will destroy the shared objects created by init().

Example code for master isolate:

void testAnotherIsolate() {
IsolateSynch.init();
Isolate iso = new Isolate(start_class, args);
iso.start();
IsolateSynch.awaitReady();
// assertions can be made safely here about the state of the slave
IsolateSynch.signalContinue();
IsolateSynch.fini();
}

Example code for slave isolate:

public static void main(Strings args[]) {
// perform initialization and execute code under test
IsolateSynch.pause();
// perform any cleanup here
}

Fields Summary
static com.sun.cldc.util.Semaphore
semReady
static com.sun.cldc.util.Semaphore
semContinue
Constructors Summary
private IsolateSynch()

        // disallow creation of instances
    
Methods Summary
public static voidawaitReady()
Blocks until the slave pauses, indicating that it's ready. Intended to be called by the master isolate.

        getSemReady0().acquire();
    
public static voidfini()
Cleans up shared objects. Does nothing if there is nothing to clean up.

        semReady = null;
        semContinue = null;
        fini0();
    
private static native voidfini0()

static native com.sun.cldc.util.SemaphoregetSemContinue0()

static native com.sun.cldc.util.SemaphoregetSemReady0()

public static voidinit()
Initialize shared objects.

throws
IllegalStateException if already initialized.

        semReady = new Semaphore(0);
        semContinue = new Semaphore(0);
        init0(semReady, semContinue);
    
private static native voidinit0(com.sun.cldc.util.Semaphore semReady, com.sun.cldc.util.Semaphore semCont)

public static voidpause()
Blocks the caller and unblocks the master. Intended to be called by the slave.

        getSemReady0().release();
        getSemContinue0().acquire();
    
public static voidsignalContinue()
Informs the slave that it can continue after having paused. Intended to be called by the master isolate.

        getSemContinue0().release();