简体   繁体   中英

Using ServiceReference objects in Spring DM

I'm currently porting a very nice demo of a modular web interface using OSGi and Vaadin from 'standard OSGi' to use Spring DM.

One OSGi configuration file listed:

<reference name="PersonListener"
        interface="com.siemens.ct.pm.model.IPersonListener"
        bind="addPersonListener"
        unbind="removePersonListener"
        cardinality="0..n"
        policy="dynamic"/>

I realise that in Spring DM this has to be done using listeners, hence the following bean configuration:

<osgi:list id="personListeners" interface="be.nnuytten.pm.model.IPersonListener" cardinality="0..N">
        <osgi:listener ref="personManager" bind-method="addPersonListener" unbind-method="removePersonListener" />
</osgi:list>

In the reference documentation I found that the addPersonListener and removePersonListener methods need the following signature:

public void anyMethodName(ServiceReference ref);

All said and done, but now the question comes up: how do I work with this ServiceReference object? More specifically, how do I achieve the following by using a ServiceReference?

public synchronized void addPersonListener(IPersonListener personListener) {
        logger.info("add personListener: " + personListener);
        personListeners.add(personListener);
    }

The same functionality now has to be implemented by

public void addPersonListener(ServiceReference ref){}

Your help is as always most appreciated!

In case this is still unresolved.

I did something similar with Virgo (which is based on Spring DM). You don't have to use ServiceReference. It all depends on the method signatures:

<osgi:list id="xyzzyList" interface="Xyzzy"
    cardinality="0..N">
    <osgi:listener ref="xyzzyRegistry" bind-method="onBind" unbind-method="onUnbind" />
</osgi:list>

and onBind() method in implementation of Xyzzy

public void onBind(Xyzzy xyzzy, Map<?, ?> properties) {
    register(xyzzy);
}

The question is of course, what do you do with the Map. I didn't do anything, really.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM