You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by afilippov <an...@gmail.com> on 2011/08/30 17:10:31 UTC

SMX osgi louse coupling

Hi there,

Need some architecture help... Imagine the following situation - I have:

Bundle 1 where service interface and its default implementation are put.
Bundle 2 that has a reference to Bundle 1 and another implementation class.

Bundle 1 has no reference to the Bundle 2.

I wonder if there are any possibilities to tell which implementation to use
only by means of config settings?

It is all driven with Spring.

Appreciate.

--
View this message in context: http://servicemix.396122.n5.nabble.com/SMX-osgi-louse-coupling-tp4750392p4750392.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: SMX osgi louse coupling

Posted by afilippov <an...@gmail.com>.
Hi guys,
This is becoming crucial for me - still could not make this work.. Probably
anybody happen to have this stuff worked - any help appreciated..

Regards.

--
View this message in context: http://servicemix.396122.n5.nabble.com/SMX-osgi-loose-coupling-tp4750392p4769608.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: SMX osgi louse coupling

Posted by afilippov <an...@gmail.com>.
Hi - tried the solution with ranking - getting ClassNotFound.

I have the following:

*Bundle 1(independent):*
interface - com.xyz.HandlerIF,
implementation - com.xyz.impl.DefaultHandlerImpl implements HandlerIF
Declaration:
<bean id="contentHandler" class="com.xyz.impl.DefaultHandlerImpl">
<osgi:service auto-export="all-classes" ref="contentHandler" 
       			interface="com.xyz.HandlerIF" ranking="5"/>

*Bundle 2(dependent from Bundle 1):*
implementation - com.xyz.impl.MyHandlerImpl implements HandlerIF
Declaration:
<bean id="myContentHandler" class="com.xyz.impl.MyHandlerImpl">
<osgi:service auto-export="all-classes" ref="myContentHandler" 
       			interface="com.xyz.HandlerIF" ranking="6"/>

and stack trace looks like:

Caused by: java.lang.ClassNotFoundException: com.xyz.impl.MyHandlerImpl not
found from bundle [my-content-handler]
	at
org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:103)
	at
org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
	at
org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1271)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1242)
	... 11 more
Caused by: java.lang.ClassNotFoundException: com.xyz.impl.MyHandlerImpl not
found by default-content-handler [287]
	at
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
	at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
	at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)

I thought with the aim of loose coupling we could keep Bundle 1 independent
of Bundle 2 - could it be so?

Appreciate.


--
View this message in context: http://servicemix.396122.n5.nabble.com/SMX-osgi-louse-coupling-tp4750392p4757528.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: SMX osgi louse coupling

Posted by afilippov <an...@gmail.com>.
Thanks a lot - seems that it is exactly that I am looking for..

--
View this message in context: http://servicemix.396122.n5.nabble.com/SMX-osgi-louse-coupling-tp4750392p4750618.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: SMX osgi louse coupling

Posted by afilippov <an...@gmail.com>.
...and in addition to the previous question about placeholders - is it
possible to share 1 placeholder between 2 bundles?

thx.

--
View this message in context: http://servicemix.396122.n5.nabble.com/SMX-osgi-louse-coupling-tp4750392p4754806.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: SMX osgi louse coupling

Posted by afilippov <an...@gmail.com>.
Hi again - probably you could give me another tip in this context...

So I have a config file with this:

<osgix:cm-properties id="contentHandlerProps"
persistent-id="integration.content.handler">
        <prop key="content.handler.host">localhost</prop>
        <prop key="content.handler.port">8080</prop>
        <prop key="content.handler.username">admin</prop>
        <prop key="content.handler.pwd">admin</prop>
        <prop key="default.handler.rank">5</prop>
  </osgix:cm-properties>

  <ctx:property-placeholder properties-ref="contentHandlerProps" />
  
  <osgi:service auto-export="all-classes" ref="contentHandler" 
       			interface="biz.integration.handle.content.ContentHandler"
ranking="${default.handler.rank}">

As soon as I trying to start it in the container I am getting:

Caused by: org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1:
'${default.handler.rank}' is not a valid value for 'integer'.

I wonder if there are a possibility to put attribute from config file?

Thanks.

--
View this message in context: http://servicemix.396122.n5.nabble.com/SMX-osgi-louse-coupling-tp4750392p4753782.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: SMX osgi louse coupling

Posted by Andreas Pieber <an...@gmail.com>.
Simply use the ranking attribute; Service in Bundle 1 becomes e.g. ranking 0
and Service in Bundle 2 becomes ranking 10; the moment Bundle 2 pops up this
service will be used instead of the one in Bundle 1;

Example taken from [1]:

<service ref="beanToBeExported" interface="com.xyz.MyServiceInterface"
  ranking="9"/>

http://static.springsource.org/osgi/docs/1.1.x/reference/html/service-registry.html

Kind regards,
Andreas


On Tue, Aug 30, 2011 at 17:10, afilippov <an...@gmail.com>wrote:

> Hi there,
>
> Need some architecture help... Imagine the following situation - I have:
>
> Bundle 1 where service interface and its default implementation are put.
> Bundle 2 that has a reference to Bundle 1 and another implementation class.
>
> Bundle 1 has no reference to the Bundle 2.
>
> I wonder if there are any possibilities to tell which implementation to use
> only by means of config settings?
>
> It is all driven with Spring.
>
> Appreciate.
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/SMX-osgi-louse-coupling-tp4750392p4750392.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>