Switch: osgi startlevel explained and using startup level mechanism and usage

Source: Internet
Author: User

Osgi startlevel explained and using startup level mechanism and usage

Bundle startlevel

In the actual application environment, our bundle is dependent on each other, so there must be a difference in the startup sequence, such as building a building,
Start from laying the foundation.
In fact, the initial start level of the osgi framework is 0,
The startup sequence is as follows: add one to the startup level. If a matching bundle is found
(That is, the bundle startup level is equal to the current startup level), then the bundle is started;
Continue the first step until you find that all bundle has been started, and the activity startup level is the same as the last startup bundle startup level.

Stop order. First, set the start level of the system to 0:
Because the system's current activity startup level is greater than the requested start level, the system first stops bundle equal to the current activity startup level;
Reduce the activity startup level by one and continue the first step until the activity startup level and request level are found to be equal to 0.

1. Set the system and the startup level of each bundle statically. When the system is started, the osgi framework will follow
Startup level from small to large. If the startup level is the same, the bundle ID is used to start from small to large until the startup level of the system is started.
Animation level.

Configration
Config. ini
Reference \: file \: Bundles/fdsf. Jar @ 4: Start // @ 4: Start is used to set
Osgi. startlevel =
// Static settings the osgi-based application system startup level (not system bundles (SB), SB = 0 forever !), Default
6
Osgi. Bundles. defaultstartlevel =
// Set the start level of each bundles statically. The default value is 4.

Make sure that the startup level of the "Application System" is higher than that of all bundles to make the application system run normally!

Remember:
The system is started at the level from small to large. If the level is equal, it is OK to start at the level from small to large!

2 dynamically set the start level
Dynamically set the startup level of the system and bundle
You can call startlevelservice at runtime to dynamically set the system and the startup levels of each bundle.
Similarly, to use startlevelservice, first open manifest. MF and
Import org. osgi. Service. startlevel,
Get startlevelservice through bundlecontext:
Servicereference serviceref = BC. getservicereference (startlevel. Class. getname ());
Startlevel startlevelsrv = (startlevel) BC. getservice (serviceref );
Startlevel provides a management system and APIs for various bundle startup levels:
?? Getbundlestartlevel (bundle)
Obtain the bundle startup level.
?? Getinitialbundlestartlevel ()
Obtain the default bundle startup level.
?? Getstartlevel ()
Obtain the system startup level.
?? Setbundlestartlevel (bundle, int startlevel)
Set the bundle startup level. If the set startup level is higher than the system startup level, the osgi framework will stop the bundle, as shown in
The Set startup level is lower than the system startup level. If the bundle is not started yet, the osgi framework will start the bundle. If the bundle has been started,
The osgi framework does not perform any action.
?? Setinitialbundlestartlevel (INT startlevel)
Sets the default startup level of the bundle. This default startup level is used for newly installed bundle.
?? Setstartlevel (INT startlevel)
Set the system startup level.
If the set system startup level is the same as the current system startup level, the osgi framework will release the frameworkevent. startlevel_changed event;

If the set system startup level is lower than the current system startup level, the osgi framework degrades the existing startup level by 1,
And stop the corresponding startup level bundle until the set system startup level, when the system startup level and the Set startup level
When the level is consistent, the osgi Framework releases the frameworkevent. startlevel_changed event;
If the set system startup level is higher than the current system startup level, the osgi framework increases the existing startup level by 1,
And start the corresponding startup level bundle until the set system startup level, when the system startup level and the Set startup level
When the level is consistent, the osgi Framework releases the frameworkevent. startlevel_changed event.

 

There are many such applications. A typical example is the pop-up screen before the system starts. You can set its startup level to "lowest "!

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.