2

I am developing an OSGI-based system which uses declarative services to define components. However, when running it from Eclipse, one of my components is not initialized. When I investigate the issue using simple console commands, I get the following output (with some small obfuscation):

osgi> component 51
    Component[
    name = com.e.location.view
    activate = activate
    deactivate = deactivate
    modified = 
    configuration-policy = optional
    factory = null
    autoenable = true
    immediate = false
    implementation = com.e.location.view.LocationViewContribution
    state = Unsatisfied
    properties = 
    serviceFactory = false
    serviceInterface = [com.e.model.ViewContribution]
    references = {
        Reference[name = SpecificationProvider, interface = com.e.SpecificationProvider, policy = static, cardinality = 1..1, target = null, bind = setSpecificationProvider, unbind = null]
    }
    located in bundle = com.e.location.view_1.0.0.SNAPSHOT [107]
]
Dynamic information :
  The component is satisfied
  All component references are satisfied
  Component configurations :
    Configuration properties:
      component.name = com.e.location.view
      component.id = 55
      objectClass = String[com.e.model.ViewContribution]
    Instances:

So the component has state = Unsatisfied, but the dynamic information states the component is satisfied and its component references are satisfied too.

Can anybody explain this? Why is my component not initialized?

UPDATE: Apparently, setting immedate="true" for the component fixes the initialization problem. The osgi command still has state = Unsatisfied though. Anybody know why?

David ten Hove
  • 2,748
  • 18
  • 33

2 Answers2

3

We had similar issues when:

  • The activate method of the component threw an exception (see the log)
  • The activate method of the component did not return (see a thread dump)
    • Infinite loop (or JVM enhanced recursion) in activate
    • Deadlock

If you are in equinox and did not install a bundle that forwards the LogEvents to the logfile/console, do not forget to check the configuration directory, where equinox puts log files for error messages.

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
0

Remember that the constructor of your component must not have arguments.

Also, force enabling using enabled="true" immediate="true" attributes in the <scr:component> tag.

Pablo García
  • 237
  • 1
  • 10
  • I made sure they have a constructor like that. Also, if the component doesn't have a constructor like that, you will see an exception in the logs. But I'm not getting that here – David ten Hove Apr 24 '15 at 10:36
  • I've updated my answer with another possible solution :) – Pablo García Apr 25 '15 at 19:14
  • Thanks for your assistance, but I already commented on immediate="true" in my question. Do you know why the shell command still says the component has state=uninitialized like I ask at the end of my question? – David ten Hove Apr 28 '15 at 07:13
  • If you type the "ls" command you see your component "ENABLED", it isn't? (probably yes, as it has the autoenabled=true attribute, but maybe something is not enabling your component, and therefore, it is not being initialized). – Pablo García Apr 29 '15 at 15:17
  • The component is enabled. In fact, it's working fine. My question is why it the "component"-command still shows it as "state=unsatisfied". – David ten Hove Apr 30 '15 at 08:23