Results 1 to 7 of 7

Thread: Referencing a map of services

  1. #1
    Join Date
    Jul 2008
    Posts
    9

    Default Referencing a map of services

    Hello,
    Is it possible to reference a map of services ?
    I have a bean which has a map property that should contains services provided by another bundle, indexed by the service name. In fact I would like to have something like:
    Code:
    <osgi:map id="myMap" interface="IService" key-ref="IService.popertyName"></osgi:map>

  2. #2
    Join Date
    Nov 2008
    Posts
    29

    Default

    Hi, MrMagne,

    My opinion is: you could provide service under one interface, then you could get a service collection, next, pick the exact one with "beanname" property.

    See

    6.2.2. Referencing a collection of services

    of DM's reference doc.

    I wish my word will help.

  3. #3
    Join Date
    Jul 2008
    Posts
    9

    Default

    Quote Originally Posted by gengshg View Post
    I wish my word will help.
    Sorry, but it didn't

    I will try to explain myself more clearly. I have a ServiceManager that owns a map of IService. I want to add some IService that are declared as osgi services. So how do I modify the declaration of my bean ServiceManager to incorporate those IService, knowing that this ServiceManager takes as an input a map, not a list.
    Code:
    <osgi:list id="myExternalServices" interface="IService"/>
    <bean id="serviceManager" class="Servicemanager">
        <property name="services">
            <map>
                 <entry key="aServiceName">
                     <ref bean="myLocalService" />
                 </entry>
                 <!-- how to add the content of myExternalServices to this map ? -->
            </map> 
        </property>
    </bean>
    I could of course modify my ServiceManager to make him accept a list, but that is a refactoring I want to avoid.

    Moreover If I introduce a setServices(List<IService> list) where I put hte elements of this list in my map, my list won't be managed anymore by SpringDM, am I wrong ? (I mean if one of the IService disappear because its bundle is down, my ServiceManager will still refer to that IService)

    I hope I managed to explain my problem more clearly...

  4. #4
    Join Date
    Nov 2008
    Posts
    29

    Default

    Hi,MrMagne
    Another hint is Services referenced from other bundle are proxy, not the object itself (the proxy was add by DM), would this be help?

    Infact, proxy would also be held by Map, but with DM, service object may not exist, but it's proxy always exist, so when you invoke or reference such a proxied service, many undesirable things may happen.

    So you could view the state of services with osgi command when you declare services directly. But warp service inside map, I really think could loss those benefits.

  5. #5
    Join Date
    Jul 2008
    Posts
    9

    Default

    I think you confirm what I thought: I will have to change my ServiceManager to make it use a list instead of a map if I want to keep the advantages of SpringDM.
    But I still think it would be a nice feature to have a <osgi:map> element, don't you think ?

    Anyway, thanks for your replies

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

    Default

    Spring DM doesn't offer a dynamic map. Since the collection is read-only, it's hard to define what is the key and what is the value since it depends on the user application.
    You could wrap a Map around a Spring DM collection which can monitor the state but then it's likely you'll end up duplicating the collection behaviour especially with respect to threading while iterating.
    If that's not an issue, you could use listeners to remove/add objects in your 'decorated' map.

    What's the relationship between the keys and values? If one can be 'infered/determined' from the other then you could use a list of services and extract the value from it.
    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

  7. #7
    Join Date
    Jul 2008
    Posts
    9

    Default

    Hi Colin, thanks for your reply.

    What I suggested was a map indexed by a property of the service (mainly its name). Of course I can iterate thru my list and retain the result with the matching name, I just think it is less elegant than doing a get() on a map... that why I think SpringDM could offer map of service for those who prefer to see it as map instead of a list.

    Concerning my problem I will change my ServiceManager to make it use a list instead of map.

Posting Permissions

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