Announcement Announcement Module
No announcement yet.
Mandatory Service (cardinality) only during init and not at runtime ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mandatory Service (cardinality) only during init and not at runtime ?

    The parameter cardinality equal to 1:1 takes effect only during initialization.Why is this not reflected at runtime ?


    Bundle A - exposes service

    Bundle B- Imports service with cardinality 1:1

    Now if i deploy bundle B first without Bundle A it waits for the timeout and then errors out . This is expected.

    Assume teh second case where

    I deploy Bundle A .then deploy Bundle B .Everything works fine. Now if i undeploy Bundle A

    I expect Bundle B to fail since its a mandatory service . Isnt this the expectation ?

    Instaed currently it waits for timeout and then throws a service unavailable Exception.

  • #2
    Is the second case, OSGi service was published by bundle A and found by bundle B. So bundle B application context is properly constructed and available.

    Service is published as a proxy that dynamically looks up proper service reference to invoke during runtime. From a perspective of bundle B - services/bean is there and available.

    OSGi service registry is a very dynamic animal, you have to be aware that services can come and go at any time.

    Is you really have to shutdown bundle b is service a is going away, you can do that with a service listener. That service listener should implement BundleContextAware - and you can call bundleContext.getBundle().update() to hopefully refresh the bundle and potentially stop spring context from starting up.

    Here is some reference:


    • #3
      I knew about the listener functionality , but was just confirming about the expected behaviour as i was confused by the word "mandatory" service . So now "mandatory at initilization" is a better word to associate.