比竇娥還冤的CM

          在之前的一篇blog中我曾經(jīng)寫到過CM對于application level的configuration的不適應(yīng),提到的主要是兩點:
          1、無法在外部統(tǒng)一的對Bundle中service所需要的屬性進(jìn)行管理;
          ??????當(dāng)時基于這個約束,只好在各自的bundle下編寫一個管理當(dāng)前bundle屬性的服務(wù),當(dāng)外部需要管理此bundle的屬性時,必須通過這個服務(wù)來管理,否則的話改變是不會起到效果的。
          2、無法共享屬性的配置。
          ????? 每個bundle都保存自己獨立的一份屬性配置,這就導(dǎo)致了當(dāng)出現(xiàn)共享屬性時,在管理端也不得不同時去重復(fù)的更新多個bundle。
          昨天在調(diào)試產(chǎn)品的時候,又被CM搞的郁悶了一把,由于CM是根據(jù)BundleLocation和service.PID共同來綁定屬性的,也就是說當(dāng)BundleLocation改變了的情況下屬性就無效了,而且也無法被重寫,這對于實際的應(yīng)用而言幾乎是不可接受的,因為模塊部署的路徑、模塊的名稱改變這都是很正常的事,但根據(jù)CM這樣的方式的話,也就意味著模塊部署的路徑、模塊的名稱都是不可改變的。
          想想挺惱人的,就開始仔細(xì)的看Equinox的CM實現(xiàn)的代碼,經(jīng)過仔細(xì)的查看后,發(fā)現(xiàn)自己疏忽了一點,冤枉了CM,其實CM也是留了一個口以供上面這樣的情況下的處理的,后來對照了下OSGi R4中CM規(guī)范的描述,確實如此,如果希望配置不要和bundleLocation綁定,那么可以在注冊ManagedService接口實現(xiàn)的服務(wù)時將其server.bundleLocation設(shè)置為null,如下:
          <component?name="PortComponent">
          ???????
          <implementation?class="com.terdon.spike.port.PortService"/>
          ???????
          <property?name="service.pid"?value="com.terdon.port"/>
          ???????
          <property?name="service.bundleLocation"?value="null"/>
          ???????
          <service>
          ???????????????
          <provide?interface="org.osgi.service.cm.ManagedService"/>
          ???????
          </service>
          </component>
          然后就可以在其他的管理屬性的服務(wù)中調(diào)用ConfigurationAdmin來實現(xiàn)對這個service的屬性的管理:
          Configuration configuration=admin.getConfiguration("com.terdon.port", null);
          根據(jù)這樣的分析,也就是說我以前所說的第一點的情況是冤枉了CM,現(xiàn)在開始給它平反,:)
          摘一下OSGi R4 CM規(guī)范中對于這種情況的描述:
          "Bundles with the required permission can create Configuration objects that
          are not bound. In other words, they have their location set to null. This can
          be useful for pre-configuring bundles before they are installed without having
          to know their actual locations.
          In this scenario, the Configuration object must become bound to the first
          bundle that registers a Managed Service (or Managed Service Factory) with
          the right PID.
          A bundle could still possibly obtain another bundle’s configuration by registering
          a Managed Service with the right PID before the victim bundle does
          so. This situation can be regarded as a denial-of-service attack, because the
          victim bundle would never receive its configuration information. Such an
          attack can be avoided by always binding Configuration objects to the right
          locations. It can also be detected by the Configuration Admin service when
          the victim bundle registers the correct PID and two equal PIDs are then registered.
          This violation of this specification should be logged."
          從上面這段描述中,可以看出,CM之所以這么設(shè)計主要還是從安全性的角度考慮的。
          但對于第二點,目前看來確實是如此,屬性無法共享,因為pid必須是唯一的,我已經(jīng)發(fā)了郵件給equinox maillist,看看是不是有人會有辦法,:)

          posted on 2006-11-22 11:59 BlueDavy 閱讀(2096) 評論(5)  編輯  收藏 所屬分類: OSGi、SOA、SCA

          評論

          # re: 比竇娥還冤的CM 2006-11-22 16:30 huang[匿名]

          你好,我在看你的《osgi實戰(zhàn)》中的實例代碼,有個小問題請教一下,就是那個Plug-in Dependencies中是的jar包是怎么設(shè)置的,是不是自動根據(jù)metafest.mf獲取的。如果一個bundle依賴一個jar包,可以將它通過配置在buildpath設(shè)置中,也可以將jar包轉(zhuǎn)為一個bundle在METAFEST.MF中配置,這兩種方法是不是通用的?謝謝

          另外關(guān)于Required Plug-in和Imported Package的問題。在《實戰(zhàn)》一書中,同樣是關(guān)聯(lián)類,為什么LDAP關(guān)聯(lián)user下的接口時用Imported Package,而WebBundle關(guān)聯(lián)HttpServlet類時使用Required Plug-in呢。是不是二者是通用的,前者是import所有的類,而后者是通過import部分類,其實也是required了相應(yīng)的bundle的?  回復(fù)  更多評論   

          # re: 比竇娥還冤的CM 2006-11-22 22:21 BlueDavy

          @huang[匿名]
          不好意思,你的第一段話的問題我看的不是非常的明白,只能按我的理解說說了,如果一個Bundle依賴jar包,做法基本上和普通的java project沒什么區(qū)別,就是都是以jar包形式放入lib目錄,然后在buildpath上加上,只是在Bundle的情況下還需要在MANIFEST.MF的Runtime/Classpath上也加上這個jar包,在Eclipse中如果是先在MANIFEST.MF的Runtime/Classpath加上jar包的話,那么可以自動同步build path。

          至于第二個問題,require通常用于可以獲取該bundle中所有的export的包,同時還有個作用就是可以獲取該bundle的資源文件,因為webbundle關(guān)聯(lián)httpservlet類的那個bundle中只有一些servlet相關(guān)的api的類,所以我就用了require的方式,兩者還是有區(qū)別的,盡量不使用require,而使用imported。  回復(fù)  更多評論   

          # re: 比竇娥還冤的CM 2006-11-22 23:27 huang[匿名]

          謝謝BlueDavy的回答,我明白了 thx  回復(fù)  更多評論   

          # re: 比竇娥還冤的CM 2007-01-27 00:42 shakebaby

          CM這部分我還不夠理解,不過之前看規(guī)范時為PID和Location的確感到奇怪。  回復(fù)  更多評論   

          # re: 比竇娥還冤的CM 2007-01-27 15:52 BlueDavy

          @shakebaby
          用用就理解了,:),還是個不錯的東西,我現(xiàn)在產(chǎn)品中的配置都是用它了。  回復(fù)  更多評論   

          公告

           









          feedsky
          抓蝦
          google reader
          鮮果

          導(dǎo)航

          <2006年11月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          統(tǒng)計

          隨筆分類

          隨筆檔案

          文章檔案

          Blogger's

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 舒城县| 安阳县| 鹤庆县| 襄汾县| 望城县| 房产| 桂林市| 衡南县| 德钦县| 镇赉县| 靖西县| 普格县| 金昌市| 中宁县| 伊金霍洛旗| 东兴市| 巴塘县| 平远县| 湘乡市| 阿拉善右旗| 柘城县| 黑龙江省| 昌都县| 武穴市| 额尔古纳市| 广东省| 新田县| 集贤县| 宜宾市| 汪清县| 西峡县| 锡林浩特市| 清镇市| 靖宇县| 安化县| 北海市| 都兰县| 荃湾区| 九江市| 濮阳县| 郴州市|