转载:OSGI组件依赖

简介: 原文链接: OSGi组件依赖     OSGi doesn’t allow you to specify class visibility at the class level, but instead at the level of the containing package. 1. The header:Export-Package and The directives for the Export-Package header     当指定一个package export,默认的它的subpackage是没有exportde,需特别指定。

原文链接:

OSGi组件依赖

    OSGi doesn’t allow you to specify class visibility at the class level, but instead at the level of the containing package.

1. The header:Export-Package and The directives for the Export-Package header

    当指定一个package export,默认的它的subpackage是没有exportde,需特别指定。

    Directives for the Export-Package header:

    (1)exclude : Specifies a list of packages that must be invisible to the component importing the

         package.
    (2)include : Specifies a list of packages that must be visible to the component importing the

         package.
    (3)mandatory Specifies a list of mandatory properties that must be specified when using the

        exported package in other components.
    (4)uses : Specifies a list of packages that an exported package uses. This directive is used by 

        the dependency resolver to ensure that imported package versions correspond to those
        specified here.

    默认情况下,在Export Package是,OSGi框架会自动将ExportBundles的bundle-symbolic-name和Bundle

    -Version属性添加上。

    例如:Export-Package:
             org.springframework.beans.factory.serviceloader;
             uses:="org.springframework.util,
             org.springframework.beans. factory.config,
             org.springframework.beans.factory";
             version=2.5.5, 
             org.springframework.beans.annotation;
             uses:="org.springframework.util,
             org.springframework.beans";
             version=2.5.5,

             ...

2. The header:Import-Package and It's stand attributes

    Standard attributes usable with the Import-Package header:

    (1)version : Specifies the version range for matching exported packages. If this attribute
        isn’t specified, the default value is [0.0.0, ∞). 
    (2)bundle-symbolic-name : Specifies the symbolic name of the component that exports the

        packages. In the case of a fragment bundle, the name will correspond to the host bundle’s

        symbolic name instead. A fragment is a special bundle that allows extending an existing

        bundle.

    (3)bundle-version : Specifies the version of the component that exports the packages. As
        with version, the default value is [0.0.0, ∞) and the fragment behavior is as for bundle-

        symbolic-name.

    例如:

    Import-Package: javax.el;version="[2.1.0, 3.0.0)";resolution:=optional
    net.sf.cglib.proxy;version="[2.1.3, 2.2.0)";resolution:=optional,
    org.apache.commons.logging;version="[1.0.4, 2.0.0)",
    org.springframework.core;version="[2.5.6, 2.5.6]";resolution:=optional,
    org.springframework.core.annotation;version="[2.5.6, 2.5.6]";
    resolution:=optional

 

    In addition to the previous attribute, the resolution directive of the Import-Package header

    makes it possible to change the behavior of this resolution mechanism.The first possible value

    of the directive is mandatory, which is also the default.When a package is marked as

    mandatory, it means that if the package can’t be resolved, the component itself can’t be

    resolved. The other value is optional. In this case, if the package isn’t present during the

    resolution phase, the package isn’t considered imported by the component.

3. The header: DynamicImport-Package

    It bypass the regular class-resolution mechanism we have described and instead allows

    classes to be loaded on demand at runtime. Dependencies specified in this way are ignored

    during the transition between the installed and resolved states.

 

    The DynamicImport-Package header can contain a list of packages, but it also supports two 

    wildcards for specifying package names. Moreover, these imports are searched for in the order

    in which they are specified. This ordering is important, especially when using wildcards,

    because it determines the order in which matching occurs. In the following snippet, packages

    with the value test for the attribute myattribute will be preferred over other packages.

 

    DynamicImport-Package: *;myattribute=test, *

    
    No directives are defined for this header, but the standard version, bundlesymbolic-name,  

    and bundle-version attributes can all be used for package matching with the same semantics

    as Import-Package.

4. The header: Require-Bundle

    The Require-Bundle header is provided by the OSGi specification so you can consume all

    exported packages from other components based on component symbolic names.

    The Require-Bundle only has one attribute:bundle-version,the bundle-version attribute uses

    the same semantics as the version attribute of the Import-Package header and specifies
    the component version of the dependency.

    例如:

    Manifest-Version: 1.0
    (...)
    Import-Package: javax.servlet;version="2.5.0",
    javax.servlet.http;version="2.5.0",
    javax.servlet.jsp;version="2.0.0",
    (...)
    Require-Bundle: com.springsource.javax.servlet.jsp.jstl;
    bundle-version=1.1.2,com.springsource.org.apache.taglibs.standard;
    bundle-version=1.1.2

    注意:同一份MANIFEST.MF配置文件中,Import-Package header takes priority over the Require

    -Bundle header.

 

    Directives usable with the Require-Bundle header:

    (1)visibility : When set to private (the default value), the exported packages of the

    corresponding bundles aren’t re-exported. Setting this to reexport will achieve the opposite.
    (2)resolution : Controls dependency resolution. If set to mandatory (the default value), the
    dependency must be successfully resolved for the bundle to resolve. With the optional value,

    dependencies are only resolved if they’re present, and the bundle will resolve regardless.

