FileDocCategorySizeDatePackage
MIDletSuiteLoader.javaAPI DocphoneME MR2 API (J2ME)12384Wed May 02 18:00:06 BST 2007com.sun.midp.main

MIDletSuiteLoader

public class MIDletSuiteLoader extends CldcMIDletSuiteLoader
The first class loaded in VM by midp_run_midlet_with_args to initialize internal security the internal AMS classes and start a MIDlet suite.

In SVM mode it handles all MIDlet suites (AMS and internal romized, and application).

In MVM mode it only handles the first MIDlet suite isolate which is used by the MIDP AMS and other internal MIDlets.

Fields Summary
protected CommandState
state
Command state of the MIDlet suite loader
protected int
disableAlerts
Disable startup error alerts, uninitialized by default
protected MIDletEventProducer
midletEventProducer
MIDlet state event producer needed by AMS
protected static com.sun.midp.lcdui.ForegroundEventProducer
foregroundEventProducer
Foreground event producer needed by AMS.
protected MIDletProxyList
midletProxyList
List of MIDlet proxies needed by AMS
Constructors Summary
private MIDletSuiteLoader()
Creates class instance and gets suite parameters from the persistent {@link CommandState} object.

        // Restore command state transfered to MIDlet suite loader
        state = CommandState.getCommandState();

        // Init internal state from the restored command state
        externalAppId = 0;
        midletDisplayName = null;
        args = new String[] {
               state.arg0, state.arg1, state.arg2};
        suiteId = state.suiteId;
        midletClassName = state.midletClassName;

        // Release command state argument references
        state.arg0 = null;
        state.arg1 = null;
        state.arg2 = null;
    
Methods Summary
protected voidcheckForShutdown()
The AMS MIDlet started in the suite loader could request for shutdown, so we need to check it, wait for other MIDlets destroying and update CommandState with appropriate status.

        if (MIDletProxyList.shutdownInProgress()) {

            // The MIDlet was shutdown by either the OS or the
            // push system. Set the command state to signal this
            // to the native AMS code.
            state.status = CommandState.SHUTDOWN;
            midletProxyList.waitForShutdownToComplete();
        } else {
            state.status = CommandState.OK;
        }
    
protected voidcloseSuite()
Overrides suite close logic for the AMS task

        /*
         * The midletSuite is not closed because the other
         * active threads may be depending on it.
         * For example, Display uses isTrusted to update
         * screen icons.
         * A native finalizer will take care of unlocking
         * the native locks.
         */
    
protected voidcreateSuiteEnvironment()
Creates environment objects needed to AMS task

        super.createSuiteEnvironment();

        midletEventProducer = new MIDletEventProducer(eventQueue);
        foregroundEventProducer = new ForegroundEventProducer(eventQueue);
        midletProxyList = new MIDletProxyList(eventQueue);
    
protected voiddisplayException(java.lang.String exceptionMsg)
Displays an exception message to user

param
exceptionMsg the message text

        MIDletSuiteUtils.displayException(
            displayEventHandler, exceptionMsg);
    
protected voiddone()
Extends base class implementatiom with additional actions for main task shutdown. Update and save CommandState instance for VM cycling mechanism.

        super.done();

        state.suiteId = MIDletSuite.UNUSED_SUITE_ID;
        state.midletClassName = null;

        if (state.status != CommandState.SHUTDOWN) {
            if (MIDletSuiteUtils.lastMidletSuiteToRun !=
                    MIDletSuite.UNUSED_SUITE_ID) {

                state.lastSuiteId = MIDletSuiteUtils.lastMidletSuiteToRun;
                state.lastMidletClassName = MIDletSuiteUtils.lastMidletToRun;
                state.lastArg0 = MIDletSuiteUtils.arg0ForLastMidlet;
                state.lastArg1 = MIDletSuiteUtils.arg1ForLastMidlet;
            }

            // Check to see if we need to run a selected suite next
            if (MIDletSuiteUtils.nextMidletSuiteToRun !=
                    MIDletSuite.UNUSED_SUITE_ID) {

                state.suiteId = MIDletSuiteUtils.nextMidletSuiteToRun;
                state.midletClassName = MIDletSuiteUtils.nextMidletToRun;

                state.arg0 = MIDletSuiteUtils.arg0ForNextMidlet;
                state.arg1 = MIDletSuiteUtils.arg1ForNextMidlet;
                state.arg2 = MIDletSuiteUtils.arg2ForNextMidlet;

                state.runtimeInfo.memoryReserved =
                    MIDletSuiteUtils.memoryReserved;
                state.runtimeInfo.memoryTotal = MIDletSuiteUtils.memoryTotal;
                state.runtimeInfo.priority    = MIDletSuiteUtils.priority;
                state.runtimeInfo.profileName = MIDletSuiteUtils.profileName;

            } else if (state.lastSuiteId !=
                    MIDletSuite.UNUSED_SUITE_ID) {

                state.suiteId = state.lastSuiteId;
                state.midletClassName = state.lastMidletClassName;
                state.arg0 = state.lastArg0;
                state.arg1 = state.lastArg1;

                /* Avoid an endless loop. */
                state.lastSuiteId = MIDletSuite.UNUSED_SUITE_ID;
                state.lastMidletClassName = null;
                state.lastArg0 = null;
                state.lastArg1 = null;

                /*
                 * This could an bad JAD from an auto test suite,
                 * so make sure the status to OK, the native
                 * code will run the last suite.
                 */
                state.status = CommandState.OK;
            }
        }

        state.save();
    
protected voidexitLoader()
Gracefully terminates VM with proper return code

        /* Return specific non-zero number so the native AMS code can
         * know that this is graceful exit and not VM abort. */
        CommandState.exitInternal(CommandState.MAIN_EXIT);
    
protected voidinit()
Extends base class initialization with initializatons specific for the AMS task


                    
       
        /*
         * WARNING: Don't add any calls before this !
         *
         * Register AMS task ID native global variable.
         * Since native functions rely on this value to distinguish
         * whether Java AMS is running, this MUST be called before any
         * other native functions from this Isolate. I.E. This call
         * must be the first thing this main make.
         */
        MIDletSuiteUtils.registerAmsIsolateId();
        super.init();

    
protected voidinitGlobalSystems()
Inits global systems common for all started MIDlet suite tasks. The systems should be initialized only once in the AMS task.


        // Initialize AMS task resources needed for all tasks
        MIDletSuiteUtils.initAmsResources();

        // Initialize JSR subsystems
        JSRInitializer.init();

        // Initaialize automation API
        AutomationInitializer.init(
            eventQueue, midletControllerEventProducer);

        // Start inbound connection watcher thread.
        PushRegistryInternal.startListening();

        // Initialize the Content Handler Monitor of MIDlet exits
        CHManager.getManager(internalSecurityToken).initCleanupMonitor(
            midletProxyList);

        // Initialize WMA's cleanup monitor
        WMACleanupMonitor.init(midletProxyList);
    
protected voidinitSuiteEnvironment()
Inits created MIDlet suite environment objects and global subsystems needed for all suites.

The method also loads MIDlet suite paramaters and arguments from the natively saved CommandState instance.

        super.initSuiteEnvironment();

        AmsUtil.initClass(
            midletProxyList, midletControllerEventProducer);

        MIDletProxy.initClass(foregroundEventProducer, midletEventProducer);
        MIDletProxyList.initClass(midletProxyList);

        // Listen for start MIDlet requests from the other isolates
        ExecuteMIDletEventListener.startListening(
            internalSecurityToken,
            displayEventHandler,
            eventQueue);

        // Init gloabal systems common for all isolates
        initGlobalSystems();
    
public static voidmain(java.lang.String[] args)
Called at the initial start of the VM. Initializes internal security and any other AMS classes related classes before starting the MIDlet.

param
args not used, a {@link CommandState} object is obtained and used for arguments

        try {
            MIDletSuiteLoader loader = new MIDletSuiteLoader();

            loader.runMIDletSuite();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    
protected voidreportError(int errorCode, java.lang.String details)
Updates CommandState status and displays proper exception message to user

param
errorCode generic error code
param
details text with error details

        state.status = errorCode;

        // Initialize display alerts state on first error handling
        if (disableAlerts < 0) {
            disableAlerts = Configuration.getIntProperty(
                "DisableStartupErrorAlert", 0);
        }

        int msgId = getErrorMessageId(errorCode);
        String errorMsg = Resource.getString(msgId);
        if (details != null) {
            errorMsg += "\n\n" + details;
        }

        if (disableAlerts == 0) {
            displayException(errorMsg);
        }

        // Error message is always obtained for logging
        if (Logging.REPORT_LEVEL <= Logging.ERROR) {
            Logging.report(Logging.ERROR, LogChannels.LC_CORE, errorMsg);
        }
    
protected voidsetSuiteProperties()
Sets suite arguments as temporary suite properties. The implementation extends base class method with additional properties specific for AMS MIDlet in the internal suite.

        super.setSuiteProperties();

        // Handle logo displaying for Manager MIDlet
        if (suiteId == MIDletSuite.INTERNAL_SUITE_ID) {
            // Disable logo when startup performance is being
            // measured or if the logo has been displayed already
            if (Constants.MEASURE_STARTUP || state.logoDisplayed) {
                midletSuite.setTempProperty(
                    internalSecurityToken, "logo-displayed", "");
            } else {
                state.logoDisplayed = true;
            }
        }