The extender pattern handler

本处理器的目标是简化基于扩展模式架构的开发。这种架构风格基于2种不同的角色:
>The extender
>The extensions

*The Extender pattern
这种架构风格有2个角色组成:
>the extender
>the extensions
2者之间关系是1..n。Extender跟踪extensions。这种架构风格的实践是extensions 被打包成不同的bundles。一个
extension是通过分析服务包被侦测到的。为此,这些bundle可以在manifest中写入特定的标志。实现一个扩展模式是非常复杂的,因为extender需要动态跟踪有特殊标志的bundle.当bundle启动后,它需要看到标志。当bundle移出时,extender不许释放所有从这个bundle创建的对象。
处理器基于特定的标志为你跟踪bundle。在任意时刻,符合规则的bundle出现或消失,一个callback就会被调用。这个标志就正好在bundle的manifest头部。
如今,一些框架使用了和iPOJO相同的模式。如Spring-DM


*Using the handler
首先,你需要配置组件类型区使用处理器,如下:
<iPOJO xmlns:extender="org.apache.felix.ipojo.extender">
<component
classname="org.apache.felix.ipojo.extender.myextender">

<!-- Extender Pattern handler configuration -->
<extender:extender
extension="My-Extension"
onArrival="onBundleArrival"
onDeparture="onBundleDeparture"
/>

<callback transition="invalidate" method="stopping" />
<callback transition="validate" method="starting" />
<provides />
</component>
</iPOJO>

注意,处理器是external handler。因此,它使用"org.apache.felix.ipojo.extender"命名空间
当描述后,你可以实现自己的组件。描述中指定的方法将会在匹配的bundle到达或者离开时被分别
调用。在上面的例子中,这些方法可能如下:
void onBundleArrival(Bundle bundle,String header){
}

void onBundleDeparture(Bundle bundle){
}
Notice the different signatures of the methods. The arrival method is called with the arriving bundle and the matching header value (i.e. the value of the My-Extension header of the bundle manifest). The departure method just receives the leaving bundle.

*Configuration
这个处理器只有3个托管(强制)的属性。
〉Extension:定义在manifest头中查找的标志
〉onArrival:定义当匹配的包到达时调用的方法
〉onDepartur:定义当匹配包离开时调用的方法

Called despite being invalid
The implementation will be notified of arrivals and departures despite the instance is invalid. Indeed, the implementation must release all objects created from another bundle as soon it leaves.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值