5. Split packages

    You saw that referencing bundles with the Require-Bundle header is equivalent to importing

    all of their exported packages. A problematic case occurs when two different required bundles 

    export the same package. Such packages are named split packages because their content

    comes from several bundles.
    Although OSGi allows split packages, you’ll notice that they have several obvious drawbacks.
    When different bundles provide the same classes, unpredictable shadowing of classes can arise.

6. Matching and Versioning

6.1 Version Matching

    The different parts of a version value:

    (1)Major number : For major updates with no provision for compatibility with previous major     

         versions.
    (2)Minor number : For functional updates compatible with the current major version (compatible

        for clients using an interface, but not for implementers).
    (3)Micro number : For bug fixes.
    (4)Qualifier : Values like “–SNAPSHOT” for the current development version can also be added

        at the end of the value. The version number with a qualifier is lower than the number without.

6.2 Optional Depedencies

    OSGi supports optional dependencies on both packages and bundles with the Import-Package

    and Require-Bundle headers.

6.3 Attribute Matching

    模式:

    Header-Name: header-value1;directive-name1:=directive-value1;attribute-name1= attribute

    -value1;attribute-name2=attribute-value2, 
    (...)

    例如:

    Export-Package: com.manning.osgi.simple;criteria="Manning";mandatory:="criteria"

    Import-Package: com.manning.osgi.simple;criteria="Manning"

目录
相关文章
|
运维 Java Shell
Linux非常详细的shell运维脚本一键启动停止状态SpringBoot打成可运行jar包
Linux非常详细的shell运维脚本一键启动停止状态SpringBoot打成可运行jar包
716 0
H8
|
物联网 数据安全/隐私保护 智能硬件
女朋友问: 你知道蓝牙耳机的原理吗?
蓝牙是一种无线通讯技术标准,用来让固定与移动设备,在短距离间交换资料,以形成个人局域网(PAN)。其使用短波特高频(UHF)无线电波,经由2.4至2.485GHz的ISM频段来进行通信。1994年由电信商(Ericsson)发展出这个技术。它最初的设计,是希望创建一个RS-232数据线的无线通信替代版本。
H8
1265 17
|
5月前
|
数据采集 数据挖掘 API
1688品类API:市场趋势分析,选品更精准!
借助1688品类API,获取商品类目、价格、销量、供应商等数据,通过热度、价格、增长性、竞争度和趋势五大维度分析,实现科学选品。结合Python技术抓取与处理数据,助力精准决策,提升电商竞争力。(239字)
|
9月前
|
缓存 JSON 数据安全/隐私保护
1688 商品详情接口(item_get)全解析:参数配置 + 高阶代码实现(附实战踩坑经验)
本文分享1688商品接口item_get的实战对接经验,涵盖参数配置、HMAC-SHA1签名流程、高阶代码实现及常见坑点,如起批量单位混乱、库存字段不一致、权限不足等,并提供可落地的解决方案与排查表,助力开发者高效稳定对接B2B电商系统。
|
机器学习/深度学习 人工智能 机器人
魔搭社区模型速递(5.11-5.17)
🙋魔搭ModelScope本期社区进展:📟1656个模型,151个数据集,645个创新应用,📄 9 篇内容
595 11
|
存储 数据挖掘 数据处理
Pandas高级数据处理:内存优化
Pandas 是流行的数据分析库,但随着数据量增加,内存使用问题日益突出。本文介绍常见内存优化问题及解决方案,包括选择合适数据类型(如 int8、float32)、使用 category 类型减少字符串内存开销、分块读取大文件避免 MemoryError 等。通过代码示例详细讲解如何优化内存使用,提高程序性能并避免错误。掌握这些技巧可显著提升 Pandas 数据处理效率。
798 58
|
12月前
|
前端开发
HarmonyOS NEXT仓颉开发语言实现画板案例
本文介绍了使用仓颉开发语言实现画板功能的案例,通过Canvas组件实现画布绘制,并利用贝塞尔曲线使画笔跟随触摸轨迹生成平滑曲线。内容包含画布初始化、触控事件处理及清空功能,展示了仓颉语言在图形绘制中的应用技巧。
|
Java 测试技术
Java反射之Method的invoke方法详解
Java反射之Method的invoke方法详解
1286 1
|
监控 安全 Java
Java多线程调试技巧:如何定位和解决线程安全问题
Java多线程调试技巧:如何定位和解决线程安全问题
395 2
|
SQL 关系型数据库 分布式数据库
PolarDB产品使用问题之如何实现在线上加索引,并且不会锁表
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。