Osgi in action Reading Notes Chapter 1

Source: Internet
Author: User

Original URL: http://sangmin214.iteye.com/blog/781600

Chapter 1 osgi

This book first points out that Java does not explicitly provide support for building modular systems, but only common Object-oriented Data encapsulation. Therefore, developers often need to make up for this. To make up for this and let application developers focus on application development, the osgi Service Platform came into being. Osgi is an industrial standard defined by the osgi alliance to address Java's lack of modular support. In addition, it introduces a new service-oriented programming model, also known as "SOA in virtual machines ".

 

1.1 What is osgi and why osgi is used

In short, osgi is the Module layer on the Java platform. What is a module? A module is the logical unit of a software application and is responsible for implementation. To clarify why osgi is used, this book first describes Java's shortcomings in modularization and then describes how osgi can make up for it.

 

1.1.1 limitations of Java in Modularization

Control of lower-Layer Code visibility

Although Java provides some control modifiers, such as public, protected, private, or default access in the package, they are all used to control the encapsulation of these low-level data objects, instead of solving the division of logical units of the system. Java uses the package keyword to separate code, but only code declared as public can be accessed from another package (if it is an inheritance relationship, the protected code can be accessed ). So if the application code is distributed in different packages and they need to access each other, you must set those methods to public so that anyone can access them. In addition, this exposes the implementation details of the interface. If you want to modify the implementation in the future, you need to consider many things (many code that calls the implementation code directly may also need to be modified ).

The nested packages in Java seem to have a logical relationship. Actually, they are not. They are two different packages. That is, org. foo and org. foo. hello, these two packages are two, and they do not seem to have an inheritance relationship, org. foo. generally, classes in Hello can only access Org. public class in Foo. This nested package is only used to avoid package name conflicts, although it provides some logic code segmentation.

Therefore, in Java

1. to prevent exposure of APIs that you do not want to disclose, you can put as much code as possible in the same package (weaken the logical structure of the Application), or

2. Use multiple packages and expose the corresponding APIs to ensure the logical structure of the application.

 

Error-prone class path

Java uses classpath to find the desired class, regardless of the version, dependency, and consistency of the code. It always uses the class it first finds. Therefore, you need to constantly add the database until the virtual machine stops complaining that the class cannot be found. In relatively large applications, different components may use different versions of the same component. If different versions used are incompatible, problems may occur.

 

Limited deployment and management support

Java lacks tools to deploy and manage your applications. Although you can use the classloader to implement dynamic insertion, the classloader itself is not a common tool for application developers.

 

1.1.2 what does osgi do for you?

Osgi checks the dependencies of your code before running your code. osgi checks the dependencies and consistency of libraries in the class path, you can package and deploy the classes you need (excluding the classes you don't need), and you can clearly control the interfaces you want to expose, osgi provides powerful scaling mechanisms (as well as dynamic runtime)

 

1.2 osgi Overview

The osgi service platform consists of the osgi framework and osgi standard services. The osgi framework is the runtime environment that implements and provides osgi functions. The osgi standard service defines reusable interfaces for some common tasks.

 

1.2.1 osgi framework

The osgi Alliance defines osgi specifications, which can then be implemented by a third party. The well-known open-source implementations include Apache Felix, eclipse equinox, and knopflerfish. The osgi specification divides the framework into three layers: The Module layer, the lifecycle layer, and the service layer.

 

[I feel that my reading notes are too detailed and I have no idea. I will abstract them from below in combination with my own understanding]

 

1.2.2 Module layer

The Module layer defines the osgi module concept, called bundle, which is actually a jar file and additional metadata. A bundle contains your class and related resource files. Budle is more powerful than a common JAR file. You can specify which classes can be accessed externally. In this regard, bundle extends the common access modifier (public, private, protected ). Another strength is that you can clearly declare which external packages your bundle depends on. The benefit of explicitly declaring the classes provided by bundle to external access and the classes dependent on bundle is that the osgi framework can automatically manage and verify the consistency of your budles. This process is also called budle parsing.

 

1.2.3 lifecycle Layer

The lifecycle layer defines how bundle can be dynamically installed and managed in the osgi framework. The lifecycle layer provides two different functions. Outside your program, the lifecycle layer precisely defines bundle lifecycle operations, such as installation, update, start, stop, and uninstall. These operations allow you to dynamically manage your applications. Your bundle can be securely added to or removed from the framework, rather than restarting the application process. Within your program, the lifecycle layer provides a way to interact with the osgi framework and to use the facilities provided by the osgi framework at runtime.

 

1.2.4 service layer

Similar to the popular SOA, this layer is service-oriented release, search, and binding: service providers publish their services to a service registration department, the customer of the Service finds the Service Registration and does not obtain the service for use.

 

1.2.5 combine three layers

The osgi framework consists of these three layers. How can we use these three layers in application development? To create an osgi-based application, follow these steps:

1. design your application into an interface-oriented client that uses these interfaces

2. Use your favorite tools and methods to implement service providers and user Components

3. Package Service Providers and user components respectively, and configure the corresponding osgi metadata

4. Start your osgi framework

5. Install and start your components (service providers and user components)

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.