Question the role of OSGi

Source: Internet
Author: User

Recently, I have discussed the role of OSGi with other people on cnblogs. Since the people there will only copy the online rhetoric from the Internet over the past n years, and seldom have their own analysis and insights, you cannot start the discussion. I would like to write an article to clarify my point of view and discuss this technology with more people.

 

OSGi is an open service specification proposed by the OSGi alliance established in 1999, initially designed for embedded devices.

According to my information from the Internet, OSGi is currently mainly used for embedded devices, single-host applications without databases, such as Eclipse.

 

Currently, OSGi is mainly used to place a module (OSGi has a special ranking, called bundle ), load it into the memory, run it, and then the control program determines when to detach it from the memory.

This is easy to understand. in Java, ClassLoader is used to load Java classes into the memory, but there is no special means to remove classes that have been loaded into the memory. Programs such as Eclipse have many functions, such as jsp Editor, java editor, and XML editor. They do not need to be started. They all load the classes corresponding to these editors into the memory. It can be delayed and loaded into JVM memory when used. Delayed loading in Java does not require special processing, because this is the case by default: unused classes are not loaded into the memory, and classes used are loaded into the memory only when they are used.

However, Java does not have any special means to uninstall classes that have been run but are not used now. If we open a java file, Eclispe starts the java Editor, closes the java file, opens a CSS file, and Eclispe starts the CSS editor. At this time, we should remove the java editor from the memory, however, Java does not provide this function. Of course we can look forward to Sun/Oracle, which will be available in Java in the future.

Eclipse uses OSGi to implement unused plug-ins and detaches them from the memory, which is good and can save memory. But most of us do not need to do this. Therefore, OSGi is not suitable for most applications.

It is strange that many OSGi fans blindly believe that OSGi can dynamically update versions. As far as I know, if Eclipse updates the plug-in through the network, it needs to restart the entire Eclipse. As these enthusiasts have said, it can be automatically updated without restarting. Maybe, as long as you update a module that is not currently used, you can achieve "automatic update, no need to restart ".

 

Car audios do not play CD and radio at the same timeTherefore, when listening to the CD instead of listening to the radio, the car control program can unload the bundle corresponding to the CD. However, I have never heard of a car manufacturer who said that when a car turns at high speed, the control program in the car is running the brake force intelligent distribution. At this time, you can go through the network, update the software "intelligent braking force distribution.

 

After the Eclipse plug-in is updated, it takes several minutes to restart. Most people can accept the plug-in, but the plug-in will not be upgraded for the time being. During High-speed turns, most people do not choose to update their car software at this time. Unless their minds are not normal, they usually choose to stop, stop, or hold empty files, stay in the bus, and have a cup of coffee, let the 4S store go to upgrade the car software. That is to say, the dynamic upgrade of OSGi in Eclipse and auto software, which is widely known by OSGi fans, is the same.

 

Dynamically Replace the module, provided that no data is lost during running hours; otherwise, it is empty talk.The OSGi official website and documentation never mentioned the replacement of busy modules.. The problem is, do I have to use OSGi to replace a non-busy module? I can stop the application system, update the version, restart the new software version, and have a cup of coffee ,...

Some people have mentioned the Dynamic Replacement of telecommunication software. Is the module of telecommunication software not busy?

 

Database applications can be used to solve dependencies between modules.: Module A reads data from table 1. After processing, it inserts data into Table 2. Module B reads data from table 2. After processing, it inserts data into table 3. On the surface, the two modules depend on each other. However, if we use independent java.exe to run module A and Module B, we can close module A for several minutes and start it without affecting Module B.
That is to say, there are database applications and dependencies between modules, and there are additional solutions. This solution does not need to set any standards or learn any new knowledge. In a word: easy!

 

This is also the reason why OSGi is only used in a database-free system.. Unfortunately, many people do not see this.

 

Here is a piece of funny words (http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-osgi ):

In addition to modularity and service-oriented programming, another important feature of OSGi is its dynamic nature. Bundle and the services provided by Bundle can be removed or rejoined at any time, other service Bundle can perceive whether the service is available and dynamically change its behavior.

The funny thing is that "other service Bundle can perceive whether the service is available and dynamically change their behavior .", If I want to call a fax sending module and the "send fax module" is unavailable, what can the program do next? ? Niang? Crying? Invocation? It is inappropriate to do anything!

Without OSGi, I do not need to "perceive" whether other modules are available and call them directly. If an error occurs, an error is returned. The program logic is clear and simple. After OSGi is added, I need to "perceive" whether other modules are available and "dynamically change my behavior". This is complicated, troublesome, and uncomfortable! If each module needs to "perceive" OtherVariousWhether the module is available or not, you need to determine how to deal with various additional situations, what a geometric level of complexity! This is what people do! This is the trouble of OSGi!

I think OSGi only does one thing at present: it does not work well with Java's unload class function. Considering that the current memory is so cheap, 4 GB memory is everywhere, and the memory of mobile phones is also growing steadily, the memory of other embedded devices is also growing. Is it necessary to unload unnecessary classes! After all, not a lot of software can make the computer memory burst.

 

It is strange that many people are playing OSGi and think it is 10 thousand gold, which can be used everywhere. I really don't know what these people think.

In addition, even useful things depend on the cost of use. The Mercedes-Benz is so good that everyone can buy a Mercedes-Benz? Is it negligible if OSGi Program Development and debugging are difficult and it takes time to learn?

 

As for OSGi, it is even more complicated to solve the modular dependency problem. Big deal I use a java.exe to run each "module" separately. Is there any dependency problem? What is the need to use OSGi?

 

SupplementMany people have mentioned Eclipse in their replies. It seems that Eclipse uses OSGi because OSGi is very powerful. However, from this article, we can see that this is not the case:

OSGi: the foundation of Eclipse

Http://www.builder.com.cn/2007/0929/528796.shtml

Many people have asked why Eclipse should be compatible with OSGI specifications instead of other ones?
Before Eclipse was donated, Eclipse was developed by OTI to develop an embedded Java software development platform. On the Internet, many connections still direct to Visual Age Micro Edition (VAME). This is also one reason why SWT is conceived and they want to use SWT in the user interface of embedded devices. This relationship explains why OSGI specifications were selected at the time.
Another reason is that there are no other specifications except OSGI...

...

 

, Add:

In the http://zh.wikipedia.org/wiki/OSGi, it states: "OSGi was originally focused on service gateways, in fact, can be used in multiple aspects. Currently, OSGi specifications have been used from mobile phones to open-source Eclipse (including open-source versions compatible with IBM's OSGi framework SMF ). OSGi service platform applications include service gateways, automobiles, mobile phones, industrial automation, building automation, PDA grid computing, Entertainment (such as iPronto), and IDE .". Database applications and enterprise applications are not mentioned. On the English version of the http://en.wikipedia.org/wiki/OSGi page, the same thing.

So far, what major companies have used OSGi in a database system? No! I don't understand which nerve is wrong when so many people use OSGi in their own database system.

 

==== You are welcome to reprint it. Please indicate the source for reprinting.

Welcome to download the trial of the Single Sign-on system, http://zheguisoft.com

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.