开发者

OSGi extender pattern with load ballancing extensions

开发者 https://www.devze.com 2023-02-12 14:07 出处:网络
I would like to implement following scenario: Extender uses his extensions while extens开发者_如何学JAVAions are grouped by theirs\' type. For example: Extender = Vendor and Extensions = HotDogSelle

I would like to implement following scenario:

Extender uses his extensions while extens开发者_如何学JAVAions are grouped by theirs' type. For example: Extender = Vendor and Extensions = HotDogSeller1, HotDogSeller2, PopcornSeller. My point is that client (customer) want to buy either HotDogs or Popcorns however he will choose less loaded HotDogSeller (smaller queue).

I am new to OSGi so I would like ask what are best practices to implement this? I suppose I could use Apache Felix with iPojo (and it's extender pattern). There are 2 problems with this:

  • Same bundle has to be installed twice (the hotdog implementation, each has it's own queue length)
  • Somehow group the bundles that are of the same type (hotdogs, popcorns). This could be done by creating property for bundle with some key like 'number' to distinct HotDogSeller1 and HotDogSeller2)

  • I think that you are trying to misuse the extender pattern. One of the key characteristics is that the extender pattern is static in its nature: everything happens when the bundle is installed. It seems that this is not your case: having multiple queues for the same implementation leads me to think that there are services behind those queues. The number of services can change dynamically, so extender will not serve you well for this.

    I think it would be better if you use Whiteboard pattern. (Ignore that fact that it is targeted at listeners mechanism). The idea is that each bundle provides service, which can handle your requests. You track all available services using a ServiceTacker. When you need a request to be processed, you iterate over all available services and ask them whether they are free (you can choose to handle this internally and don't negotiate this with the service implementations). When a free service is found you forward the request.

    You can group the services by registering them with a property 'type' and the corresponding value, so you can use services, which have 'type' 'HotDog' and services with 'type' 'Popcorn'.

    If you go this way, you can use OSGi Declarative Services, so you don't need write the code, which does the service registration or any other service management.

    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    关注公众号