I am not sure it is that unlikely. Scenario:
A framework is launching and there are 3 bundles: A (contains your snippet), Http, Log. They are all at the same start level and the framework chooses to start them in the order: A, Http, Log. A will start right up and create 2 trackers. No problem. Http starts up and registers the HttpService in its activator. The ServiceEvent is received by the tracker in A and A calls log which then waits for 10 seconds for a LogService. The thread launching the bundles is now blocked and the Log bundle wont be started to register its LogService. In this scenario, it does not matter how long you wait for a LogService. You might say a framework impl should use multiple threads to launch the bundles which would avoid this. But this is not required by the spec and we shouldn't promote coding examples which rely upon it. I think it is bad from to block for a long time in an event listener which is effect what your snippet suggests. The waitForService method warns about avoiding that in BundleActivator methods. I guess the warning should be extended to include event listener methods and ServiceTrackerCustomizer methods. To demonstrate the use of waitForService, it would be better to use a thread which is not related to event delivery and whose blocking does not impede progress of the system. BJ Hargrave Senior Technical Staff Member, IBM OSGi Fellow and CTO of the OSGi Alliance [EMAIL PROTECTED] office: +1 386 848 1781 mobile: +1 386 848 3788 Peter Kriens <[EMAIL PROTECTED]> 02/23/2007 08:04 AM To BJ Hargrave/Austin/[EMAIL PROTECTED] cc OSGi Developer Mail List <[email protected]> Subject Re[2]: [osgi-dev] Re: Knopflerfish and Eclipse The key word is potentially ... normally the log service will be there or shortly. It is highly unlikely that it will -ever- have to wait. So in the unlikely case you take a performance hit, but things keep on working. I just needed to demonstrate the waitForService as well. However, I'll add a comment about the synchronous behavior of service tracker. Kind regards, Peter Kriens BH> I am not sure that is such a great example. The log method block for BH> potentialy a very long time and thus can impede the ServiceEvent deliver BH> for HttpService. The ServiceTrackerCustomizer methods are called from the BH> ServiceListener inside ServiceTracker and should complete quickly. BH> BJ Hargrave BH> Senior Technical Staff Member, IBM BH> OSGi Fellow and CTO of the OSGi Alliance BH> [EMAIL PROTECTED] BH> office: +1 386 848 1781 BH> mobile: +1 386 848 3788 BH> Peter Kriens <[EMAIL PROTECTED]> BH> Sent by: [EMAIL PROTECTED] BH> 02/23/2007 04:11 AM BH> Please respond to BH> OSGi Developer Mail List <[email protected]> BH> To BH> Aggelos Mpimpoudis <[EMAIL PROTECTED]> BH> cc BH> [email protected] BH> Subject BH> Re: [osgi-dev] Re: Knopflerfish and Eclipse BH> If you need another example with the service tracker look at: BH> http://www.aqute.biz/Snippets/Tracker BH> There are also some similar examples. BH> Kind regards, BH> Peter Kriens BH> _______________________________________________ BH> OSGi Developer Mail List BH> [email protected] BH> http://www2.osgi.org/mailman/listinfo/osgi-dev -- Peter Kriens Tel +33467542167 9C, Avenue St. Drézéry AOL,Yahoo: pkriens 34160 Beaulieu, France ICQ 255570717 Skype pkriens Fax +1 8153772599 _______________________________________________ OSGi Developer Mail List [email protected] http://www2.osgi.org/mailman/listinfo/osgi-dev
