[
https://issues.apache.org/jira/browse/FELIX-4350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13843239#comment-13843239
]
Guillaume Nodet commented on FELIX-4350:
----------------------------------------
I have written a junit test that shows the problem.
It's basically the following:
{code}
@Test
public void test_unbind_while_activating()
{
final Component main =
findComponentByName("org.apache.felix.scr.integration.components.Felix4350Component");
TestCase.assertNotNull(main);
ServiceRegistration dep1Reg =
bundleContext.registerService(SimpleComponent.class.getName(),
new ServiceFactory() {
public Object getService(Bundle bundle, ServiceRegistration
registration) {
return new SimpleComponent();
}
public void ungetService(Bundle bundle, ServiceRegistration
registration, Object service) {
}
}, null);
ServiceRegistration dep2Reg =
bundleContext.registerService(SimpleComponent2.class.getName(),
new ServiceFactory() {
public Object getService(Bundle bundle, ServiceRegistration
registration) {
delay(1000);
return new SimpleComponent2();
}
public void ungetService(Bundle bundle, ServiceRegistration
registration, Object service) {
}
}, null);
main.enable();
delay(300);
dep1Reg.unregister();
delay(2000);
ComponentInstance mainCompInst = main.getComponentInstance();
TestCase.assertNull(mainCompInst);
}
{code}
Where the Felix4350Component is defined with:
{code}
<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
<scr:component xmlns:scr='http://www.osgi.org/xmlns/scr/v1.1.0'
enabled='false'
name='org.apache.felix.scr.integration.components.Felix4350Component'
activate='start' deactivate='stop'>
<implementation
class='org.apache.felix.scr.integration.components.Felix4350Component' />
<reference name='component1'
interface='org.apache.felix.scr.integration.components.SimpleComponent'
cardinality='1..1' bind='bindComponent1'
unbind='unbindComponent1' policy='static' />
<reference name='component2'
interface='org.apache.felix.scr.integration.components.SimpleComponent2'
cardinality='1..1' bind='bindComponent2'
unbind='unbindComponent2' policy='static' />
</scr:component>
</components>
{code}
The explanation is the following:
* the 2 dependencies are registered
* main is enabled
* it will go into the prebind() phase and call the first dependency factory,
and the second one
* while the second while is waiting, the first dependency is unregistered
* the component is created and bound to an unregistered service
I'll now work on a fix.
> Component wrongly activated
> ---------------------------
>
> Key: FELIX-4350
> URL: https://issues.apache.org/jira/browse/FELIX-4350
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Reporter: Guillaume Nodet
> Attachments: karaf.log
>
>
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)