felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fleygues <francois.leyg...@alcatel-lucent.com>
Subject SCR: what are the conditions to satisfy a componentFactory service?
Date Mon, 12 Sep 2011 12:18:03 GMT

A simple example as this one
(a few lines of SCALA)
shows that the registration of ANY dependent service (here aDep, from 
the console)
activates the componentFactory service (here "Factory"),
even if it does NOT satisfy the references
of the component (here the  property "Dep=true" required by "Comp").

This is unfortunate, since this may trigger a code which try to 
instanciate the component service, which  will be refused by the SCR, 
while the factory is activated.

-------------------------------- cut here 
package test;

import org.osgi.service.component.ComponentFactory
import aQute.bnd.annotation.component.Activate
import aQute.bnd.annotation.component.Component
import aQute.bnd.annotation.component.Reference

@Component (provide=Array())
class Factory {
     var c: Comp = _
     @Reference(target = "(component.factory=Comp)")
       def bind(cf : ComponentFactory ) = { println("Factory bind")
     c = cf.newInstance(null).getInstance().asInstanceOf[Comp];
     println("c is " + c)
   def start()=println("Factory Activate")

@Component(factory = "Comp")
class Comp {
     @Reference(target = "(Dep=true)")
     def bind(d: Dep)  = println("Comp.bind")

trait Dep {}
@Component(enabled=false, properties=Array("Dep=false"))
class aDep extends Dep

-------------------------------- cut here 

Is this a bug of the SCR implementation ?

In apparence, yes.
A Component Factory service whose  component instance has a dependence 
on another
component shall be available only when this dependence is resolved.
This is apparently the meaning of chapter 112.5.5 of  compendium 4.2,  
in the first paragraph.

The issue raised about this
(which provided  the example re-coded here)
has been closed, and marked resolved, which seems wrong.

What could we do or say about that,  please ?


View raw message