You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Snorre Lothar von Gohren Edwin <sn...@gmail.com> on 2013/05/22 16:07:56 UTC

ServiceTracker problems

Hi, im new to OSGi and using the felix framework.
My code can be found here: https://github.com/Snorlock/prosjektoppgavekode

My problem is that the removedService method is never called when a service
is stopped.
The servicetracker implementatition can be found here:
https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/impl

Im not using the customizer, just tried to use it to see if that solved the
problem.

The activator can be found here:
https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/internal

And a service that is beeing registerd can be found here:
https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.service.sign/src/org/snorre/sign/internal

So the thing is that addedService is beeing called everytime the service
bundle is started, but for some reason I cant get the removedService to get
called when I stop the service bundle. So basically my gui gets repetative
buttons because it never registers that a service is gone.

I dont know what is wrong and dont know how to debug this.
Im trying this maillist to see if someone might help.
Thx in advance.


-- 
Mvh
Snorre Lothar von Gohren Edwin
+47 411 611 94

Re: ServiceTracker problems

Posted by Neil Bartlett <nj...@gmail.com>.
"Cheating" is a very strange word to use! It is not cheating to get your
work done more quickly, easily and with less scope for mistakes.

There is an #osgi channel on freenode. However it is not very busy.

On Wed, May 22, 2013 at 3:51 PM, Snorre Lothar von Gohren Edwin <
snorre.edwin@gmail.com> wrote:

> Thank you very much. I have wondered if I should do that, but feel like
> cheating!
> But im writing a thesis so this is information i should put down.
> But another question, do this mailinglist have a irc channel?
>
>
> On Wed, May 22, 2013 at 4:45 PM, Neil Bartlett <nj...@gmail.com>
> wrote:
>
> > If you return null from your addingService method, it indicates that you
> > are not interested in that service. Therefore the tracker will not inform
> > you of any more events about that service.
> >
> > However since you are new to OSGi, you really should NOT be using
> > ServiceTracker!! I cannot emphasise this enough. ServiceTracker is meant
> > for advanced users who need to implement certain edge cases. You should
> use
> > a higher level abstraction; I recommend learning about Declarative
> > Services, it will make your life MUCH easier:
> > http://wiki.osgi.org/wiki/Declarative_Services
> >
> > Kind regards,
> > Neil
> >
> > On Wed, May 22, 2013 at 3:30 PM, Snorre Lothar von Gohren Edwin <
> > snorre.edwin@gmail.com> wrote:
> >
> > > Ahh thank you very much! It solved it.
> > > Do you mind explaining the reason for this?
> > > Im in the learning fase:)
> > >
> > >
> > > On Wed, May 22, 2013 at 4:25 PM, Chetan Mehrotra
> > > <ch...@gmail.com>wrote:
> > >
> > > > Try to modify the addingService in TrackerImpl and instead of
> returning
> > > > null delegate the call to parent
> > > >
> > > > @Override
> > > > public Object addingService(ServiceReference ref) {
> > > > System.out.println("Added a service with snorre");
> > > > button = new ServiceButton(ref);
> > > > button.addActionListener(new ButtonActionListener(frame, ref));
> > > > frame.addToolBarButton(button);
> > > > frame.addServiceToList(ref.getBundle().getSymbolicName());
> > > > return super.addingService(ref);
> > > > }
> > > >
> > > > That you get the expected flow working
> > > >
> > > > Chetan Mehrotra
> > > >
> > > >
> > > > On Wed, May 22, 2013 at 7:37 PM, Snorre Lothar von Gohren Edwin <
> > > > snorre.edwin@gmail.com> wrote:
> > > >
> > > > > Hi, im new to OSGi and using the felix framework.
> > > > > My code can be found here:
> > > > https://github.com/Snorlock/prosjektoppgavekode
> > > > >
> > > > > My problem is that the removedService method is never called when a
> > > > service
> > > > > is stopped.
> > > > > The servicetracker implementatition can be found here:
> > > > >
> > > > >
> > > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/impl
> > > > >
> > > > > Im not using the customizer, just tried to use it to see if that
> > solved
> > > > the
> > > > > problem.
> > > > >
> > > > > The activator can be found here:
> > > > >
> > > > >
> > > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/internal
> > > > >
> > > > > And a service that is beeing registerd can be found here:
> > > > >
> > > > >
> > > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.service.sign/src/org/snorre/sign/internal
> > > > >
> > > > > So the thing is that addedService is beeing called everytime the
> > > service
> > > > > bundle is started, but for some reason I cant get the
> removedService
> > to
> > > > get
> > > > > called when I stop the service bundle. So basically my gui gets
> > > > repetative
> > > > > buttons because it never registers that a service is gone.
> > > > >
> > > > > I dont know what is wrong and dont know how to debug this.
> > > > > Im trying this maillist to see if someone might help.
> > > > > Thx in advance.
> > > > >
> > > > >
> > > > > --
> > > > > Mvh
> > > > > Snorre Lothar von Gohren Edwin
> > > > > +47 411 611 94
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Mvh
> > > Snorre Lothar von Gohren Edwin
> > > +47 411 611 94
> > >
> >
>
>
>
> --
> Mvh
> Snorre Lothar von Gohren Edwin
> +47 411 611 94
>

Re: ServiceTracker problems

Posted by Snorre Lothar von Gohren Edwin <sn...@gmail.com>.
Thank you very much. I have wondered if I should do that, but feel like
cheating!
But im writing a thesis so this is information i should put down.
But another question, do this mailinglist have a irc channel?


On Wed, May 22, 2013 at 4:45 PM, Neil Bartlett <nj...@gmail.com> wrote:

> If you return null from your addingService method, it indicates that you
> are not interested in that service. Therefore the tracker will not inform
> you of any more events about that service.
>
> However since you are new to OSGi, you really should NOT be using
> ServiceTracker!! I cannot emphasise this enough. ServiceTracker is meant
> for advanced users who need to implement certain edge cases. You should use
> a higher level abstraction; I recommend learning about Declarative
> Services, it will make your life MUCH easier:
> http://wiki.osgi.org/wiki/Declarative_Services
>
> Kind regards,
> Neil
>
> On Wed, May 22, 2013 at 3:30 PM, Snorre Lothar von Gohren Edwin <
> snorre.edwin@gmail.com> wrote:
>
> > Ahh thank you very much! It solved it.
> > Do you mind explaining the reason for this?
> > Im in the learning fase:)
> >
> >
> > On Wed, May 22, 2013 at 4:25 PM, Chetan Mehrotra
> > <ch...@gmail.com>wrote:
> >
> > > Try to modify the addingService in TrackerImpl and instead of returning
> > > null delegate the call to parent
> > >
> > > @Override
> > > public Object addingService(ServiceReference ref) {
> > > System.out.println("Added a service with snorre");
> > > button = new ServiceButton(ref);
> > > button.addActionListener(new ButtonActionListener(frame, ref));
> > > frame.addToolBarButton(button);
> > > frame.addServiceToList(ref.getBundle().getSymbolicName());
> > > return super.addingService(ref);
> > > }
> > >
> > > That you get the expected flow working
> > >
> > > Chetan Mehrotra
> > >
> > >
> > > On Wed, May 22, 2013 at 7:37 PM, Snorre Lothar von Gohren Edwin <
> > > snorre.edwin@gmail.com> wrote:
> > >
> > > > Hi, im new to OSGi and using the felix framework.
> > > > My code can be found here:
> > > https://github.com/Snorlock/prosjektoppgavekode
> > > >
> > > > My problem is that the removedService method is never called when a
> > > service
> > > > is stopped.
> > > > The servicetracker implementatition can be found here:
> > > >
> > > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/impl
> > > >
> > > > Im not using the customizer, just tried to use it to see if that
> solved
> > > the
> > > > problem.
> > > >
> > > > The activator can be found here:
> > > >
> > > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/internal
> > > >
> > > > And a service that is beeing registerd can be found here:
> > > >
> > > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.service.sign/src/org/snorre/sign/internal
> > > >
> > > > So the thing is that addedService is beeing called everytime the
> > service
> > > > bundle is started, but for some reason I cant get the removedService
> to
> > > get
> > > > called when I stop the service bundle. So basically my gui gets
> > > repetative
> > > > buttons because it never registers that a service is gone.
> > > >
> > > > I dont know what is wrong and dont know how to debug this.
> > > > Im trying this maillist to see if someone might help.
> > > > Thx in advance.
> > > >
> > > >
> > > > --
> > > > Mvh
> > > > Snorre Lothar von Gohren Edwin
> > > > +47 411 611 94
> > > >
> > >
> >
> >
> >
> > --
> > Mvh
> > Snorre Lothar von Gohren Edwin
> > +47 411 611 94
> >
>



