You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "m.jimen.blazquez" <m....@gmail.com> on 2012/01/11 16:12:35 UTC
Creating an alternative OsgiServiceRegistry
Hi,
I am working with camel, spring and OSGi (Spring DM). In my scenario I have
several OSGi services registered under the same interface (each one with
different implementation). This services could be differentiated by their
properties:
<osgi:service ref="orderService" interface="myPackage.Order">
<osgi:service-properties>
<entry key="version_impl" value="1.0.0"/>
</osgi:service-properties>
</osgi:service>
When looking in the registry, in the OsgiServiceRegistry, he code is the
following:
public Object lookup(String name) {
Object service = serviceCacheMap.get(name);
if (service == null) {
* ServiceReference sr = bundleContext.getServiceReference(name);
*
if (sr != null) {
// Need to keep the track of Service
// and call ungetService when the camel context is closed
serviceReferenceQueue.add(sr);
service = bundleContext.getService(sr);
if (service != null) {
serviceCacheMap.put(name, service);
}
}
}
return service;
}
but the method I would really want to invoke is this one:
String filter = "(&(objectClass=" + className + ") (version_impl=" + version
+ "))";
ServiceReference[] serviceReferences =
bundleContext.getServiceReferences(className,filter);
Do you recommend me to create a custom registry for my purposes?
kindest regards
--
View this message in context: http://camel.465427.n5.nabble.com/Creating-an-alternative-OsgiServiceRegistry-tp5137028p5137028.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Creating an alternative OsgiServiceRegistry
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
I think you can extends the OSGiServiceRegistry as you want, but you
still need to find a way to set the className and version things.
Maybe you can set the filter String when you create your version of
OSGiServiceRegistry.
On Wed Jan 11 23:12:35 2012, m.jimen.blazquez wrote:
> Hi,
>
> I am working with camel, spring and OSGi (Spring DM). In my scenario I have
> several OSGi services registered under the same interface (each one with
> different implementation). This services could be differentiated by their
> properties:
>
> <osgi:service ref="orderService" interface="myPackage.Order">
> <osgi:service-properties>
> <entry key="version_impl" value="1.0.0"/>
> </osgi:service-properties>
> </osgi:service>
>
> When looking in the registry, in the OsgiServiceRegistry, he code is the
> following:
>
> public Object lookup(String name) {
> Object service = serviceCacheMap.get(name);
> if (service == null) {
> * ServiceReference sr = bundleContext.getServiceReference(name);
> *
> if (sr != null) {
> // Need to keep the track of Service
> // and call ungetService when the camel context is closed
> serviceReferenceQueue.add(sr);
> service = bundleContext.getService(sr);
> if (service != null) {
> serviceCacheMap.put(name, service);
> }
> }
> }
> return service;
> }
>
> but the method I would really want to invoke is this one:
>
> String filter = "(&(objectClass=" + className + ") (version_impl=" + version
> + "))";
> ServiceReference[] serviceReferences =
> bundleContext.getServiceReferences(className,filter);
>
> Do you recommend me to create a custom registry for my purposes?
>
> kindest regards
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Creating-an-alternative-OsgiServiceRegistry-tp5137028p5137028.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang