Hi,
On 30.06.2010, at 08:42, LongkerDandy wrote:
> Hi
>
> I'm using the iPOJO WhiteBoard handler like this:
>
> public final void onArrival(final ServiceReference ref) {
> final IWebModule module = (IWebModule) this.context.getService(ref);
> synchronized (lock) {
> //do something with the module service
> }
> this.context.ungetService(ref);
> }
>
> public final void onDeparture(final ServiceReference ref) {
> final IWebModule module = (IWebModule) this.context.getService(ref);
> synchronized (lock) {
> //do something with the module service
> }
> this.context.ungetService(ref);
> }
>
>
>> From what I see, I can only have the ServiceReference injected.
> To get the real service object, I also need a BundleContext.
> And using getService and ungetService.
> Which make the code "Un-POJO".
>
> And the above code, in onDeparture method,
> this.context.getService(ref); returns null.
> So there is something wrong.
>
> Is there a way to get the POJO service directly without messing up with
> ServiceReference? Or any best practice using iPOJO WhiteBoard.
From what I see, you don't need the Whiteboard pattern handler here.
Just do
@Bind
public void addWebModule(IWebModule web, Map props) {
...
}
@Unbind
public void removeWebModule(IWebModule web) {
...
}
The second arguments of the bind method is a map containing the service
properties of the service. If you don't need them, then just remove the
argument. The first arguments is the service object (so you don't need the
bundle context.)
The whiteboard pattern handler is generally used when you don't need to get the
service object, but just the service reference to for example inject this
reference inside another component.
Regards,
Clement
>
> Regards
> LongkerDandy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]