I got a customer that would like to use a quite exotic construct. They want to 
export a service in a blueprint context and import it in the same context.
I do not really recommend this model but they would prefer it to keep their 
code generation simple.
They know this is not possible with mandatory services so the used optional 
ones.

In a simple case the example below works. If the init method of serviceB calls 
serviceA though then we always get a ServiceUnavailableException.

My explanation was that the blueprint context is initialized in these stages:
- create references to services, wait till mandatory ones are present
- wire each bean and call init-method
- export all services

So the reason why it does not work for mandatory services is that the 
references are checked before our own services are exported.
The reason why the init-method with call to serviceA does not work is because 
the services are exported only after all beans are injected.

So I have two questions:
1. Is my model how blueprint starts up correct?
2. Could Aries blueprint theoretically be changed to export services as soon as 
all necessary beans are injected instead of at the end? Or is the startup model 
above mandated by the spec?

Best regards

Christian

----

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
                               
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>


    <bean id="aImpl" class="test.ServiceAImpl"/>
    <service ref="aImpl" interface="test.ServiceA"/>

    <reference id="serviceA" interface="test.ServiceA" availability="optional" 
timeout="60000"/>
    <bean id="bImpl" class="test.ServiceBImpl" init-method="init">
        <property name="serviceA" ref="serviceA"/>
    </bean>
    <service ref="bImpl" interface="test.ServiceB"/>

</blueprint>

--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

Reply via email to