Mule ESB的component(三)——Java Component
?
Java Component
? ? 参考Mule的用户开发手册,component分为三类:Simple Components、Java Components、Other Components。《Mule ESB的component(二)》涉及了Simple Components和Other Components(没有详细介绍),这篇将介绍Java Components,也就是我们常说的自定义Components。
?
1. 示例:
? ? Java Components主要处理业务逻辑,它通过实现Mule不同的接口,从而提供符合业务逻辑的方法入口,其中org.mule.api.lifecycle.Callable和org.mule.api.component.LifecycleAdapter:
? ? ? ? * org.mule.api.lifecycle.Callable 仅有一个方法onCall(eventContext),顾名思义它是在service被调用时进入该方法;
? ? ? ? * org.mule.api.component.LifecycleAdapter 针对org.mule.api.lifecycle.Lifecycle接口进行了扩充,实现LifecycleAdapter需要实现invoke、isDisposed、isStarted、initialise、start、stop、dispose等方法,这些方法即一个请求的生命周期。
?
2. entry point? ?当你需要特定的请求进入指定的component时,entry point将会帮助你。? ?Mule提供的entry point:array-entry-point-resolver、callable-entry-pointresolver、method-entry-pointresolver、no-arguments-entry-pointresolver、property-entry-pointresolver、reflection-entry-pointresolver、custom-entry-pointresolver? ?entry point常用子元素:exclude-object-methods、exclude-entry-point、include-entry-point? ?? ?当Component没有设置entry point时,Mule会使用默认的配置(第三条和第四条没看懂,原文奉上),Mule in action中写到这个配置很复杂,原因是为了兼容Mule 1的版本:? ? ? ?■ A property-entry-point-resolver? ? ? ?■ A callable-entry-point-resolver? ? ? ?■ A reflection-entry-point-resolver configured to accept setter methods(they’re normally excluded)? ? ? ?■ A reflection-entry-point-resolver configured to accept setter methods and with transformation first disabledAt this point, you might feel overwhelmed by the versatility of the entry point resolutionmechanism. The best hint we can give you at this point is not to overengineer yourconfiguration with armies of finely tuned entry point resolvers. Rely first on the defaultset that Mule uses and add specific resolvers only if it’s not able to satisfy your needs.?? ?这段内容大概意思是,读者可能会对大量的entry point感到不知所措,作者给出的最好建议是:先使用默认的配置,除非它不满足你的需要。



