4.1 Container-Managed ApplicationsIn the field of software engineering, the term container refers to specialized software that runs other software. For example,The MIDP Application Management Software (AMS) is a container that installs, starts, pauses, stops, updates, and deletes MIDlet applications. In the CDC Personal Basis Profile, the Xlet programming model also features container-managed life-cycle methods.A Java servlet engine is a container that invokes servlets and provides access to the HTTP context.The Java Virtual Machine (JVM) itself is a container. It monitors Java applications for proper memory usage (garbage collector) and security. In the next two sections, we will discuss the features and benefits of mobile containers. 4.1.1 Container FeaturesAs mobile enterprise applications become mainstream, the complexity of smart clients grows. For example, fully commercial applications often require features such as user login, logging, transaction, and transparent data access. Without proper tools for code and service reuse, mobile developers have to duplicate those functionalities for every smart client. Wasting time reinventing the wheel is not only inefficient but also causes error-prone code.
In this book, we use the term container rather loosely. Our containers do not impose arbitrary boundaries for API usages. Applications installed inside the container can transparently access any Java or native API available on the device. These containers are often known as frameworks. The container architecture on J2ME mobile devices is illustrated in Figure 4.1. Figure 4.1. The container architecture for J2ME smart clients.![]() 4.1.2 Benefits of ContainersThe above container features translate to real benefits in mobile development projects:Reduced code redundancy: Since the common services are not repeatedly implemented, we can reduce overall footprint and potential number of errors while improving the developer productivity.Managed update: When we fix a bug or add a new feature in a service, all applications that use it automatically get the update. Some containers support service versioning for more refined controls.Support for multitiered application models: Services in a container offer natural separations between application tiers (e.g., the presentation and business layers).Simplified application provisioning: Self-contained applications can be easily deployed to any container. That enhances Java's value proposition of "write once, run anywhere." Given these benefits, containers or frameworks are widely used in mobile Java application development. In the next section, we introduce a standard container specification for lightweight mobile devices: the OSGi specification. NoteEvery MIDP device comes with the AMS container for provisioning, security, and life-cycle management. However, the MIDP platform is too resource-constrained to run any more advanced containers. As a result, the containers we discuss in this chapter require at least J2ME/CDC or PersonalJava runtimes. |