Osgi Specification

zhaozj2021-02-16  69

Osgi Specification

Osgi is an Open Service Gateway Initiative, the organization is established in 1999, a non-profit organization aimed at establishing an open service specification that establishes an open standard to establish a service to the device through the network.

The OSGI specification includes all aspects of building an open accessible network service, and the OSGi specification includes the following sub-specifications.

Framework Specification (OSGi core, providing a secure manageable Java Framework to deploy scalable Java services.)

Package Admin Service Specification (to manage the reference relationship between different bundles. When it is bundle update or counter-installation, it is determined whether other services are using the current bundle.

Start Level Specification (defined when starting and stoping an OSGi Service Platform, the order of the different bundles starts or stops)

Permission Admin Service Specification (whether bundle is permitted to perform another bundle code)

URL Handlers Service Specification (How to Register URL Schema, how to convert Java.io.InputStream objects to specific Java objects)

Log Service Specification (omitted below ...)

Configuration Admin Service Specification

Device Access Specification

User Admin Service Specification

Io Connector Service Specification

HTTP Service Specification

Preference Service Specification

Wire Admin Service Specification

XML Parser Service Specification

Metatype Specification

Service Tracker Specification

Measurement and state specification

Position Specification

Execution Environment Specfication

Osgi Framework

Framework is the core component of the OSGi Service Platform specification. It provides a universal, safe and manageable Java Framework. With this Framework, you can support deployment and extension of Service Application called bundles.

OSGi compatible devices can download and install OSGi Bundles, or you can delete when they are no longer needed. Bundles will register a certain number of services after installation and is used by other bundles under the same framework.

In a dynamically extended OSGi environment, Framework management bundles installation and update. Also manage the dependencies between bundles and services.

Framework provides the Bundle developer's resources to develop on the Java platform, providing the bundles that the bundles provides code dynamically loaded, which makes developers develop and deploy a large-scale Services change.

Second, Framework provides a concise programming model for Java Bundle developers. Simplified the complexity of development deployment. This programming model allows developers to bind their interface specifications to the service in the OSGi environment. .

A consistent programming model helps developers can cope with some estimated critical errors. Framework will run in different hardware environments, but the consistent interface ensures that the software is running on a consistent service interface. The bundle object

There is a bundle object that is associated with each bundle installed in OSGI Service Platform. A bundle object is used to manage the lifecycle of the bundle. This work is usually made by the management agent.

Bundle State

Bundle has the following state;

Installed - The Bundle Has Been Success Installed. Native Code Clauses Must Have Been Validated.

Resolved - All Java Classes That The Bundle Needs Are Available. This State Indicates That The Bundle Is Either Ready To Be Started or Has Stopped.

Starting - The Bundle is Being Started, And The BundleActivato R. Start Method Has Been Called and Has Not Yet Returned.

Stopping - The bundle is being stopped, and the bundleactivato r. Stop Method Has Been Called and Has Not Yet Returned.

Active - The Bundle Has SuccessFully Started and is Running.

Uninstalled - The Bundle Has Been Uninstalled. It cannot Move Into Another State.

The bundle interface defines the GetState () method to return the state of the bundle.

INSTALLING bundles

BundleContext defines the following two methods to install bundle:

L Instal Lbundle (String) - Installs A Bundle From The Specified Location String (Which Should Be a URL).

L Instal Lbundle (Stri Ng, InputStream) - Installs a bundle from the specified inputstream object.

Every bundle is uniquely identified by a string. If an installed bundle is using this specified location, the installbundle () method must return the original bundle object instead of installing a new bundle. The bundle to be installed must be lasting and installation is fully automated.

When a bundle is installed, Framework will find the Native Code of Bundle dependencies. Bundle cannot be installed if it does not exist.

Once a bundle installation is complete, a bundle object is created. Operations for the life cycle of bundle are completed by this object. Can be used to start, stop, update, uninstall this bundle.

Resolving bundles

When Framework successfully found the Bundle's code dependency, the state of the bundle changed to resolved. Dependencies include:

l ClassPath Dependencies from the bundle's bundle-classpath manifest header.

l Package Dependencies from the bundle's export-package and import-package manifest headers.plugin.xml and manifest control relationship table

Plugin.xml tag / attribute manifest.mf header

Bundle-SymbolicName

Bundle-Version

Bundle-name

Bundle-vendor

Bundle-Activator

FRAGMENT-HOST

FRAGMENT-HOST:

Bundle-Version =

,

REQUIRE-BUNDLE

,

Bundle-ClassPath

Starting bundles

The bundle interface defines the start () method to launch a bundle. If the startup is successful, the status of the bundle becomes Active and keeps this state knows to be stopped.

In order to be started, you must first analyze its dependencies. If the analysis reliance failed, start this bundle, start () method throws a bundleException exception.

If the bundle dependency analysis is successful, the bundle is activated by calling the Bundle Activator object. The BundleActivator interface defines how the method is available for Framework call to start or stop bundle.

Developers can define a bundle-activator manifest header in the bundle's manifest file to tell OSGi Environment as the full name of the files of the Bundle Activator class. This class implements the bundleactivator interface.

For a bundle, it is not necessary to provide a bundle Activator. But only the Bundle's bundlecontext object can be obtained by this method.

BundleActivato offers the following method to start or stop a bundle:

? Start (BundleContext) -. This method can allocate resources that a bundle needs and start threads, and also usually registers the bundle's services If this method does not register any services, the bundle can register the services it needs at a later time, for Example In a Callback, As Long As It Is in The Active State.

? Stop (BundleContext) - This method must undo all the actions of the BundleActivator.star t (BundleContext) method However, it is unnecessary to unregister services or Framework listeners because they must be cleaned up by the Framework anyway..

Stopping bundles

Bundle Interface Defines the stop () method stops a bundle. This method stops a bundle and change the state of the bundle to resolved.

The BundleActivator interface defines the STOP (BundleContext) method, which is called by the framework to stop a bundle. This method must release all resources since the activation. All threads related to the dead bundle must be stopped immediately. The thread code will not use the object related to Framework.

Updating bundles

Bundle Interface defines two ways to update a bundle:

l Update () - This Method Updates a bundle.

l Update (InputStream) - This Method Updates a bundle from the specified input.

The UPDATE process supports a new version of Bundle from a version of bundle. A new bundle and another bundle is compatible backwards.

Framework must ensure that only one version of bundle's CLASS is available at any time. If any package exported by the updated bundle is used by other bundle, then those packages will not be updated. Their old versions will always be retained until org.osgi.Service.Admin.PackageAdmin.RefreshPackages is called or Framework restart.

Uninstalling bundles

Bundle Interface Defines the Uninstall () method to Uninstall in the framework. This method allows Framework to notify other bundles that a bundle has been Uninstalled and sets this bundles' status to Uninstalled.

Osgi & Eclipse

Since the Eclipse RC3 version integrates and implements the OSGi specification. Eclipse is built on the OSGi layer. Plugins becomes OSGi Bundles to be started and stopped. When Eclipse starts, it first converts the original Plugins to OSGi bundles. This makes it possible to install, uninstall, start, and update Plugin at runtime. Although there are still some functions that are not perfect, now we can still run a normal osgi bundles on the Eclipse M6 or updated version. At present, Eclipse does not provide a good environment to debug osgi bundles. The mobile phone manufacturing has also used OSGi specifications in the next generation of Smart Phone, so it will become easier to adjust the mobile phone program in Eclipse.

The Eclipse is a hierarchical structure. The Osgi layer is used as the foundation basis to manage Osgi bundles. The OSGi layer provides the ability to create and deploy OSGi Bundles. Above the OSGi layer is Eclipse Registry. Plugin has joined the concept of extended and extended points. When an OSGI bundle is parsed by an OSGi layer, it will be written to PLUGIN Registry. Plugin Registry is used to manage extensions and extensions. Above the Registry layer is Workbench and Workspace.

Org.eclipse.osgi.internal.resolver.bundleinstaller

Public void installbundle (bundlescription toinstall) THROWS bundleexception;

Public void UninstallBundle (bundlescription TounInstall) THROWS BUNDLEEXCEPTION;

Public void updatebundle (bundlescription Torefresh) THROWS BUNDLEEXCEPTION;

A Bundle Installer Allows The Platform Adminimentation To Delegate The Behavior of Installing / Uninstalling Bundles To Another Object.

Org.eclipse.core.Runtime.Adaptor. EclipseBundleinstaller

EclipseBundleinstaller implemented bundleinstaller interface org.osgi.framework. Bundleactivator

Public Abstract Void Start (BundleContext Context) Throws Exception;

Public Abstract Void Stop (BundleContext Context) Throws Exception;

Org.eclipse.core.Runtime.plugin implements bundleactivator. All PLUGIN must inherit from the Plugin class.

转载请注明原文地址:https://www.9cbs.com/read-14574.html

New Post(0)