Results 1 to 3 of 3

Thread: Is that possible to get osgi service reference without proxy?

  1. #1
    Join Date
    Feb 2010
    Location
    Dublin, Ireland
    Posts
    10

    Default Is that possible to get osgi service reference without proxy?

    It's easy to get an OSGi service with following simple configuration:
    <reference id="asyncMessageService" interface="com.xyz.MessageService"/>

    While it always return a proxy to original bean or service exposed by other bundles. I am wondering is that possible to get original instance instead proxy?

    Thanks!

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Yes, you can by casting the proxy to a Spring DM interface. See the reference documentation:
    http://static.springsource.org/osgi/...roperty-editor

    and the ImportedOsgiServiceProxy javadoc: http://static.springsource.org/osgi/...viceProxy.html
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Feb 2010
    Location
    Dublin, Ireland
    Posts
    10

    Default

    Hi Costin, first thanks for the reply.

    I tried following configuration:
    Code:
    <reference id="myService" interface="com.xyz.MyServiceInterface"/>
    		
    <bean id="serviceConsumer" class="MyServiceConsumerImpl">
      <property name="serviceReferenceField" ref="myService"/>                                      
      <property name="myServiceFiled" ref="myService"/>                                               
    </bean>
    I have com.xyz.MyServiceImpl bean exported as OSGi service from other bundle.

    My goal is to get the com.xyz.MyServiceImpl bean injected to serviceConsumer as myServiceFiled. Not the proxy created by Spring DM. I am not interested to get the raw ServiceReference.

    I don't like proxy for the service like cache interface, which could be invoked thousands times per second.

    Apologize if didn't make it clear at first place.

    However, I could get the raw service object by following code:
    Code:
    ServiceReference nativeReference = ((ServiceReferenceProxy)serviceReference).getTargetServiceReference();
    com.xyz.MyServiceImpl myServiceImpl= (com.xyz.MyServiceImpl)bundleContext.getService(nativeReference);
    I want to know is it possible to inject com.xyz.MyServiceImpl raw instance by configuration instead of my code. Or it could be a feature for future.

    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •