Results 1 to 2 of 2

Thread: Service publication and service listener notification

  1. #1
    Join Date
    Dec 2005
    Location
    Philadelphia, PA, USA
    Posts
    228

    Default Service publication and service listener notification

    Hi,

    I am looking for help in deciphering following issue.

    If service listener and service publication happens in the same bundle, order of beans in spring-config is important.

    Example 1:
    If service is published after osgi:list with osgi:listener, listener is invoked properly.
    Code:
    <osgi:list id="menuContributions" interface="shared.ui.menu.MenuContribution" cardinality="0..N">
            <osgi:listener bind-method="onBind" unbind-method="onUnbind">
                <bean class="shared.ui.menu.support.MenuContributionListener">
                    <constructor-arg ref="menuBuilder"/>
                </bean>
            </osgi:listener>
        </osgi:list>
    
        <osgi:service ref="hostMenuContribution" interface="shared.ui.menu.MenuContribution">
            <osgi:service-properties>
                <entry key="publisher" value="HOST"/>
            </osgi:service-properties>
        </osgi:service>
    Example 2:
    If service is published (osgi:service) before listener (osgi:list with osgi:listener), listener is not notified.

    Code:
        <osgi:service ref="hostMenuContribution" interface="shared.ui.menu.MenuContribution">
            <osgi:service-properties>
                <entry key="publisher" value="HOST"/>
            </osgi:service-properties>
        </osgi:service>
    
    <osgi:list id="menuContributions" interface="shared.ui.menu.MenuContribution" cardinality="0..N">
            <osgi:listener bind-method="onBind" unbind-method="onUnbind">
                <bean class="shared.ui.menu.support.MenuContributionListener">
                    <constructor-arg ref="menuBuilder"/>
                </bean>
            </osgi:listener>
        </osgi:list>
    From looking at the source code of org.springframework.osgi.service.importer.support. internal.collection.OsgiServiceCollection, I would expect a call to OsgiListenerUtils.addServiceListener() to nullify the need for order of beans.

    From OsgiServiceCollection.
    Code:
    // now get the already registered services and call the listener
    // (the listener should be able to handle duplicates)
    		dispatchServiceRegistrationEvents(OsgiServiceReferenceUtils.getServiceReferences(context, filter), listener);
    I debugged through the code and I actually do see published service with correct properties in the Framework service registry. But a call to bundleContext.getServiceReferences with a proper filter returns a null.

    Is there some timing issue that I am stumbling into? Felling very obtuse.

    p.s. This might be a spring-dm question, but I am seeing it in the server so posting here.

    Environment: dm-server 2 RC1, spring.dm 1.2.1, springframework 3 RELEASE
    Thanks
    Dmitry

  2. #2
    Join Date
    Oct 2008
    Location
    Winchester, UK
    Posts
    535

    Default

    This looks very similar to the other problem you raised. We'll take a look at the other problem in the next few days.
    Glyn Normington
    SpringSource

Posting Permissions

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