midletproxylist.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,361 行 · 第 1/3 页

JAVA
1,361
字号
             * MIDlet's destroyApp method is called and the proxy removed             * from this list. One of the cases is when             * a thread the MIDlet started and is still running after             * the destroyApp method has returned, calls display.setCurrent             * with null while cleaning up.             */            return;        }        midletProxy.setMidletState(MIDletProxy.MIDLET_ACTIVE);        notifyListenersOfProxyUpdate(midletProxy,                                     MIDletProxyListListener.MIDLET_STATE);        setForegroundMIDlet(displayController.midletActive(midletProxy));        notifyIfMidletActive();    }    /**     * Process a MIDlet paused notification.     * MIDletControllerEventConsumer I/F method.     *     * TBD: param midletProxy proxy with information about MIDlet     *     * @param midletSuiteId ID of the MIDlet suite     * @param midletClassName Class name of the MIDlet     */    public void handleMIDletPauseNotifyEvent(        // MIDletProxy midletProxy) {        int midletSuiteId,        String midletClassName) {        MIDletProxy midletProxy = findMIDletProxy(midletSuiteId,                                                  midletClassName);        if (midletProxy == null) {            /*             * There is nothing we can do for the other events             * if a proxy was not found. See midletActiveNotification().             */            return;        }        midletProxy.setMidletState(MIDletProxy.MIDLET_PAUSED);        notifyListenersOfProxyUpdate(midletProxy,                                     MIDletProxyListListener.MIDLET_STATE);        setForegroundMIDlet(displayController.midletPaused(midletProxy));    }    /**     * Process a MIDlet destroyed event.     * MIDletControllerEventConsumer I/F method.     *     * TBD: param midletProxy proxy with information about MIDlet     *     * @param midletSuiteId ID of the MIDlet suite     * @param midletClassName Class name of the MIDlet     */    public void handleMIDletDestroyNotifyEvent(        // MIDletProxy midletProxy) {        int midletSuiteId,        String midletClassName) {        MIDletProxy midletProxy = findMIDletProxy(midletSuiteId,                                                  midletClassName);        if (midletProxy == null) {            /*             * There is nothing we can do for the event             * if a proxy was not found. See midletActiveNotification().             */            return;        }        midletProxy.destroyedNotification();        removeMidletProxy(midletProxy);    }    /**     * Processes a MIDLET_RESUME_REQUEST event.     *     * MIDletControllerEventConsumer I/F method.     *     * @param midletSuiteId ID of the MIDlet suite     * @param midletClassName Class name of the MIDlet     */    public void handleMIDletResumeRequestEvent(int midletSuiteId,                                               String midletClassName) {        MIDletProxy midletProxy = findMIDletProxy(midletSuiteId,                                                  midletClassName);        if (midletProxy == null) {            /*             * There is nothing we can do for the event             * if a proxy was not found. See midletActiveNotification().             */            return;        }        // Just grant the request.        midletProxy.activateMidlet();    }    /**     * Handles notification event of MIDlet resources pause.     * MIDletControllerEventConsumer I/F method.     *     * @param midletSuiteId ID of the MIDlet suite     * @param midletClassName Class name of the MIDlet     */    public void handleMIDletRsPauseNotifyEvent(        int midletSuiteId,        String midletClassName) {        MIDletProxy midletProxy = findMIDletProxy(midletSuiteId,                                                  midletClassName);        if (midletProxy == null) {            /*             * There is nothing we can do for the other events             * if a proxy was not found.             */            return;        }        notifyListenersOfProxyUpdate(midletProxy,                MIDletProxyListListener.RESOURCES_SUSPENDED);    }    /**     * Process a MIDlet destroy request event.     * MIDletControllerEventConsumer I/F method.     *     * TBD: param midletProxy proxy with information about MIDlet     *     * @param midletIsolateId isolate ID of the sending Display     * @param midletDisplayId ID of the sending Display     */    public void handleMIDletDestroyRequestEvent(        // MIDletProxy midletProxy) {        int midletIsolateId,        int midletDisplayId) {        MIDletProxy midletProxy = findMIDletProxy(midletIsolateId,                                                  midletDisplayId);        if (midletProxy == null) {            return;        }        midletProxy.destroyMidlet();    }    /**     * Process an ACTIVATE_ALL_EVENT.     * MIDletControllerEventConsumer I/F method.     *     */    public void handleActivateAllEvent() {        SuspendSystem.getInstance(classSecurityToken).resume();        synchronized (midletProxies) {            MIDletProxy current;            for (int i = midletProxies.size() - 1; i >= 0; i--) {                current = (MIDletProxy)midletProxies.elementAt(i);                current.activateMidlet();            }        }    }    /**     * Process a PAUSE_ALL_EVENT.     * MIDletControllerEventConsumer I/F method.     */    public void handlePauseAllEvent() {        synchronized (midletProxies) {            MIDletProxy current;            for (int i = midletProxies.size() - 1; i >= 0; i--) {                current = (MIDletProxy)midletProxies.elementAt(i);                if (!current.wasNotActive) {                    SuspendSystem.getInstance(classSecurityToken).                            addSuspendDependency(current);                    current.pauseMidlet();                } else {                    MIDletProxyUtils.terminateMIDletIsolate(current, this);                }            }        }        SuspendSystem.getInstance(classSecurityToken).suspend();    }    /**     * Finalizes PAUSE_ALL_EVENT processing after timeout for     * pausing MIDlets expires.     */    public void terminatePauseAll() {        synchronized (midletProxies) {            MIDletProxy current;            for (int i = midletProxies.size() - 1; i >= 0; i--) {                current = (MIDletProxy)midletProxies.elementAt(i);                current.terminateNotPausedMidlet();            }        }    }    /**     * Process a SHUTDOWN_ALL_EVENT.     * MIDletControllerEventConsumer I/F method.     *     * It simply calls "shutdown()". In future it shall be merged with     * "shutdown()" and substitute it.     */    public void handleDestroyAllEvent() {        shutdown();    }    /**     * Processes FATAL_ERROR_NOTIFICATION.     *     * MIDletControllerEventConsumer I/F method.     *     * @param midletIsolateId isolate ID of the sending isolate     * @param midletDisplayId ID of the sending Display     */    public void handleFatalErrorNotifyEvent(        int midletIsolateId,        int midletDisplayId) {        removeIsolateProxies(midletIsolateId);        AmsUtil.terminateIsolate(midletIsolateId);    }    /**     * Notifies the device if an active MIDlet appeared in the system.     * The notification is produced only once when the system runs     * out of the state with all the MIDlets being either paused      * or destroyed.     */    private void notifyIfMidletActive() {        MIDletProxy midletProxy;        synchronized (midletProxies) {            if (allPaused) {                for (int i = midletProxies.size() - 1; i >= 0; i--) {                    midletProxy = (MIDletProxy)midletProxies.elementAt(i);                    if (midletProxy.getMidletState() ==                            MIDletProxy.MIDLET_ACTIVE) {                        allPaused = false;                        notifyResumeAll0();                        break;                    }                }            }        }    }    /**     * Notifies the device if all MIDlets considered to be paused, that is     * at least one MIDlet is paused and others are either paused or     * destroyed. The notification is produced only once when the system     * runs to that state.     */    private void notifyIfAllPaused() {        boolean  allMidletsPaused = false;        int midletState;        synchronized (midletProxies) {            if (!allPaused) {                for (int i = midletProxies.size() - 1; i >= 0; i--) {                    midletState = ((MIDletProxy) midletProxies.elementAt(i)).                            getMidletState();                    if (MIDletProxy.MIDLET_PAUSED == midletState) {                        allMidletsPaused = true;                    } else if (MIDletProxy.MIDLET_DESTROYED != midletState) {                        allMidletsPaused = false;                        break;                    }                }                if (allMidletsPaused) {                    allPaused = true;                    notifySuspendAll0();                }            }        }    }    /**     * Process a Display created notification.     * MIDletControllerEventConsumer I/F method.     *     * @param midletIsolateId isolate ID of the sending Display     * @param midletDisplayId ID of the sending Display     * @param midletClassName Class name of the MIDlet that owns the display     */    public void handleDisplayCreateNotifyEvent(        int midletIsolateId,        int midletDisplayId,        String midletClassName) {        MIDletProxy midletProxy = null;        synchronized (midletProxies) {            for (int i = midletProxies.size() - 1; i >= 0; i--) {                MIDletProxy current = (MIDletProxy)midletProxies.elementAt(i);                if (current.getIsolateId() == midletIsolateId &&                        current.getClassName().equals(midletClassName)) {                    midletProxy = current;                    break;                }            }        }        if (midletProxy == null) {            /**             * The isolate is create a display without a MIDlet to display             * a fatal error loading the suite in SVM mode.             * So just do nothing, a preempt event will follow.             */            return;        }        /* Just set the display ID of the proxy. */        midletProxy.setDisplayId(midletDisplayId);    }    /**     * Process a foreground request event.     * MIDletControllerEventConsumer I/F method.     *     * TBD: param midletProxy proxy with information about MIDlet     *     * @param midletIsolateId isolate ID of the sending Display     * @param midletDisplayId ID of the sending Display     * @param isAlert true if the current displayable is an Alert     */    public void handleDisplayForegroundRequestEvent(        // MIDletProxy midletProxy) {        int midletIsolateId,        int midletDisplayId,        boolean isAlert) {        MIDletProxy midletProxy = findMIDletProxy(midletIsolateId,                                                  midletDisplayId);        if (midletProxy == null) {            /*             * There is nothing we can do for the event             * if a proxy was not found. See midletActiveNotification().             */            return;        }        if (midletProxy == foregroundMidlet) {            // force alert waiting to false, since it can't be waiting            midletProxy.setWantsForeground(true, false);        } else {            midletProxy.setWantsForeground(true, isAlert);            setForegroundMIDlet(                displayController.foregroundRequest(midletProxy));        }        /**         * The internal calls to  notifyListenersOfProxyChange() within         * setForegroundMIDlet() should not override the behaviour of         * listener which is an IndicatorManager in this case. So,         * notifyListenersOfProxyChange() should be called after         * setForegroundMIDlet().         */        notifyListenersOfProxyUpdate(midletProxy,                                     MIDletProxyListListener.WANTS_FOREGROUND);    }    /**     * Process a background request event.     * MIDletControllerEventConsumer I/F method.     *     * TBD: param midletProxy proxy with information about MIDlet     *     * @param midletIsolateId isolate ID of the sending Display     * @param midletDisplayId ID of the sending Display     */    public void handleDisplayBackgroundRequestEvent(        // MIDletProxy midletProxy) {        int midletIsolateId,        int midletDisplayId) {        MIDletProxy midletProxy = findMIDletProxy(midletIsolateId,                                                  midletDisplayId);        if (midletProxy == null) {            /*             * There is nothing we can do for the event             * if a proxy was not found.             *             * Sometimes an display can send an event before             * MIDlet. One of the cases is when             * a MIDlet calls Display.setCurrent with a new displayable in             * its constructor which happens before the MIDlet created             * event.             *             * Sometimes an display can send an event after a             * MIDlet's destroyApp method is called and the proxy removed             * from this list. One of the cases is when             * a thread the MIDlet started and is still running after             * the destroyApp method has returned, calls display.setCurrent             * with null while cleaning up.             */            return;        }        midletProxy.setWantsForeground(false, false);        setForegroundMIDlet(displayController.backgroundRequest(midletProxy));        notifyListenersOfProxyUpdate(midletProxy,                                     MIDletProxyListListener.WANTS_FOREGROUND);    }    /**     * Process a "display preempt start" event.     * <p>     * Set the foreground to a given display if a certain display     * has the foreground. Used to start preempting.     *     * MIDletControllerEventConsumer I/F method.     *     * @param midletIsolateId isolate ID of the sending Display     * @param midletDisplayId ID of the sending Display     */    public void handleDisplayPreemptStartEvent(        int midletIsolateId,        int midletDisplayId) {        MIDletProxy preempting = new MIDletProxy(this, 0,            midletIsolateId, MIDletSuite.UNUSED_SUITE_ID,                null, null, MIDletProxy.MIDLET_ACTIVE);        preempting.setDisplayId(midletDisplayId);        MIDletProxy nextForeground =            displayController.startPreempting(preempting);        if (nextForeground != null) {            setForegroundMIDlet(nextForeground);        }    }    /**     * Process a "display preempt stop" event.     * <p>     * Set the foreground to a given display if a certain display     * has the foreground. Used to end preempting.     *     * MIDletControllerEventConsumer I/F method.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?