You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Sergey Shcherbakov <ss...@echelon.de> on 2009/10/06 12:10:41 UTC

Simple service instancing question

Hi all,

 

I am new to Servicemix and OSGi therefore sorry for a probably stupid
question.

Do I understand correctly that a service within a Servicemix container
is in essence a single object instance serving a given contract
(interface[s])?

I mean, is that correct that it is not possible (by design) to obtain a
new service object instance by each call to a BundleContext.getService()
<http://www.knopflerfish.org/releases/current/docs/javadoc/org/osgi/fram
ework/BundleContext.html#getService(org.osgi.framework.ServiceReference)
> ?

As I understand, according to this tutorial article:
http://www.knopflerfish.org/osgi_service_tutorial.html this is not
possible.

At maximum, I get can a list of service objects registered in the
container and select a needed one by myself or I can get a separate
service object "per bundle", but I cannot make the service factory to
instantiate a new service instance every time my bundle wants to call
it?

 

Best Regards,

Sergey Shcherbakov.


RE: Simple service instancing question

Posted by Sergey Shcherbakov <ss...@echelon.de>.
Gert,

I looked through the presentation and figured out that one of the
Blueprint Services implementation is part of the Apache Karaf.
You were saying: "then use that object as a factory for creating new
instances and injecting them in some other bean."
But I am not sure if that is what my question is about.

What I would like to achieve is a "Per Call" service object
instantiation mode similar to that of Microsoft WCF.
What I am looking for is actually not only a getting of a service
reference and injecting it. 
I'd like to grab resources on the service side at the beginning of the
call and release them afterwards and all that in a thread safe manner
without special coding.
Or simply to speak: get a reference to a new service object instance
each time I call getService().

Would be great, if that's what Karaf/Geronimo Blueprint Services allow
(Spring DM Server has a restrictive license AFAIK).

Best Regards,
Sergey Shcherbakov.

-----Original Message-----
From: Sergey Shcherbakov [mailto:sshcherbakov@echelon.de] 
Sent: Wednesday, October 07, 2009 11:08 AM
To: users@servicemix.apache.org
Subject: RE: Simple service instancing question

Thank you, Gerd, for a detailed answer. I'll definitely look through the
presentation you sent a link to.

But if we would talk exclusively about what is available in the
Servicemix distribution, would the following excerpt from the
Knopflerfish tutorial I mentioned at the beginning still be true?

"An OSGi service factory is a special class ServiceFactory, which can
create individual instances of service objects for different bundles.
... Note: The framework will cache generated service objects. Thus, at
most one service can be generated per client bundle."

Best Regards,
Sergey Shcherbakov.

-----Original Message-----
From: Gert Vanthienen [mailto:gert.vanthienen@gmail.com] 
Sent: Tuesday, October 06, 2009 9:45 PM
To: users@servicemix.apache.org
Subject: Re: Simple service instancing question

Sergey,

You can always register a factory for your Service in the OSGi
registry.  That way, you can get a reference to the service factory
and create a new object instance using the factory.  If you're
building applications for ServiceMix 4, I would really recommend you
to look into Spring DM or (even better) Blueprint services to ease the
effort to register new services and consume them afterwards.

