1. OSGI bundle间的协作方式
类似SOA,每个bundle可以通过BundleContext注册对外提供的服务,同时也可以通过BundleContext来获得需要引用的服务。借助使用bundle的元数据来实现工程之间package的共享。export package和import package。
在OSGI框架中,Service是个实际的概念,只有通过BundleContext注册成Service才能使得一个POJO作为Service在OSGI框架中被使用,同时也只有通过BundleContext来获取发布到框架中的Service,通过Service的方式来实现Bundle之间实例级的依赖,和Import-Package、Require-Bundle不同的地方在于通过Service获取的是其他Bundle中类的实例。
2.bundle的classloader机制
每一个bundle都有自己的classloader
题外话:虚拟机的类加载机制
虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验、转换解析和初始化,最终形成可以被虚拟机直接使用的Java类型,这就是虚拟机的类加载机制。JVM类加载的双亲委派模型(Parents Delegation Model)。
OSGI没有采用该模型,使用了网状模型。
2.OSGI和Spring
使用Spring DM整合OSGI和Spring框架。
Spring-OSGI默认加载解析META-INF/spring目录下的xml文件作为spring bean配置文件.
问题1:如何把Spring中的bean发布为OSGI服务?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<bean id="multiplyImpl" class="org.flyer.multiply.bundle.MultiplyImpl">
</bean>
<osgi:service id="multiplyOsgiService" ref="multiplyImpl"
interface="com.osgi.compute.ComputerInterface">
</osgi:service>
</beans>
问题2:如何引用OSGI服务?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<bean id="computeClient" class="org.flyer.compute.client.bundle.ComputeClient">
<constructor-arg ref="computeService"></constructor-arg>
</bean>
<osgi:reference id="computeService" interface="com.osgi.compute.ComputeInterface"></osgi:reference>
</beans>
Spring DM 提供了spring-osgi-extender bundle,该bundle负责为你的应用bundle初始化Spring 的Application context,和Spring中的ContextLoadListener提供的功能类似。
extender bundle异步创建Application context,使用另外一个线程创建。如下图所示:
Application context的销毁:
打包和部署基于Spring的OSGI应用
- 大小: 40.4 KB
- 大小: 16.9 KB
- 大小: 58.9 KB
- 大小: 21 KB
分享到:
相关推荐
OSGI学习笔记
NULL 博文链接:https://abstractforever.iteye.com/blog/758879
OSGi入门笔记
NULL 博文链接:https://abstractforever.iteye.com/blog/761674
Linux OSGi的框架搭建,使用cvm来编译文件
本人学习osgi karaf笔记,karaf常用命令
EquinoxEquinox Equinox在创建 Bundle Bundle 的 ClassLoader ClassLoader 时,首先获取 时,首先获取 时,首先获取 时,首先获取 bundle bundle bundle 的 classpath classpath classpath ,然后执行 。...
NULL 博文链接:https://abstractforever.iteye.com/blog/1126123
NULL 博文链接:https://itway.iteye.com/blog/1545218
NULL 博文链接:https://jay1986.iteye.com/blog/1913526
凡人的OSGi 这是我在 NA 2011,EU 2012和EU 2014上的“ OSGi的凡人”演示文稿的代码。 这是使用OSGi Declarative Services从头开始构建的最小的独立RESTful服务器,旨在证明OSGi不仅适用于超人大师。 该示例演示了...
笔记仅在主要从 Eclipse 运行的基于 Equinox 的 OSGi 环境中对其进行了测试(Felix 和 Virgo 也可以运行)。安装一旦我完成了项目的 Tycho 构建,我将提供一个包含所有必需包的 p2 更新站点。 在此之前,您必须编译...
NULL 博文链接:https://springsfeng.iteye.com/blog/1152012
NULL 博文链接:https://springsfeng.iteye.com/blog/1271565
NULL 博文链接:https://springsfeng.iteye.com/blog/1259203
凡人的 OSGi 这是我在 NA 2011、EU 2012 和 EU 2014 上的“OSGi for meretals”演示文稿的代码。 它是一个使用 OSGi 声明式服务从头开始构建的最小的独立 RESTful 服务器,旨在证明 OSGi 不仅适用于超人的大师...
Solr OSGi 该项目的目标是能够在OSGi环境中运行Apache Solr,并将OSGi动态生命周期带入Solr世界。 笔记尚不支持所有的Solr功能,尚未测试集群和分片。 从理论上讲,每项功能都可以在将来实现。 已计划基于地窖的...
1.4 插件技术和OSGi 1.5 RCP技术 1.6 EMF技术 1.7 GEF技术 1.8 本章小结 第2章 SWT/JFace概述 第3章 SWT编程基础 第4章 使用基本控件与对话框 第5章 容器与布局管理器 第6章 界面开发工具 第7章 高级控件使用 第8章 ...
包括 OSGI 服务、REST 服务、ui、kar 应用程序和分发的示例我该如何设置? 从根目录运行“mvn clean install” 将 tar.gz 文件从“distro/target”文件夹复制到您想要运行 Karaf 的目录中。 解压 tar.gz 文件在...