I need to create service components with same interface. That mean i have different implementations for same interface. I tried to create two Components with same interface either one only active.
i am using equinox declarative. Do you have any better design to solve this problem? please find my configuration below.
Component1.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="comp1">
<implementation class="com.demo.impl.CompOneImpl"/>
<service>
<provide interface="com.demo.IComponent"/>
</service>
</scr:component>
Component2.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="comp2">
<implementation class="com.demo.impl.CompTwoImpl"/>
<service>
<provide interface="com.demo.IComponent"/>
</service>
</scr:component>
Accessing component from consumer
Consume component
comp1.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="consumeComp1">
<implementation class="com.demo.service.ConsumeCompOne"/>
<reference bind="setComp" cardinality="1..1" interface="com.demo.IComponent" name="comp1" policy="static" unbind="unsetComp"/>
</scr:component>
comp2.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="consumeComp2">
<implementation class="com.demo.service.ConsumeCompTwo"/>
<reference bind="setComp" cardinality="1..1" interface="com.demo.IComponent" name="comp2" policy="static" unbind="unsetComp"/>
</scr:component>
when i try to access comp1 and comp2 respectively through ConsumeCompOne and ConsumeCompTwo class i am always getting same component for both, either comp1 or comp2. Please help me to solve this.
Thankyou in advance
gopy
DS is working correctly, so there is nothing to solve here.
As you said, both consumer components get provided with an instance of the
IComponent
service, which is exactly what they are requesting as references.