Take the 2-minute tour ×

I would like to implement following scenario:

Extender uses his extensions while extensions 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)
  • share|improve this question
    I think it may be implemented by changing bundles' URI and installing it under different symbolic name. It's little hacky but i don't get different idea right now. –  Kalaz Feb 23 '11 at 2:13
    add comment

    1 Answer

    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.

    share|improve this answer
    add comment

    Your Answer


