转载: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"

目录
相关文章
|
3月前
|
存储 NoSQL Java
【第三部分:第一个 Agent 应用】13. 为 Agent 增加记忆能力:不是记住一切,而是在需要时想起正确的信息
本文围绕 Agent Memory 展开,重点说明记忆并不是简单保存全部历史,而是从对话、任务和工具结果中提取值得长期保留的信息,并在未来任务中按需召回。文章区分当前对话记忆、会话记忆、任务记忆、用户长期记忆、语义记忆、情景记忆、程序性记忆、工作区文件与项目知识,并进一步介绍 Memory Capture、Recall、更新、冲突处理、遗忘、作用域、权限与记忆污染等问题。核心观点是:Memory ≠ History,真正成熟的 Agent 应该记住有价值的信息,并在正确的时机重新进入 Context。
258 0
|
4月前
|
人工智能 机器人 数据挖掘
4 大技巧,教你打造高效的 AI Agent 团队!
Claude 母公司 Anthropic 官方分享:怎么在团队中高效和 AI 协作,覆盖文档驱动协作、Skills 角色定义、多 Agent 分工、北极星目标设定等,配合鱼皮团队真实落地案例讲透
410 0
|
5月前
|
存储 人工智能 数据安全/隐私保护
企业AI知识库技术架构实战指南:从存储到RAG的全链路开发要点
本文为企业AI知识库落地提供全链路技术指南,涵盖异构存储统一纳管、智能文档解析、向量化索引与混合检索、RAG管线优化、知识图谱构建、物理级数据隔离及混合云部署七大核心要点,含可落地代码与选型建议,助开发者跨越Demo到生产鸿沟。(239字)
328 0
|
6月前
|
存储 算法 Java
【JVM虚拟机】垃圾回收GC:垃圾收集器:G1:Region分区、Mixed GC、回收流程、适用场景(高频)(附《思维导图》+《面试高频考点清单》)
G1是JDK 9起默认的低延迟垃圾收集器,将堆划分为2048个可动态分配角色的Region,通过Mixed GC优先回收垃圾最多的区域,结合Remembered Set与SATB算法,在大堆(≥4GB)场景下实现可预测停顿(如≤200ms)与高吞吐平衡。
1010 2
|
8月前
|
人工智能 IDE Shell
同事.Skill刷屏出圈,AI“技能蒸馏”的底层规则
本文深度解析爆火的“同事.skill”现象,揭示Skill本质是结构化提示词而非AI新能力。它通过三层渐进式披露与Harness运行时框架,解决AI工程化落地难题,而非替代人类判断力。Skill炼化的是流程,不是人。
|
10月前
|
消息中间件 人工智能 NoSQL
函数计算异步任务在高并发Agent场景下的幂等性与去重实践(附真实踩坑案例)
本文分享大厂AI应用在函数计算(FC)高并发场景下,应对异步任务重复执行的**四层幂等去重实战方案**:从全链路requestId透传、Redis+Lua轻量锁(拦截85%+重复)、Handler内指纹校验,到DB唯一索引兜底。附可落地代码与真实数据——重复率由11.7%降至0.08%,LLM调用与FC账单显著下降。
669 0
|
程序员 编译器 C++
【实战指南】C++ lambda表达式使用总结
Lambda表达式是C++11引入的特性,简洁灵活,可作为匿名函数使用,支持捕获变量,提升代码可读性与开发效率。本文详解其基本用法与捕获机制。
595 99
|
Web App开发 前端开发 JavaScript
CSS :has() 选择器:改变游戏规则的父选择器
CSS :has() 选择器:改变游戏规则的父选择器
1001 95
|
移动开发 前端开发 JavaScript
HTML表单验证:确认input元素输入为具有特定整数和小数位数的数值。
将上述JavaScript代码与HTML一同使用,便可以确保用户输入的数值符合特定的格式要求。特别要注意,在实际的生产环境中,仅仅依靠前端验证是不够的。为了安全起见,后端也应该实施相应的验证措施,以防止不匹配格式的数据通过其他手段提交到服务器。
1067 74
|
缓存 JSON 数据安全/隐私保护
1688 商品详情接口(item_get)全解析:参数配置 + 高阶代码实现(附实战踩坑经验)
本文分享1688商品接口item_get的实战对接经验,涵盖参数配置、HMAC-SHA1签名流程、高阶代码实现及常见坑点,如起批量单位混乱、库存字段不一致、权限不足等,并提供可落地的解决方案与排查表,助力开发者高效稳定对接B2B电商系统。