You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by gnanda1 <gi...@hotmail.com> on 2010/08/26 19:24:33 UTC

Servicemix 4.2 Writing an OSGI service

Hi All,
I have requirement to write an utility class that will be called from many
other cpmonents.  I think if I  can wrap this utility class as an OSGI
service then I can call from other components just by refrencing it and do a
simple method call on the class.
But not able to find any good document or example how to write and deploy an
OSGI service in servicemix4.2 container.

Any example or document will be very helpful.

Thanks
GNanda

-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Servicemix-4-2-Writing-an-OSGI-service-tp2730486p2730486.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Servicemix 4.2 Writing an OSGI service

Posted by gnanda1 <gi...@hotmail.com>.
When a consumer component calls a method of an OSGI service  in the producer
component, does  the message call pass thru NMR?

In the below example I guess TransformerInformationServiceImpl implements
TransformerInformationService. Is that sufficient enough to call a method in
TransformerInformationServiceImpl  referencing thru
ransformerInformationService?

Does that mean there is a limitation that ransformerInformationService can
have only one implemenation class, in other words there are no more than one
derived calss of ransformerInformationService?

Thanks Johan for all your time and help
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Servicemix-4-2-Writing-an-OSGI-service-tp2730486p2739420.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Servicemix 4.2 Writing an OSGI service

Posted by Johan Edstrom <se...@gmail.com>.

Since you use spring-dm, the whole cycle is taken car of for you.
Normal beans stay 'normal' but you can export them as an osgi service for
other spring contexts to consume (For unit-testing it is often handy to have two separate spring files) that you just put under META-INF/spring

Spring-DM will look at the osgi particulars and export your bean as an osgi service, it'll 
also handle the registration and disconnections for you.

Here are is a consuming example
<osgi:reference id="jmsConnectionPool" interface="javax.jms.ConnectionFactory"/>

It can be used like a normal bean

 <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="jmsConnectionPool" />
        <property name="transacted" value="true" />
        <property name="transactionManager" ref="transactionManager" />
    </bean>

Here is a producing example

<bean id="transformerHandler" class="edu.ucar.ral.wcsri.pubsub.sm.hidden.TransformerHandler">
        <constructor-arg value="${submgt.transformer.list}"/>
    </bean>

    <!-- TransformerInformation -->
    <bean id="transformerInformationService" class="edu.ucar.ral.wcsri.pubsub.sm.TransformerInformationServiceImpl">
        <property name="transformerHandler" ref="transformerHandler"/>
    </bean>


<osgi:service ref="transformerInformationService" interface="edu.ucar.ral.wcsri.pubsub.sm.TransformerInformationService"/>


On Aug 26, 2010, at 3:27 PM, gnanda1 wrote:

> 
> Thanks Johan for the quick reply.
> 
> I could able to create an OSGI service following the example.
> I referenced the service from another bundle by declaring in xbean.xml file
> <osgi:reference id="hello" interface="com.pf.sample.hello" />
> 
> But I am not very clear about few things
> If I have a POJO file  and I  declare it in a spring beans.xml file  as
> below
> <bean id="hello" class="com.pf.sample.hello">
> </bean>
> 
> If I deploy the compiled jar file in servicemix as an OSGI bundle, would
> that inetrnally creates an OSGI service? I do not register this calss with
> bundlecontext as an osgi service here though.
> 
> If yes, then how would I refer it in another bundle? what would be the
> reference id  and interface to refer it?
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/Servicemix-4-2-Writing-an-OSGI-service-tp2730486p2739250.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

Johan Edstrom

joed@opennms.org

They that can give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety.

Benjamin Franklin, Historical Review of Pennsylvania, 1759






Re: Servicemix 4.2 Writing an OSGI service

Posted by gnanda1 <gi...@hotmail.com>.
Thanks Johan for the quick reply.

I could able to create an OSGI service following the example.
I referenced the service from another bundle by declaring in xbean.xml file
<osgi:reference id="hello" interface="com.pf.sample.hello" />

But I am not very clear about few things
If I have a POJO file  and I  declare it in a spring beans.xml file  as
below
<bean id="hello" class="com.pf.sample.hello">
</bean>

If I deploy the compiled jar file in servicemix as an OSGI bundle, would
that inetrnally creates an OSGI service? I do not register this calss with
bundlecontext as an osgi service here though.

If yes, then how would I refer it in another bundle? what would be the
reference id  and interface to refer it?
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Servicemix-4-2-Writing-an-OSGI-service-tp2730486p2739250.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Servicemix 4.2 Writing an OSGI service

Posted by Johan Edstrom <se...@gmail.com>.
Here is a simple example.
http://java.dzone.com/articles/simple-osgi-service

That does it 'natively' if you simply want to quickly expose a service, look 
at Blueprint or Spring-DM to handle the lifecycle for you.

/je

On Aug 26, 2010, at 11:24 AM, gnanda1 wrote:

> 
> Hi All,
> I have requirement to write an utility class that will be called from many
> other cpmonents.  I think if I  can wrap this utility class as an OSGI
> service then I can call from other components just by refrencing it and do a
> simple method call on the class.
> But not able to find any good document or example how to write and deploy an
> OSGI service in servicemix4.2 container.
> 
> Any example or document will be very helpful.
> 
> Thanks
> GNanda
> 
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/Servicemix-4-2-Writing-an-OSGI-service-tp2730486p2730486.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

Johan Edstrom

joed@opennms.org

They that can give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety.

Benjamin Franklin, Historical Review of Pennsylvania, 1759