Enterprise J2ME Developing Mobile Java Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Enterprise J2ME Developing Mobile Java Applications [Electronic resources] - نسخه متنی

Michael Juntao Yuan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



4.2 OSGi Containers


The OSGi Alliance is an industry consortium that creates open standard specifications for network-delivered services. Founded in March 1999, OSGi is a nonprofit organization with open membership. Its board of directors includes Acunia, BMW, Deutsche Telekom, Echelon, Gatespace, IBM, Motorola, Oracle, Philips, ProSyst, Samsung, Sun and Telcordia. The OSGi specification defines the mobile container framework and standard container services as Java APIs that span from J2ME to J2SE to J2EE.

The OSGi Service Platform Release 2 specification was released in October 2001. It has been widely adopted by vendors and has many implementations. The OSGi Service Platform Release 3 specification was made available in March 2003. The IBM Services Management Framework (SMF) v3.5 is targeted to be OSGi R3 compatible. It is available for free evaluation from the IBM Web site (see "Resources"). We discuss both Release 2 and 3 in this chapter. However, all examples are written for and tested on Release 2 containers.

Note

Despite the term Gateway in its name, the OSGi specification does not define any particular kind of gateway servers. It defines a framework for service components delivery and execution. The OSGi container provides the runtime environment for those services. Gateway server is only one of OSGi's application areas.


4.2.1 Bundles


OSGi applications are packaged as bundles, which are just standard JAR files. The OSGi bundle is completely self-contained with all the necessary metadata in its manifest file. The OSGi container completely manages the bundle life cycle:

Install, update, and uninstall the bundle.

Start and stop the bundle.

Register, unregister, and track services in the bundle.


The bundle management interfaces are defined in the org.osgi.framework package. Since the bundles can be deployed to the container dynamically without restarting the container, the OSGi platform is an ideal choice for mobile application provisioning clients. It allows applications to be managed, tracked, and updated throughout its lifetime.


4.2.2 Standard Services


The OSGi container provides common crosscutting services such as device drivers, user preferences, and logging to all its bundles. Table 4.1 lists the OSGi services defined in OSGi Service Platform Release 2 specification. The new OSGi Service Platform Release 3 specification defines more services, some of which are of great importance to mobile applications. Those new services are listed in Table 4.2.

Table 4.1. OSGi Services in OSGi Service Platform Release 2 Specification (org.osgi.*)

Java package

Description

service.http

The HTTP service responds to HTTP requests. The service listens on ports specified in the container configuration. It dispatches each HTTP request to a handling servlet based on an URL-to-servlet mapping table registered by individual bundles. Finally, it returns the servlet's response to the HTTP requester. The service also handles HTML content without the help of a servlet.

service.device

The device service manages custom device adaptors. It allows bundle developers to plug in device drivers and develop algorithms to match devices to drivers. This service allows the OSGi bundles to respond to many different types of client devices.

service.prefs

The preference service manages a hierarchical collection of preference data resembling the JDK v1.4 preference API. It is much more advanced than simple Java property files.

service.useradmin

The user administration service provides role-based authorization service. It manages user credentials and user groups.

service.permissionadmin

The permission service allows operators to manage bundle permissions.

service.packageadmin

The package administration service manages Java packages exported by bundles (see Section 4.2.3 for exported packages).

service.metatype

The metatype service provides a mechanism for bundles to expose their configuration metadata.

service.cm

The configuration manager service administrates bundle configurations.

service.log

The logging service logs messages during the bundle execution. We can extend the basic logging service interface for custom logging needs.

util.tracker

The ServiceTracker class in this package provides easy ways to use and manage the container's service registry.

Table 4.2. New OSGi Services in OSGi Service Platform Release 3 Specification (org.osgi.*)

Java package

Description

service.startlevel

A policy service that allows the developer to specify the startup and shutdown sequence of bundles.

service.url

This service allows bundles to register URL schemes with content types and provide content handlers for the registered types.

util.xml

This is a utility service that allows bundles to use JAXP, SAX, and DOM XML parsers. Each parser interface can have multiple implementations.

service.wireadmin

It supports a convenient way to connect data producers and consumers. Two utility classes are commonly used with the wireadmin service to handle measurement-related (e.g., error calculation and unit conversion) and position related (location, speed, orientation) data.

service.io

This service allows bundles to handle arbitrary network protocols using the J2ME Generic Connection Framework (GCF). Since the GCF is a layered and abstract framework, bundles only need to extend the abstract connection factory to return the correct connection class based on the URL string format.

service.upnp

This service makes OSGi bundles transparently available to universal plug-and-play networks.

service.jini

This service allows OSGi bundles to interact with Jini network services.


4.2.3 Bundle Interaction and Custom Services


The OSGi framework provides powerful ways for bundles to interact with each other. This encourages code reuse and makes it easier to architect complex multilayer applications. For example, the OSGi container on a stock trader's PDA might be provisioned with services bundles from major exchanges. Each bundle knows how to run real-time queries and execute trades in a specific exchange market, and it makes those functionalities available to other bundles. The trader can then deploy the actual trading client bundle, which provides a user interface, supports custom trade logic, and executes the query/trade through the individual service bundles. The possible interactions among bundles are as follows.

Static sharing: The OSGi container runs on a single JVM instance but has a different classloader for each bundle. That means bundle namespaces are separate. We cannot directly access objects or classes in another bundle by default. However, a bundle can explicitly export some of its Java packages through the Export-Package attribute in its manifest file. It can also import Java packages exported by others using the Import-Package manifest attribute. The export and import features allow direct sharing of Java packages.

Dynamic services: In addition to standard services provided by the container, any bundle can consume and provide services from/to other bundles at the same time:

A bundle can dynamically register (or unregister) services with the container. The bundle needs to register the service interface with a concrete implementation class. Any change to the service (register, modify, unregister) will result in framework events that could be captured and processed.

Another bundle finds the service reference through a lookup API in the framework. It calls a framework method to obtain the service implementation object from the service provider bundle. The service object is now ready to use.


The interacting bundles allow us to deliver reusable services to any OSGi node, from the high function grid to pervasive devices.


4.2.4 OSGi Runtime Requirements


Currently, different OSGi vendors have different requirements for their products. The required execution environments range from PersonalJava v1.1 to J2SE. This has created considerable confusion in the developer community. In an effort to standardize the runtime requirements, the OSGi Service Platform Release 3 specification formally defines the following runtime environments:

The Java 2 Micro Edition: All OSGi implementations should run under the CDC v1.0 plus Foundation Profile v1.0 runtime environment.

The OSGi minimum execution environment: The specification also defines a subset of CDC/FP APIs, which allows devices not powerful enough for the CDC/FP (e.g., Palm PDAs) to run the OSGi framework. The OSGi minimum execution environment is defined to be a proper subset of CDC/FP and J2SE.


The standard execution environments make it easier for developers, especially resource-conscious mobile developers, to choose the right OSGi product.


/ 204