-- 
Mvh
Snorre Lothar von Gohren Edwin
+47 411 611 94

Re: ServiceTracker problems

Posted by Neil Bartlett <nj...@gmail.com>.
If you return null from your addingService method, it indicates that you
are not interested in that service. Therefore the tracker will not inform
you of any more events about that service.

However since you are new to OSGi, you really should NOT be using
ServiceTracker!! I cannot emphasise this enough. ServiceTracker is meant
for advanced users who need to implement certain edge cases. You should use
a higher level abstraction; I recommend learning about Declarative
Services, it will make your life MUCH easier:
http://wiki.osgi.org/wiki/Declarative_Services

Kind regards,
Neil

On Wed, May 22, 2013 at 3:30 PM, Snorre Lothar von Gohren Edwin <
snorre.edwin@gmail.com> wrote:

> Ahh thank you very much! It solved it.
> Do you mind explaining the reason for this?
> Im in the learning fase:)
>
>
> On Wed, May 22, 2013 at 4:25 PM, Chetan Mehrotra
> <ch...@gmail.com>wrote:
>
> > Try to modify the addingService in TrackerImpl and instead of returning
> > null delegate the call to parent
> >
> > @Override
> > public Object addingService(ServiceReference ref) {
> > System.out.println("Added a service with snorre");
> > button = new ServiceButton(ref);
> > button.addActionListener(new ButtonActionListener(frame, ref));
> > frame.addToolBarButton(button);
> > frame.addServiceToList(ref.getBundle().getSymbolicName());
> > return super.addingService(ref);
> > }
> >
> > That you get the expected flow working
> >
> > Chetan Mehrotra
> >
> >
> > On Wed, May 22, 2013 at 7:37 PM, Snorre Lothar von Gohren Edwin <
> > snorre.edwin@gmail.com> wrote:
> >
> > > Hi, im new to OSGi and using the felix framework.
> > > My code can be found here:
> > https://github.com/Snorlock/prosjektoppgavekode
> > >
> > > My problem is that the removedService method is never called when a
> > service
> > > is stopped.
> > > The servicetracker implementatition can be found here:
> > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/impl
> > >
> > > Im not using the customizer, just tried to use it to see if that solved
> > the
> > > problem.
> > >
> > > The activator can be found here:
> > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/internal
> > >
> > > And a service that is beeing registerd can be found here:
> > >
> > >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.service.sign/src/org/snorre/sign/internal
> > >
> > > So the thing is that addedService is beeing called everytime the
> service
> > > bundle is started, but for some reason I cant get the removedService to
> > get
> > > called when I stop the service bundle. So basically my gui gets
> > repetative
> > > buttons because it never registers that a service is gone.
> > >
> > > I dont know what is wrong and dont know how to debug this.
> > > Im trying this maillist to see if someone might help.
> > > Thx in advance.
> > >
> > >
> > > --
> > > Mvh
> > > Snorre Lothar von Gohren Edwin
> > > +47 411 611 94
> > >
> >
>
>
>
> --
> Mvh
> Snorre Lothar von Gohren Edwin
> +47 411 611 94
>

