2009/6/1 Aaron Zeckoski <[email protected]> > I am having trouble utilizing the service tracker events. There are 3 > of them (add, modify, remove) and I am calling my own methods which > try to start my service if the services I require are available (or > shut it down when they are no longer available). > > The issue is that the adding event happens before the service is added > into the tracker so when I call my start method it cannot find the > service yet. >
that's part of the design - the instance returned by the "addingService" method is the object you want tracked, so it won't be available from the trackers "getService" method until "addingService" returns. however, you could pass the service object (which is available inside the "addingService" method) to some sort of "combiner" that collects together all the various service dependencies and only activates your component (or in this case registers the servlet) when it has them all you might also want to consider using a ServiceTrackerCustomizer to extend the behaviour rather than sub-classing the service tracker Here is the code if anyone is insterested: > > http://code.google.com/p/azsandbox/source/browse/trunk/osgi-sample/sample-servlet/src/main/java/org/azeckoski/sample/internal/SampleServletActivator.java > > I ended up creating something a lot more complicated which uses both > the servicetracker and also the servicelistener and only uses the > listener events but it seems like maybe I am doing something wrong > here. Is it possible to utilize the servicetracker events and also use > it to get the service out while the event method is triggering or is > that not really what the events are for? > > I would prefer to not to have to use DS or big libraries for such a > simple bundle in this case but maybe that is just not practical. FWIW the Apache Felix DS implementation (called SCR) is only ~100k > -AZ > > -- > Aaron Zeckoski ([email protected]) > Senior Research Engineer - CARET - Cambridge University > https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski > http://aaronz-sakai.blogspot.com/ - > http://confluence.sakaiproject.org/confluence/display/~aaronz/<http://confluence.sakaiproject.org/confluence/display/%7Eaaronz/> > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev > -- Cheers, Stuart
_______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
