A central requirement for KVM in most target devices is to be able to execute applications that have been downloaded dynamically from the network. Once downloaded, the user commonly wants to use the applications several times before deleting them. The process of downloading, installing, inspecting, launching and uninstalling of Java applications is referred to generally as application management. In typical desktop computing environments, these tasks can be performed by utilizing the facilities of the host operating system. However, the situation is very different in many small, resource-constrained devices which often lack even basic facilities such as a built-in file system.
To facilitate the porting of KVM to small, resource-constrained platforms, KVM implementation contains an optional component called Java Application Manager (JAM) that can be used as a starting point for machine-specific implementations.
At the compilation level, JAM can be turned on or off by using the flag
When building the KVM using gnumake, the following command automatically builds the system with the JAM enabled:
This section provides a brief overview of the JAM reference implementation provided with KVM. The description below assumes that the target device has some kind of a “microbrowser” that can be used for initiating the downloading of applications. This microbrowser is commonly provided as part of the native computing environment, but it can also be part of the JAM in some implementations.
Java Application Manager is a native C application that is responsible for downloading, installing, inspecting, launching, and uninstalling Java applications.
From the user’s viewpoint, the JAM is typically used as follows:
.jam
file extension, is a text file consisting of name/value pairs. The purpose of this file is to allow the JAM to decide, before it tries to download it, whether the Java application the user selected can be installed successfully on the device. This saves the user the cost of moving the Java application to the device if it cannot be installed. The Descriptor File is small (several hundred bytes), while a typical Java application is from 10 to 20 kilobytes, so it is much cheaper to download the Descriptor File rather than the entire Java application.JAR-File-Size
tag of the Java application to ensure that there is sufficient space on the device to save it.JAR-File-URL
tag in the descriptor file to get the URL of the JAR file (it may use the base URL to the Descriptor File, if the JAR-File-URL
tag is a relative URL) and start the download process using HTTP. The JAM then stores the JAR file on the device. The absolute URL and the version number are used to uniquely identify an application during application update (see next subsection.)
In the reference implementation of the JAM, the user is shown the list of installed Java applications on the device, with the recently installed application selected for execution.
However, if the Use-Once
tag is set to yes, JAM does not add the application to the list, and it launches the application immediately.
Here’s a typical use case for launching a Java application:
main
class of the application. The KVM initializes the main
class and starts executing it. As additional classes are required for the execution of the application, the KVM uses a manufacturer-defined API to unpack and load the class files from the stored JAR file.Use-Once
tag in the Descriptor File is set to YES
, the JAM removes the JAR file.When the content provider updates an application (for example, to fix bugs or add new features), the content provider should do the following:
JAR-File-URL
tag as the previous version of the application.
When the user requests the installation of an application, the JAM checks if the application's JAR-File-URL
is the same as one of the installed applications. If so, and the Application-Version of the requested version is newer than the installed version, the JAM prompts for user approval before downloading and installing the newer version of the application.
The reference implementation uses a string to specify the version number in the following format:
Major.Minor[.Micro]
(X.X[.X])
, where the .Micro
portion is optional (it defaults to “0”). In addition, each portion of the version number is allowed to a maximum of 2 decimal digits (that is, the range is from 0 to 99.)
For example, “1.0.0” can be used to specify the first version of an application. For each portion of the version number, leading zeros are not significant. For example, “08” is equivalent to “8”. Also, “1.0” is equivalent to “1.0.0”. However, “1.1” is equivalent to “1.1.0”, and not “1.0.1”.
In the reference implementation, missing Application-Version tag is assumed to be “0.0.0”, which means that any non-zero version number is considered as a newer version of the application.
The JAM must ensure that if the application update fails for any reason, the older version is left intact on the device. When the update is successful, the older version of the application is removed.
The JAM, its data, and associated libraries, should be stored securely on the device. The device manufacturer must ensure that these components cannot be modified by Java applications or other downloadable content.
JAR files are a standard feature of Java technology designed to hold class files and application resource data in a compressed format. JAM-compliant JAR files hold exactly one Java application and its associated resources. Compressed JAR files reduce the size of the application by approximately 40% to 50%. This both reduces the storage requirements on the device and reduces the download time for the application. Items in the JAR file are unpacked as required by the JAM.
The Application Descriptor File is a readable text file. It consists of name-value pairs that describe the important aspects of its associated Java application. It is referenced from a tag on a content provider's web page. It is created and maintained by the Java application developer and stored along with its application JAR file on the same web site. Developers may create this file with any text editor.
The Descriptor File has the following entries (tag names are case sensitive):
Displayable text, limited to width of screen on the device
Major.Minor[.Micro] (X.X[.X]
, where X
is a 1 or 2 digit decimal number, and the .Micro
part is optional)
Comma separated list of KVM version strings as defined in the CLDC microedition.configuration system property (see CLDC Specification).
“CLDC-1.0” is an example of the KVM version string. The items in the list are matched against the KVM version string on the device, and an exact match is required to execute this application. Any item matching the KVM version string on the device satisfies this condition. For example, “CLDC-1.0, CLDC-1.0.3” runs on either version of KVM on the device.
Text name of the application's Main class in standard Java format.
Integer in bytes
Standard URL text format to specify the source URL. If this is a relative URL, then the URL to the Descriptor File is the base URL.
yes/no
Standard URL text format, used by the browser to access help pages
Additional requirements and restrictions:
application/x-jam
and the extension is .jam
.The application developer may add any application specific name-value pairs to the Descriptor File. This allows the application to be configured at deployment by changing the values in the Descriptor File. So, different Descriptor Files could use the same application JAR file, with different application parameters.
The format of the tag is a string, but it is recommended that it follow a similar style as the tags defined in the above table. The format of the value is an application specific string.
A simple proposed API to retrieve the value via the JAM could be:
Whenever a Java application tries to make an HTTP connection, the networking implementation should check with the JAM to find the name of the server where the application was downloaded. This ensures that the connection is made to the same server the application came from. A string comparison is made between the host name in both the URLs.
The lifecycle of a Java application is defined to be the following:
Main-Class
entry of the Descriptor File.)The term task is used loosely to describe the KVM as a logically distinct execution unit. In actual devices, the KVM task can be implemented as a task, a process or a thread of the underlying operating system.
The API functions for controlling the lifecycle of the KVM are not specified, as the mechanism is vastly different from platform to platform. Instead, it is required that all JAM implementations support the following features:
main
class of the Java application.The KVM task can be terminated in two ways: voluntarily or involuntarily.
The application can voluntarily terminate itself by calling the Java method System.exit
. Under certain conditions, the JAM may decide to force the KVM to terminate. The exact method of triggering forced termination is platform dependent. For example, the JAM may spawn a watchdog thread that wakes up after a certain period. If the watchdog thread detects that the KVM has not terminated voluntarily, it forces the KVM to terminate.
During forced termination, the JAM actively frees all resources allocated by the KVM and terminates the KVM task. The exact procedure is platform dependent. On some platforms, calling exit
or kill
may be enough. On other platforms, more elaborate clean-up may be required.
The JAM is responsible for handling all errors encountered in installing and launching Java applications. The method of handling errors differs from implementation to implementation, but the JAM should be able to interact with the user to resolve the error if possible. To assist in this, the Descriptor File has a tag called Help-Page-URL
that is set by the content provider. The JAM may decide that under certain conditions, the browser should be invoked and the user sent to the help page. The help page could have information that would allow the user to contact the content provider for additional assistance.
The following are a set of possible error conditions and sample messages that can be displayed to describe the error to the user. Manufacturers should design the messages so that they are appropriate to their device user interface.
“NAMEOFAPP” is too large to run on this device and cannot be installed.
There is not enough room to install. Try removing an application and trying again.
“NAMEOFAPP” is already installed. (Soft buttons should be labeled OK and Launch. Launch would run the existing application on the device.)
“NAMEOFAPP” won't work on this device. Choose another application. (Soft button label = Back, Done.)
The installation failed. Contact your ISP for help.
The URL for “NAMEOFAPP” is invalid. Contact your ISP for help.
“NAMEOFAPP” does not match its description and may be invalid. Contact your ISP for help.
The connection dropped and the installation did not complete. Please try installing again. [Soft button label = Install, Back]
The JAM should check the version # of both versions and present a decision to the user.
Cannot launch “NAMEOFAPP”. Contact your ISP for help.
Cannot save data. Contact your ISP for help.
“NAMEOFAPP” has unexpectedly quit.
KVM Porting Guide , CLDC 1.1 |
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.