A simple example of developing OSGi based on eclipse

Source: Internet
Author: User

<?xml:namespace prefix = o/>

A simple example of developing OSGi based on Eclipse


A. Overview

OSGI SERVICE PLATFORM is a Java-based, open and unified Interface Standard Architecture Framework,

The deployment of all modules in OSGi must be deployed in a bundle manner. Based on this framework, service providers, program developers, software providers, service management operators, and device providers can jointly develop, deploy, and manage the various services provided to users in a coordinated manner.

(a) Advantages of OSGI:

1. Plug-in hot-swappable to enable dynamic software upgrades

2. The maintenance of code is advantageous to the maintenance of code by maintaining the dependencies of different bundles only on the interface level.

3. Stable and efficient system

OSGi-based systems use a micro-core mechanism, micro-core mechanism to ensure the stability of the system, micro-core mechanism of the system as long as the micro-core is stable operation, then the system will not crash, that is, OSGi-based systems are not affected by the bundle running in it, will not cause the whole system to collapse because of the bundle's collapse.

4. Standard, Cumulative modules

Most software companies can not form a standard module development method, because there is no unified specification of the definition of the infrastructure system, often each project, each product will be due to the architect's preferences, technology development and lead to the development of modules completely different, which makes the software company in personnel skills requirements, training is difficult to form a unified, OSGi provides a solution to this problem, and OSGi-based systems use a standardized module development and deployment approach to build systems.

(b) Bundle Partitioning Rules

 

When using OSGi technology to implement the application system, the final presentation will be a bundle component in front of us, then an application system should be divided into several bundles appropriate. This involves the realization of the granularity problem of bundle partitioning. I prefer to divide by hierarchy, the following example development will be the use of this structure division.

Divide by hierarchy:

<1>services Bundle: In OSGi, services are defined through Java interfaces, which can be used to compose a service bundle of Java interfaces that define services, and this bundle provides interfaces to other bundles.

<2> Service Provider Bundle: Implements the interface provided by the services bundle and registers the service with the OSGi framework.

<3> Service User bundle: References the interfaces provided by the services bundle and requests the appropriate services from the OSGi framework.

two. Examples of development using SPRINGDM

a) environmental Construction

I. Adding a spring environment

Download Spring dynamic module, the current version is 1.0-RC2. Place the following jar under the Eclipse/plugins directory.

Spring-osgi-core-1.0-rc2.jar

Spring-osgi-io-1.0-rc2.jar

Spring-osgi-extender-1.0-rc2.jar

II. Add SPRING-OSGI Environment (SPRINGDM)

Download Spring, current version 2.5.1, and place the following jar under the Eclipse/plugins directory.

Spring-beans-2.5.1.jar

Spring-aop-2.5.1.jar (dependent on Aopalliance.osgi-1.0-snapshot.jar)

Spring-core-2.5.1.jar

Spring-context-2.5.1.jar

Restart Eclipse, and in the run options, tick the newly added bundles.

b) Create a plug-in project

I. Steps:

1. Create a plug-in project

<?xml:namespace prefix = v/>

2. Select the An OSGI framework and choose the standard way, I recommend using the standardized way, because we can not be limited to Equinox, can be deployed to other standards of OSGi container.

3. We do not generate activator here, because the SPRINGDM method is used, and the work is given to spring.

c) The above three steps are basically the same when building each bundle, and we're going to analyze the build process for each of these three bundles one at a time.

I. Creating a service Bundle definition class

1. Defining the interface

Public Interface Mysercice {

Public String Gethello ();

}

2. Open the runtime node of the MANIFEST.MF file and export the interface to other bundles for import.

Ii. Building Serviceimpl Bundle Implementation class

1. Open the Dependencies node of the MANIFEST.MF file and import the interface that you just defined.

2. Defining an interface implementation class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.