AmsUtilpublic class AmsUtil extends Object Implements utilities that are different for SVM and MVM modes.
Utilities to start a MIDlet in a suite. If not the called from the
AMS Isolate the request is forwarded to the AMS Isolate.
See {@link #executeWithArgs}.
In the AMS Isolate, a check is make that the MIDlet is
not already running and is not in the process of starting.
If the MIDlet is already running or is starting the request
returns immediately. See {@link #startMidletCommon}
|
Fields Summary |
---|
private static MIDletExecuteEventProducer | midletExecuteEventProducerCached reference to the MIDletExecuteEventProducer. | private static MIDletControllerEventProducer | midletControllerEventProducerCached reference to the MIDletControllerEventProducer. | private static MIDletProxyList | midletProxyListCached reference to the MIDletProxyList. |
Methods Summary |
---|
static boolean | executeWithArgs(com.sun.midp.midletsuite.MIDletSuiteStorage midletSuiteStorage, int externalAppId, int id, java.lang.String midlet, java.lang.String displayName, java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, int memoryReserved, int memoryTotal, int priority, java.lang.String profileName)Starts a MIDlet in a new Isolate.
if (id == MIDletSuite.UNUSED_SUITE_ID) {
// this was just a cancel request meant for SVM mode
return false;
}
if (midlet == null) {
throw new IllegalArgumentException("MIDlet class cannot be null");
}
if (!MIDletSuiteUtils.isAmsIsolate()) {
/*
* This is not the AMS isolate so send the request to the
* AMS isolate.
*/
midletExecuteEventProducer.sendMIDletExecuteEvent(
externalAppId, id,
midlet, displayName,
arg0, arg1, arg2,
memoryReserved, memoryTotal, priority,
profileName
);
return false;
}
// Don't start the MIDlet if it is already running.
if (midletProxyList.isMidletInList(id, midlet)) {
return false;
}
try {
startMidletCommon(midletSuiteStorage, externalAppId, id, midlet,
displayName, arg0, arg1, arg2,
memoryReserved, memoryTotal, priority,
profileName);
} catch (Throwable t) {
/*
* This method does not throw exceptions for start errors,
* (just like the SVM case), for errors, MVM callers rely on
* start error events.
*/
}
return false;
| static void | initClass(MIDletProxyList theMIDletProxyList, MIDletControllerEventProducer theMidletControllerEventProducer)Initializes AmsUtil class. shall only be called from
MIDletSuiteLoader's main() in MVM AMS isolate
or in SVM main isolate.
No need in security checks since it is package private method.
midletProxyList = theMIDletProxyList;
midletControllerEventProducer = theMidletControllerEventProducer;
IsolateMonitor.initClass(theMIDletProxyList);
StartMIDletMonitor.initClass(theMIDletProxyList);
| static void | initClassInAppIsolate(MIDletExecuteEventProducer theMIDletExecuteEventProducer)Initializes AmsUtil class. shall only be called from
AppIsolateMIDletSuiteLoader's main() in
non-AMS isolates.
No need in security checks since it is package private method.
midletExecuteEventProducer = theMIDletExecuteEventProducer;
| private static Isolate | startMidletCommon(com.sun.midp.midletsuite.MIDletSuiteStorage midletSuiteStorage, int externalAppId, int id, java.lang.String midlet, java.lang.String displayName, java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, int memoryReserved, int memoryTotal, int priority, java.lang.String profileName)Starts a MIDlet in a new Isolate.
Check that the MIDlet is is not realy running and is not already
being started. If so, return immediately.
Isolate isolate;
String[] args = {Integer.toString(id), midlet, displayName, arg0,
arg1, arg2, Integer.toString(externalAppId)};
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};
}
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;
}
}
isolate.setMemoryQuota(reserved, limit);
if (priority >= Isolate.MIN_PRIORITY) {
isolate.setPriority(priority);
}
if (profileName != null) {
IsolateUtil.setProfile(isolate, profileName);
}
isolate.setAPIAccess(true);
isolate.start();
} 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;
| public static Isolate | startMidletInNewIsolate(int id, java.lang.String midlet, java.lang.String displayName, java.lang.String arg0, java.lang.String arg1, java.lang.String arg2)Starts a MIDlet in a new Isolate. Called from the AMS MIDlet suite.
// Note: getMIDletSuiteStorage performs an AMS permission check
return startMidletCommon(MIDletSuiteStorage.getMIDletSuiteStorage(),
0, id, midlet, displayName, arg0, arg1, arg2,
-1, -1, Isolate.MIN_PRIORITY - 1, null);
| static void | terminateIsolate(int id)Terminates an isolate.
Isolate isolate = MIDletProxyUtils.getIsolateFromId(id);
if (isolate != null) {
isolate.exit(0);
}
|
|