开发者

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="a开发者_Python百科ddPersonListener"
        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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