Hi,

On 06.05.2009, at 18:20, Vrignaud Etienne wrote:

Hi,

I am trying to figure out why the @WBP annotation exist, and what are the advantages compared to using the @Requires annotation. I failed to find some details regarding that point on the documentation. (http://felix.apache.org/site/white-board-pattern-handler.html )

I managed to create the @WBP behavior using the @Requires, @Bind, @Unbind annotations (explained in the example 1).
And in my point of view it does quite the same.
So I think perhaps I mist something.
The main advantage that I see with this kind of implementation is that the filtered class is not a 'dead String', but a reference to an existing interface.

Well, It's basically the same. The whiteboard pattern is equivalent to a:
- aggregate optional filtered dependency
- with bind and unbind method receiving the service reference

One difference is that the WBP does not get the service object, so, do not have any class loading issue. This might be useful when the service reference is just analyzed and given to another component (like, for example in the Device Access Specification).

The onModification callback is called when a matching service is "updated" (service properties updated). Regular requirement does not support such kind of notification. (modifications are mapped to arrivals / departures).

Regards,

Clement



For example I see one difference. The @WBP annotation have a 'onModification' field (as exposed in the example 2). But I didn't manage to try it, because I never reach the case when it is called.

-------------------------------------------------------------------------------------------
Implementation example 1:

@Component
public class RestActivator
{
        @Requires(id = "plugins", optional = true)
        private Plugin[] plugins;

        @Bind(id = "plugins")
        private synchronized void addplugin(Restplugin plugin)
        {
                // ...
        }

        @Unbind(id = "plugins")
        private synchronized void removeplugin(Restplugin plugin)
        {
                // ...
        }
}

-------------------------------------------------------------------------------------------
Implementation example 2:

@Component
@Wbp(filter = "(objectClass=com.test.Plugin)",
onArrival = "onArrival", onDeparture = "onDeparture", onModification = "onModification")
public class PluginContainer
{
        public void onArrival(ServiceReference ref)
        {
                // ...
        }

        public void onDeparture(ServiceReference ref)
        {
                // ...
        }

        public void onModification(ServiceReference ref)
        {
                // ...
        }
}

Regards,
/Etienne


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to