osgi - multiple instances of a service

落花浮王杯 提交于 2019-12-12 05:14:18

问题


How can I create multiple instances of a bundle that consumes an external webservice? An external webservice requires clients to logon before using the services. I have multiple accounts. The problem is I want to be able to add multiple instances; one for each account. Each instance is an osgi declarative service that consumes the external service.

Do I have to deploy a new bundle for each account? This does not feel like the right way to solve this.


回答1:


Is that bundle under your control - can you refactor it ?

If yes, it might be useful to expose a client factory service, rather than client service itself. Then each instance can log into a different account.




回答2:


What you need is multiple instances of an OSGi component or service, not multiple instances of a bundle.

I'd recommend a service factory, where each OSGi config that you create (account parameters in your case) for your service causes a new instance of a service to be created.

Neil Bartlett's tutorial at http://njbartlett.name/2010/07/19/factory-components-in-ds.html looks like a good starting point for that.



来源:https://stackoverflow.com/questions/13241897/osgi-multiple-instances-of-a-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!