amsutil.java

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

JAVA
491
字号
            int priority, String profileName,            boolean isDebugMode) {        Isolate isolate;        String[] args = {Integer.toString(id), midlet, displayName, arg0,                         arg1, arg2, Integer.toString(externalAppId),                         isDebugMode ? "1" : "0"};        String[] classpath = midletSuiteStorage.getMidletSuiteClassPath(id);        if (classpath[0] == null) {            /*             * Avoid a null pointer exception, rommized midlets don't need             * a classpath.             */            classpath[0] = "";        }        String isolateClassPath = System.getProperty("classpathext");        String[] classpathext = null;        if (isolateClassPath != null) {            classpathext = new String[] {isolateClassPath};        }        /*         * Include paths to dynamic components belonging to this suite         * into class path for the new Isolate.         */        DynamicComponentStorage componentStorage =                DynamicComponentStorage.getComponentStorage();        ComponentInfo[] ci = componentStorage.getListOfSuiteComponents(id);        if (ci != null && ci.length > 0) {            /*             * IMPL_NOTE: currently is assumed that each component may have             *            not more than 1 entry in class path.             *            Later it will be possible to have 2: 1 for MONET.             *            + 1 is for System.getProperty("classpathext").             */            int n = 0;            if (isolateClassPath != null) {                classpathext = new String[ci.length + 1];                classpathext[n++] = isolateClassPath;            } else {                classpathext = new String[ci.length];            }            for (int i = 0; i < ci.length; i++) {                String[] componentPath =                        componentStorage.getComponentClassPath(                                ci[i].getComponentId());                if (componentPath != null) {                    for (int j = 0; j < componentPath.length; j++) {                        classpathext[n++] = componentPath[j];                    }                }            }        }        try {            StartMIDletMonitor app = StartMIDletMonitor.okToStart(id, midlet);            if (app == null) {                // Isolate is already running; don't start it again                return null;            }            isolate =                new Isolate("com.sun.midp.main.AppIsolateMIDletSuiteLoader",                    args, classpath, classpathext);            app.setIsolate(isolate);        } catch (Throwable t) {            t.printStackTrace();            throw new RuntimeException("Can't create Isolate****");        }        try {            int reserved, limit;            if (memoryReserved >= 0) {                reserved = memoryReserved;            } else {                reserved = Constants.SUITE_MEMORY_RESERVED * 1024;            }            if (memoryTotal > 0) {                limit = memoryTotal;            } else {                limit = Constants.SUITE_MEMORY_LIMIT;                if (limit < 0) {                    limit = isolate.totalMemory();                } else {                    limit = limit * 1024;                }                int heapSize = getMidletHeapSize(id, midlet);                if ((heapSize > 0) && (heapSize < limit)) {                    limit = heapSize;                }            }            isolate.setMemoryQuota(reserved, limit);            if (priority >= Isolate.MIN_PRIORITY) {                isolate.setPriority(priority);            }            if (profileName != null) {                IsolateUtil.setProfile(isolate, profileName);            }            isolate.setDebug(isDebugMode);                        isolate.setAPIAccess(true);            isolate.start();            // Ability to launch midlet implies right to use Service API for negotiations            // with isolate being run            Link[] isolateLinks =                     SystemServiceLinkPortal.establishLinksFor(isolate, getTrustedToken());            LinkPortal.setLinks(isolate, isolateLinks);        } catch (Throwable t) {            int errorCode;            String msg;            if (Logging.REPORT_LEVEL <= Logging.WARNING) {                t.printStackTrace();            }            if (t instanceof IsolateStartupException) {                /*                 * An error occured in the                 * initialization or configuration of the new isolate                 * before any application code is invoked, or if this                 * Isolate was already started or is terminated.                 */                errorCode = Constants.MIDLET_ISOLATE_CONSTRUCTOR_FAILED;                msg = "Can't start Application.";            } else if (t instanceof IsolateResourceError) {                /* The system has exceeded the maximum Isolate count. */                errorCode = Constants.MIDLET_ISOLATE_RESOURCE_LIMIT;                msg = "No more concurrent applications allowed.";            } else if (t instanceof IllegalArgumentException) {                /* Requested profile doesn't exist. */                errorCode = Constants.MIDLET_ISOLATE_CONSTRUCTOR_FAILED;                msg = "Invalid profile name: " + profileName;            } else if (t instanceof OutOfMemoryError) {                /* The reserved memory cannot be allocated */                errorCode = Constants.MIDLET_OUT_OF_MEM_ERROR;                msg = "Not enough memory to run the application.";            } else {                errorCode = Constants.MIDLET_ISOLATE_CONSTRUCTOR_FAILED;                msg = t.toString();            }            midletControllerEventProducer.sendMIDletStartErrorEvent(                id,                midlet,                externalAppId,                errorCode,                msg);            throw new RuntimeException(msg);        }        return isolate;    }    /*     * Check whether MIDlet-Heap-Size attribute is defined for the     * MIDlet. It specifies maximum heap memory available for the MIDlet.     *     * The value is in bytes and must be a positive integer. The     * only abbreviation in the value definition supported is K that     * stands for kilobytes.     *     * If the amount declared exceeds the maximum heap limit allowed     * for a single MIDlet, the attribute is ignored and the default     * heap limit is used.     *     * Heap size is a total heap memory available for the isolate     * where the MIDlet is launched. The size includes memory     * occupied by the implementation for internal system purposes.     * Thus the real heap size available for the MIDlet may be less.     *     * @param suiteId ID of an installed suite     * @param midletName class name of MIDlet to invoke     *     * @return heap size limit if it's explicitly defined for the MIDlet,     *         or -1 if it's not defined or invalid     */    static private int getMidletHeapSize(int suiteId, String midletName) {        int heapSize = -1;        if (Constants.EXTENDED_MIDLET_ATTRIBUTES_ENABLED) {            String heapSizeProp = MIDletSuiteUtils.getSuiteProperty(                suiteId, midletName, MIDletSuite.HEAP_SIZE_PROP);            if (heapSizeProp != null) {                boolean sizeInKilos = false;                int propLen = heapSizeProp.length();                if (propLen > 0) {                    char lastChar = heapSizeProp.charAt(propLen - 1);                    if ((lastChar == 'K') || (lastChar == 'k')) {                        heapSizeProp = heapSizeProp.substring(0, propLen - 1);                        sizeInKilos = true;                    }                }                try {                    heapSize = Integer.parseInt(heapSizeProp);                    heapSize = sizeInKilos ? heapSize * 1024 : heapSize;                } catch (NumberFormatException e) {                    // ignore the attribute if the value is not valid                }            }        }        return heapSize;    }    /**     * Terminates an isolate.     *     * @param id Isolate Id     */    static void terminateIsolate(int id) {        Isolate isolate = MIDletProxyUtils.getIsolateFromId(id);        if (isolate != null) {            isolate.exit(0);        }    }        /**     * Obtains trusted instance of SecurityToken     *     * @return instance of SecurityToken     */    private static SecurityToken getTrustedToken() {        if (trustedToken == null) {            trustedToken = SecurityInitializer.requestToken(new SecurityTrusted());        }                return trustedToken;    }}

⌨️ 快捷键说明

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