You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Christian Schneider <ch...@die-schneider.net> on 2015/07/09 17:45:22 UTC

Using service reference to a service created in the same blueprint context

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


Re: Using service reference to a service created in the same blueprint context

Posted by Guillaume Nodet <gn...@apache.org>.
The export of services and the wiring are done at the same time.
Each manager is created and started, it it's a bean manager, it will create
a bean in the internal blueprint container, if it's a service, it will
register it (without even creating the bean afaik).
You may want to move the order of your beans to move the services at the
top of your file, it may help.  Another way would be to use depends-on to
force the creation order.


2015-07-09 17:45 GMT+02:00 Christian Schneider <ch...@die-schneider.net>:

>  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" <http://www.osgi.org/xmlns/blueprint/v1.0.0>
>            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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" <http://www.osgi.org/xmlns/blueprint/v1.0.0http://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 Schneiderhttp://www.liquid-reality.de
>
> Open Source Architecthttp://www.talend.com
>
>