<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    yangbutao

     

    2007年8月14日

    淺析擴(kuò)展點(diǎn)(Extension Point)

         摘要: 擴(kuò)展(Extension)是很多可擴(kuò)展項(xiàng)目中一個(gè)關(guān)鍵的機(jī)制,可以利用擴(kuò)展向平臺(tái)添加新功能。但是擴(kuò)展不能隨意地創(chuàng)建,必須按照擴(kuò)展點(diǎn)(Extension Point)定義的規(guī)范進(jìn)行明確的聲明,平臺(tái)才能識(shí)別出這些擴(kuò)展。所謂擴(kuò)展點(diǎn),就是系統(tǒng)定義出來(lái)可以讓你擴(kuò)展的地方,可以認(rèn)為是一些擴(kuò)展的契約,而擴(kuò)展,這是你對(duì)這些擴(kuò)展點(diǎn)的實(shí)現(xiàn),當(dāng)然你自己的插件也可以定義擴(kuò)展點(diǎn)供別的開發(fā)人員擴(kuò)展。  閱讀全文

    posted @ 2007-09-27 09:09 阿不 閱讀(12002) | 評(píng)論 (0)編輯 收藏

    OSGI Module&lifecycle

                                                               OSGI Module&lifecycle
     
    OSGI概念中主要分為了Bundle和Service,可以認(rèn)為Bundle是一個(gè)模塊的管理器,主要是通過(guò)BundleActivator管理模塊的生命周期,而Service則是這個(gè)模塊可暴露對(duì)外的服務(wù)對(duì)象,這里體現(xiàn)了OSGI和傳統(tǒng)的Plugin Framework不同的一個(gè)地方,管理和靜態(tài)結(jié)構(gòu)分開,在OSGI中通過(guò)在manifest.mf文件中增加一些內(nèi)容來(lái)發(fā)布Bundle,在其中描述了Bundle的提供商、版本、唯一ID、classpath、暴露對(duì)外的包、所依賴的包;每個(gè)Bundle擁有自己的ClassLoader以及context,通過(guò)context可進(jìn)行服務(wù)的注冊(cè)、卸載等,這些操作都會(huì)通過(guò)事件機(jī)制廣播給相應(yīng)的其他的Bundle;一般來(lái)說(shuō)都為通過(guò)在Bundle中編寫初始需要注冊(cè)的服務(wù)的方法來(lái)完成Bundle可供外部使用的服務(wù)的暴露功能;如需要調(diào)用其他Plugin提供的服務(wù)可通過(guò)context的getServiceReference先獲取Service的句柄,再通過(guò)context.getService(ServiceReference)的方法獲取Service的實(shí)體。
    前一段時(shí)間對(duì)osgi的service層做了介紹,下面介紹module和lifecycle層,在這里主要介紹lifecycle
    系統(tǒng)框架對(duì)bundle的生命周期進(jìn)行了管理。
    osgi生命周期的管理,覆蓋到bundle的安裝,啟動(dòng),停止,更新,卸載,和監(jiān)控這么一個(gè)過(guò)程。
    Bundle的生命周期
    下面是bundle的lifecycle的類圖
    下面詳細(xì)介紹bundle的幾個(gè)對(duì)象
     
    l         Bunlde 標(biāo)識(shí)
     Identifier
     Location
     symbolicName
    l         bundle的狀態(tài)
      狀態(tài)轉(zhuǎn)換圖
    ü         bundle的安裝一般有兩種方式:
    通過(guò)另外一個(gè)bundle的bundlecontext來(lái)完成
    通過(guò)命令行的形式(比如系統(tǒng)bundle一般是這樣的)來(lái)完成的
    ü         Bundle的解析(一般是在啟動(dòng)過(guò)程中完成的)
    根據(jù)bundle的定義,創(chuàng)建基于版本的module(ModuleDefinitionContentLoaderWire
    ü         Bundle的啟動(dòng),由該bundle的調(diào)用start api來(lái)完成的
          這里包含創(chuàng)建該bundle的上下文(BundleContext)
          創(chuàng)建該bundle的activator,可以在activator里進(jìn)行與該bundle相關(guān)的service的注冊(cè),bundlelistener,servicelistener ,frameworklistener的注冊(cè)以及安裝其他的bundle.等.
          是否要立即觸發(fā)該activator,需要根據(jù)該bundle的activator policy來(lái)決定;在用bundle獲取resource的時(shí)候,采取解析bundle,才創(chuàng)建該bundle的classloader和activate該bundle。這樣能節(jié)省啟動(dòng)的時(shí)間,實(shí)現(xiàn)了懶加載。
    下圖描述了bundle的啟動(dòng)過(guò)程中的狀態(tài)變化
    ü         Bundle的更新
    Bundle的更新,是從一個(gè)版本到另一個(gè)版本的遷移過(guò)程
    流程如下:
    1.  檢查bundle的狀態(tài)
    如果是uninsalled,拋出異常
    2.  ,但是不改變持久化的狀態(tài)Stop bundle
    3.  版本的修訂
    4.  更改bundle的時(shí)間戳,狀態(tài)設(shè)置成installed
    5.  發(fā)送unresolved事件給bundle
    6.  把該bundle的老的module做一個(gè)removal標(biāo)記,表示不可用
    7.  發(fā)送updated事件給bundle
    8.  啟動(dòng)(start)bundle
       
    ü         Bundle的停止
    1.  把bundle的持久化狀態(tài)設(shè)置成inactive
    2.  檢查bundle的狀態(tài)
    如果狀態(tài)是Installed,Resolved,就返回
    如果是uninstalled,拋出異常
    如果是starting,stopping,拋異常
    如果ACTIVE,把bundle的狀態(tài)設(shè)置成stopping,發(fā)stopping事件跟響應(yīng)的bundle
    3.  調(diào)用該bundle的activator的stop操作,清理分配的資源
    4.  清除bundle的上下文
    清理該bundle注冊(cè)的service
    釋放該bundle用到的service
    刪除該bundle注冊(cè)的listener  
    5.  該bundle的狀態(tài)返回到resolved狀態(tài)
    6.  發(fā)stopped事件給該bundle
     
    ü         Bundle的卸載
    1.  Stop bundle
    2.  把該bundle從緩存中刪除
    3.  把該bundle放入uninstall 類別中
    4.  該bundle狀態(tài)設(shè)置成uninstalled
    5.  觸發(fā)bundle的uninstall事件
    6.  看是否有以來(lái)該bundle的module,如果沒有則垃圾回收
    Listener和事件機(jī)制            
    關(guān)于這一部分功能和用法已在上一篇service層里已經(jīng)做了介紹,這里只做一下簡(jiǎn)單的羅列
    ü         Framework
    FrameworkListener:
    注冊(cè)時(shí)間:
    觸發(fā)時(shí)間:
    作用:OSGI environment
     FrameworkEvent: type,bundle,throwable
    ü         Bundle
    BundleListener
    注冊(cè)時(shí)間:
    觸發(fā)時(shí)間:
    作用:a bundle lifecycle change.
    BundleEvent: Bundle,type
    ü         Service
    ServiceListener
    注冊(cè)時(shí)間:
    觸發(fā)時(shí)間:
    作用:a service lifecycle change.
    ServiceEvent:serviceReference ,type
     
    資源
    事件類型
    觸發(fā)時(shí)機(jī)
    Framework
    STARTED
    Framework啟動(dòng)完成
    Framework has started after all installed bundles that are marked to be started have been started and the Framework has reached the intitial start level.
    ERROR
    There was an error associated with a bundle.
    PACKAGES_REFRESHED
    Framework has completed the refresh  packages operation initiated by a call to the
    PackageAdmin.refreshPackages method.
    STARTLEVEL_CHANGED
    the Framework has completed changing the active start level initiated by a call to the StartLevel.setStartLevel
    method.
    WARNING
    There was a warning associated with a bundle.
    INFO
    There was an informational event associated with a bundle.
    Bundle
    INSTALLED
    The bundle has been installed.
    STARTED
    The bundle has been started.
    STOPPED
    The bundle has been stopped.
    UNINSTALLED
    The bundle has been uninstalled.
    RESOLVED
    The bundle has been resolved.
    UNRESOLVED
    The bundle has been unresolved.
    STARTING
    The bundle is about to start.
    STOPPING
    The bundle is about to stop.
    Service
    REGISTERED
    This service has been registered.
    MODIFIED
    The properties of a registered service have been modified.
    UNREGISTERING
     This service is in the process of being unregistered.
     
    If a bundle is using a service that is <code>UNREGISTERING</code>, the
         bundle should release its use of the service when it receives this event.
         If the bundle does not release its use of the service when it receives
         this event, the Framework will automatically release the bundle's use of
         the service while completing the service unregistration operation.
     
     
     
     
      
    資源的查找
    幾點(diǎn)說(shuō)明
    系統(tǒng)啟動(dòng)時(shí)候,會(huì)把所有職責(zé)的關(guān)聯(lián)關(guān)系wire起來(lái)
    并且創(chuàng)建核心的查找資源policy
    還有就是有的module可以放在resolve階段可以放到查找資源的時(shí)候進(jìn)行,實(shí)現(xiàn)懶加載的功能
     
    1.查找資源的核心類,分發(fā)中心,所有的調(diào)度邏輯都在這里
    2.所有的資源查找都代理到該核心類,有點(diǎn)象代理的方式
    3.module的修改,這里會(huì)實(shí)時(shí)的得到更新(通過(guò)注冊(cè)listener)
    資源的查找:在本bundle的classloader范圍內(nèi),進(jìn)行class的查找,資源加載的順序可以參見規(guī)范
    下面是類查找的類圖
     
    該bundle的Classloader在bundle的resolve階段就創(chuàng)建好了
    關(guān)于bundle的說(shuō)明定義中的import export詳見規(guī)范
    系統(tǒng)Bundle的啟動(dòng)過(guò)程
    1.系統(tǒng)bundle由框架啟動(dòng),并且只啟動(dòng)一次
    2. 創(chuàng)建服務(wù)的注冊(cè)中心,該中心作為各種事件的分發(fā)場(chǎng)所。
    3. 創(chuàng)建核心的查找資源的policy,加入resolver listener到該policy,可以在module解析后,得到通知更新bundle的狀態(tài)
    4. 初始化事件分發(fā)器
    5. 在加載其他的bundle之前,創(chuàng)建系統(tǒng)的bundle負(fù)責(zé)容器相關(guān)的service,resolve系統(tǒng)bundle,創(chuàng)建系統(tǒng)bundle的activator,創(chuàng)建bundle的上下文,并觸發(fā)activator
    6. 安裝其他的bundle
    7 觸發(fā)系統(tǒng)bundle的started事件,標(biāo)志系統(tǒng)bundle啟動(dòng)完成
    8. 觸發(fā)框架的started時(shí)間,標(biāo)志框架啟動(dòng)完成

    posted @ 2007-09-24 13:26 阿不 閱讀(695) | 評(píng)論 (0)編輯 收藏

    OSGI 服務(wù)層探究

         摘要: OSGI的框架很好的解決了模塊動(dòng)態(tài)的更新,部署,以及解決他們之間的依賴關(guān)系
    的問(wèn)題,更夠搭建動(dòng)態(tài)化的系統(tǒng)可以說(shuō)是OSGI在SCA的部署策略上的一種很好的參考實(shí)現(xiàn)。
      閱讀全文

    posted @ 2007-08-14 11:51 阿不 閱讀(1381) | 評(píng)論 (0)編輯 收藏

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(2)

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产亚洲人成在线影院| 无码 免费 国产在线观看91| 无人视频免费观看免费视频| 在线人成免费视频69国产| 最近最新MV在线观看免费高清| 亚洲国产成人久久一区久久 | 国产国拍精品亚洲AV片| 亚洲熟妇无码久久精品| 男女污污污超污视频免费在线看| 亚洲国产精品免费视频| 国产一区二区三区在线免费观看| 亚洲成a人片77777老司机| 亚洲欧美乱色情图片| 可以免费观看的国产视频| 日韩一级免费视频| 亚洲精品线在线观看| 国产亚洲人成在线影院| 日本亚洲免费无线码| 亚洲综合图色40p| 亚洲JIZZJIZZ妇女| 91成人免费观看| 国产亚洲精品精品国产亚洲综合 | 亚洲精品在线不卡| 一个人免费播放在线视频看片| 免费一本色道久久一区| 亚洲精品无码久久千人斩| 精品亚洲国产成人av| 91嫩草免费国产永久入口| 77777亚洲午夜久久多人| 亚洲国产精品成人午夜在线观看| 久久久久久国产精品免费免费男同| 又黄又爽一线毛片免费观看| 亚洲人成网站在线观看播放动漫| 你懂的在线免费观看| 免费jjzz在线播放国产| 亚洲资源最新版在线观看| 久久午夜羞羞影院免费观看| 在线亚洲午夜理论AV大片| 国产亚洲综合精品一区二区三区| 一二三四影视在线看片免费| 亚洲国产香蕉碰碰人人|