自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

OSGi應(yīng)用中自動啟動bundle

開發(fā) 后端
本文講述OSGi應(yīng)用中如何自動啟動bundle。作者發(fā)現(xiàn)應(yīng)用啟動的時候,幾乎所有 bundle 都處于 Resolved 狀態(tài),而不是 Started 狀態(tài)。本文逐步介紹了如何將所有bundle啟動的方法。

OSGi即Java模塊系統(tǒng),而OSGi bundle則是OSGi中軟件發(fā)布的形式。本文講述OSGi應(yīng)用中如何自動啟動bundle。作者最近開發(fā)了一個 OSGi 的應(yīng)用,部署之后發(fā)現(xiàn),當應(yīng)用啟動的時候,幾乎所有 bundle 都處于 Resolved 狀態(tài),而不是 Started 狀態(tài)。

51CTO編輯推薦:OSGi入門與實踐全攻略

怎樣啟動bundle 呢?有如下幾種方法 :

1. 手工啟動bundle,即在 console 中使用命令 start N 來逐個啟動所有bundle,其中 N 表示每個 bundle 的 id

這種方法過于麻煩,要耗費大量時間,因此不可取。

2.在配置文件中聲明為自動啟動bundle。在 WEB-INF\eclipse\configuration 中的 config.ini 中,如下配置:

osgi.bundles=bundle1@start, bundle2@start,......bundleN@start

這種方法可以自動啟動所有bundle,但是寫起來仍然比較麻煩,需要把所有bundle 一個一個都配置為@start。

3. 在應(yīng)用的所有bundle 中選擇一個bundle,將其在 config.ini 中配置為自動啟動,然后在這個bundle 中,再把

應(yīng)用的所有其他bundle 啟動起來。假定該bundle 的Activator 類為 OSGiStartingBundleActivator, 代碼如下:

  1. public class OSGiStartingBundleActivator implements BundleActivator  
  2. {  
  3.     public static BundleContext bundleContext = null;  
  4.       
  5.     public void start(BundleContext context) throws Exception  
  6.     {  
  7.         bundleContext = context;  
  8.          
  9.         // start bundles if it has been installed and not started  
  10.         Bundle[] allBundles = context.getBundles();  
  11.         for (int i=0; i<allBundles.length; i++)  
  12.         {  
  13.             int currState = allBundles[i].getState();  
  14.             if ( Bundle.ACTIVE != currState && Bundle.RESOLVED==currState  )  
  15.             {  
  16.                     System.out.println("starting bundle : " + allBundles[i].getSymbolicName());  
  17.  
  18.                     try 
  19.                     {  
  20.                             allBundles[i].start();  
  21.                     }  
  22.                     catch (BundleException e)  
  23.                     {  
  24.                             e.printStackTrace();  
  25.                     }  
  26.               }  
  27.           }  
  28.     }  
  29.  
  30.     public void stop(BundleContext context) throws Exception  
  31.     {  
  32.     }  
  33.  }  
  34.  

【編輯推薦】

  1. OSGi入門與實踐全攻略
  2. 你好,OSGi!OSGi入門必讀系列
  3. OSGi與Spring:設(shè)置Spring DM開發(fā)環(huán)境
  4. OSGi和Spring入門:什么是Spring動態(tài)模型(Spring DM)?
  5. OSGi是什么:Java語言的動態(tài)模塊系統(tǒng)
責任編輯:yangsai 來源: 博客園
相關(guān)推薦

2009-09-16 17:15:19

OSGi Bundle

2009-09-17 11:19:34

OSGi依賴性管理

2009-06-16 13:49:53

ServiceMix4OSGi

2012-06-25 11:47:14

ibmdw

2017-09-21 10:43:55

web程序語言

2009-03-03 10:06:00

IBMJavaOSGi

2009-12-21 13:34:41

OSGi

2009-09-28 13:32:39

OSGi入門

2018-05-25 15:26:28

Windows 10Windows自動啟動

2024-06-24 08:24:57

2009-10-15 15:12:39

Equinox服務(wù)器端Equinox

2009-06-10 18:12:38

Equinox動態(tài)化OSGi動態(tài)化

2009-06-01 11:12:34

OSGi規(guī)范架構(gòu)體系結(jié)構(gòu)

2009-10-22 11:03:20

OSGi Web應(yīng)用程

2010-04-07 08:55:00

OSGiSpring

2009-06-18 15:24:08

Spring OSGi

2009-06-01 11:37:46

EquinoxOSGi服務(wù)器

2009-10-19 14:14:19

OSGi Web應(yīng)用

2009-06-18 10:03:57

EquinoxOSGi應(yīng)用服務(wù)器

2009-06-01 11:09:16

OSGI實戰(zhàn)進階
點贊
收藏

51CTO技術(shù)棧公眾號