Re: ServiceTracker problems

Posted by Snorre Lothar von Gohren Edwin <sn...@gmail.com>.
Ahh thank you very much! It solved it.
Do you mind explaining the reason for this?
Im in the learning fase:)


On Wed, May 22, 2013 at 4:25 PM, Chetan Mehrotra
<ch...@gmail.com>wrote:

> Try to modify the addingService in TrackerImpl and instead of returning
> null delegate the call to parent
>
> @Override
> public Object addingService(ServiceReference ref) {
> System.out.println("Added a service with snorre");
> button = new ServiceButton(ref);
> button.addActionListener(new ButtonActionListener(frame, ref));
> frame.addToolBarButton(button);
> frame.addServiceToList(ref.getBundle().getSymbolicName());
> return super.addingService(ref);
> }
>
> That you get the expected flow working
>
> Chetan Mehrotra
>
>
> On Wed, May 22, 2013 at 7:37 PM, Snorre Lothar von Gohren Edwin <
> snorre.edwin@gmail.com> wrote:
>
> > Hi, im new to OSGi and using the felix framework.
> > My code can be found here:
> https://github.com/Snorlock/prosjektoppgavekode
> >
> > My problem is that the removedService method is never called when a
> service
> > is stopped.
> > The servicetracker implementatition can be found here:
> >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/impl
> >
> > Im not using the customizer, just tried to use it to see if that solved
> the
> > problem.
> >
> > The activator can be found here:
> >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/internal
> >
> > And a service that is beeing registerd can be found here:
> >
> >
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.service.sign/src/org/snorre/sign/internal
> >
> > So the thing is that addedService is beeing called everytime the service
> > bundle is started, but for some reason I cant get the removedService to
> get
> > called when I stop the service bundle. So basically my gui gets
> repetative
> > buttons because it never registers that a service is gone.
> >
> > I dont know what is wrong and dont know how to debug this.
> > Im trying this maillist to see if someone might help.
> > Thx in advance.
> >
> >
> > --
> > Mvh
> > Snorre Lothar von Gohren Edwin
> > +47 411 611 94
> >
>



-- 
Mvh
Snorre Lothar von Gohren Edwin
+47 411 611 94

Re: ServiceTracker problems

Posted by Chetan Mehrotra <ch...@gmail.com>.
Try to modify the addingService in TrackerImpl and instead of returning
null delegate the call to parent

@Override
public Object addingService(ServiceReference ref) {
System.out.println("Added a service with snorre");
button = new ServiceButton(ref);
button.addActionListener(new ButtonActionListener(frame, ref));
frame.addToolBarButton(button);
frame.addServiceToList(ref.getBundle().getSymbolicName());
return super.addingService(ref);
}

That you get the expected flow working

Chetan Mehrotra


On Wed, May 22, 2013 at 7:37 PM, Snorre Lothar von Gohren Edwin <
snorre.edwin@gmail.com> wrote:

> Hi, im new to OSGi and using the felix framework.
> My code can be found here: https://github.com/Snorlock/prosjektoppgavekode
>
> My problem is that the removedService method is never called when a service
> is stopped.
> The servicetracker implementatition can be found here:
>
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/impl
>
> Im not using the customizer, just tried to use it to see if that solved the
> problem.
>
> The activator can be found here:
>
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.roadstation/src/org/snorre/roadstation/internal
>
> And a service that is beeing registerd can be found here:
>
> https://github.com/Snorlock/prosjektoppgavekode/tree/master/org.snorre.service.sign/src/org/snorre/sign/internal
>
> So the thing is that addedService is beeing called everytime the service
> bundle is started, but for some reason I cant get the removedService to get
> called when I stop the service bundle. So basically my gui gets repetative
> buttons because it never registers that a service is gone.
>
> I dont know what is wrong and dont know how to debug this.
> Im trying this maillist to see if someone might help.
> Thx in advance.
>
>
> --
> Mvh
> Snorre Lothar von Gohren Edwin
> +47 411 611 94
>