reference-list除了可以用setter的方式注入OSGI service外,还可以用listener的方法来实现OSGI service的注入。
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
default-timeout="0">
<bean id="coders" class="com.ponder.coders">
</bean>
<!-- 为以上bean定义一个引用列表,将所有com.ponder.ICoder服务都通过bindICoder注入进来 -->
<reference-list id="coderExtender" interface="com.ponder.ICoder" availability="optional">
<reference-listener bind-method="bindICoder" unbind-method="unbindICoder" ref="coders">
</reference-listener>
</reference-list>
<!-- bean通过使用引用列表里的服务,对外提供com.ponder.ICodeService服务,这个bean就类似于一个"扩展点" -->
<service id="CoderService" ref="coders" interface="com.ponder.ICodeService">
</service>
</blueprint>
这种方法就是通过bean里定义由reference-listener子节点的属性bind-method和unbind-method指定的两个方法来注入或撤走服务的引用。这两个方法都带一个com.ponder.ICoder的参数,也就是将要被注入或撤走的那个服务引用。当多个服务被注入(或撤走)时,bind-method(或unbind-method)会被调用多次。这种方式给予你更大的控制自由度。
另外,reference-list还支持availability属性,可取“optional”和“mandatory”两个选项之一。
optional代表引用的服务可以为0个,即使引用的服务不存在,也不影响引用它的那个bean,blueprint的应用组装依然能够顺利完成。
而mandatory则要求引用的服务至少存在1个,被引用的服务必须在超时时间内最少存在1个可用,否则这个bundle的blueprint状态将在超时后变成“fail”,应用的组装将失败,无法对外提供服务。
最后,reference-list节点也可以和reference节点那样用filter属性来过滤引用的服务。
分享到:
相关推荐
OSGi的入门资料,网上找的,初探OSGi 的全文
OSGi的入门教程,帮助初学者快速了解OSGi的定义、用途及组成。
强大的OSGI框架入门和例子,看看eclipse就知道OSGI有多强大了。希望对大家有用!
OSGI 入门资料PDF,包括OSGI实战、OSGI进阶、OSGI 入门和整合Spring、OSGI原理与最佳实践
NULL 博文链接:https://conkeyn.iteye.com/blog/2113824
osgi-blueprint-helloworld 概述 一个使用OSGI蓝图容器规范的非常简单的HelloWorld示例。 想要查询更多的信息: osgi-blueprint-helloworld-api 应用程序API osgi-blueprint-helloworld-server 发布服务以供...
Spring OSGI 快速入门中文教程
OSGI简单入门.doc
osgi webservice入门
OSGI入门和整合Spring OSGI入门和整合Spring
spring-osgi 入门手册和代码 spring-osgi 入门手册和代码 spring-osgi 入门手册和代码 spring-osgi 入门手册和代码
总结了osgi服务发布和获取的多种方式。
Spring OSGi 入门.pdf Spring OSGi 入门.pdf
OSGI入门和整合Spring + OSGI进阶 + OSGI实战
OSGi 入门级教程OSGi 入门级教程OSGi 入门级教程OSGi 入门级教程中文版
blueprint-osgi-bundle
关于SOA中热门技术OSGI的入门样例的经典版本,供对需要进行ERP设计和学习的入门读者使用的经典
资源名称:OSGI原理与最佳实践内容简介:国内第一本OSGi图书OSGi国内推广者林昊多年经验的结晶涵盖OSGi从入门到深入的知识体系引领OSGi国内研究和普及本书基于作者多年使用OSGi的经验而编写,涵盖了OSGi从入门到深入...
OSGI进阶.pdf,OSGI实战.pdf,OSGI入门和整合Spring.pdf