Guillaume has made an excellent introduction presentation on Blueprint
available on Slideshare
(http://www.slideshare.net/gnodet/osgi-blueprint-services-1622424),
which shows how you can get a service reference (or in your case, a
reference to the service factory) and then use that object as a
factory for creating new instances and injecting them in some other
bean.

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/10/6 Sergey Shcherbakov <ss...@echelon.de>:
> Hi all,
>
>
>
> I am new to Servicemix and OSGi therefore sorry for a probably stupid
> question.
>
> Do I understand correctly that a service within a Servicemix container
> is in essence a single object instance serving a given contract
> (interface[s])?
>
> I mean, is that correct that it is not possible (by design) to obtain
a
> new service object instance by each call to a
BundleContext.getService()
>
<http://www.knopflerfish.org/releases/current/docs/javadoc/org/osgi/fram
>
ework/BundleContext.html#getService(org.osgi.framework.ServiceReference)
>> ?
>
> As I understand, according to this tutorial article:
> http://www.knopflerfish.org/osgi_service_tutorial.html this is not
> possible.
>
> At maximum, I get can a list of service objects registered in the
> container and select a needed one by myself or I can get a separate
> service object "per bundle", but I cannot make the service factory to
> instantiate a new service instance every time my bundle wants to call
> it?
>
>
>
> Best Regards,
>
> Sergey Shcherbakov.
>
>

RE: Simple service instancing question

Posted by Sergey Shcherbakov <ss...@echelon.de>.
Thank you, Gerd, for a detailed answer. I'll definitely look through the
presentation you sent a link to.

But if we would talk exclusively about what is available in the
Servicemix distribution, would the following excerpt from the
Knopflerfish tutorial I mentioned at the beginning still be true?

"An OSGi service factory is a special class ServiceFactory, which can
create individual instances of service objects for different bundles.
... Note: The framework will cache generated service objects. Thus, at
most one service can be generated per client bundle."

Best Regards,
Sergey Shcherbakov.

-----Original Message-----
From: Gert Vanthienen [mailto:gert.vanthienen@gmail.com] 
Sent: Tuesday, October 06, 2009 9:45 PM
To: users@servicemix.apache.org
Subject: Re: Simple service instancing question

Sergey,

You can always register a factory for your Service in the OSGi
registry.  That way, you can get a reference to the service factory
and create a new object instance using the factory.  If you're
building applications for ServiceMix 4, I would really recommend you
to look into Spring DM or (even better) Blueprint services to ease the
effort to register new services and consume them afterwards.

Guillaume has made an excellent introduction presentation on Blueprint
available on Slideshare
(http://www.slideshare.net/gnodet/osgi-blueprint-services-1622424),
which shows how you can get a service reference (or in your case, a
reference to the service factory) and then use that object as a
factory for creating new instances and injecting them in some other
bean.

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/10/6 Sergey Shcherbakov <ss...@echelon.de>:
> Hi all,
>
>
>
> I am new to Servicemix and OSGi therefore sorry for a probably stupid
> question.
>
> Do I understand correctly that a service within a Servicemix container
> is in essence a single object instance serving a given contract
> (interface[s])?
>
> I mean, is that correct that it is not possible (by design) to obtain
a
> new service object instance by each call to a
BundleContext.getService()
>
<http://www.knopflerfish.org/releases/current/docs/javadoc/org/osgi/fram
>
ework/BundleContext.html#getService(org.osgi.framework.ServiceReference)
>> ?
>
> As I understand, according to this tutorial article:
> http://www.knopflerfish.org/osgi_service_tutorial.html this is not
> possible.
>
> At maximum, I get can a list of service objects registered in the
> container and select a needed one by myself or I can get a separate
> service object "per bundle", but I cannot make the service factory to
> instantiate a new service instance every time my bundle wants to call
> it?
>
>
>
> Best Regards,
>
> Sergey Shcherbakov.
>
>

Re: Simple service instancing question

Posted by Gert Vanthienen <ge...@gmail.com>.
Sergey,

You can always register a factory for your Service in the OSGi
registry.  That way, you can get a reference to the service factory
and create a new object instance using the factory.  If you're
building applications for ServiceMix 4, I would really recommend you
to look into Spring DM or (even better) Blueprint services to ease the
effort to register new services and consume them afterwards.

Guillaume has made an excellent introduction presentation on Blueprint
available on Slideshare
(http://www.slideshare.net/gnodet/osgi-blueprint-services-1622424),
which shows how you can get a service reference (or in your case, a
reference to the service factory) and then use that object as a
factory for creating new instances and injecting them in some other
bean.

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/10/6 Sergey Shcherbakov <ss...@echelon.de>:
> Hi all,
>
>
>
> I am new to Servicemix and OSGi therefore sorry for a probably stupid
> question.
>
> Do I understand correctly that a service within a Servicemix container
> is in essence a single object instance serving a given contract
> (interface[s])?
>
> I mean, is that correct that it is not possible (by design) to obtain a
> new service object instance by each call to a BundleContext.getService()
> <http://www.knopflerfish.org/releases/current/docs/javadoc/org/osgi/fram
> ework/BundleContext.html#getService(org.osgi.framework.ServiceReference)
>> ?
>
> As I understand, according to this tutorial article:
> http://www.knopflerfish.org/osgi_service_tutorial.html this is not
> possible.
>
> At maximum, I get can a list of service objects registered in the
> container and select a needed one by myself or I can get a separate
> service object "per bundle", but I cannot make the service factory to
> instantiate a new service instance every time my bundle wants to call
> it?
>
>
>
> Best Regards,
>
> Sergey Shcherbakov.
>
>