pderop opened a new pull request, #598:
URL: https://github.com/apache/felix-dev/pull/598

   Motivation:
   
   ServiceRegistryCacheManager initialized itself from a static initializer, 
which called start() on the DM bundle in order to get its BundleContext. When a 
user bundle is started before the DM bundle, the framework may not start the DM 
bundle synchronously, so getBundleContext() returned null. The static 
initializer then failed with a NullPointerException, and 
ServiceRegistryCacheManager became unusable for every DM bundle 
(NoClassDefFoundError: Could not initialize class ...).
   
   This can happen when threads that start bundles in parallel are launched 
while the framework is still starting and raising its start levels: a user 
bundle may then be started before the DM bundle, which is still waiting to be 
started by the framework start level thread.
   
   Until now, DM in parallel mode has only been tested after the 
FrameworkStarted event, once the framework is fully started and all the start 
levels are reached. This is why the problem was never seen.
   
   Modification:
   
   The cache is now initialized by the DM bundle Activator, using its own 
BundleContext, and the static initializer is removed:
   
   - Activator.start() calls ServiceRegistryCacheManager.init(context), which 
creates the configured filter indices once. The framework serializes the 
Activator start, so no extra locking is needed.
   
   - getCache(), called by DependencyManager, now locates the DM bundle with 
FrameworkUtil and starts it transiently if it is not active. If another thread 
is already starting the DM bundle, the framework blocks the caller until the DM 
Activator has completed, so the cache is ready when the DependencyManager is 
created.
   
   - While the framework is raising its start level, it may refuse a transient 
start because the DM bundle start level is not met yet. In this case, the DM 
bundle is started with a persistent start, which lets the framework start it 
now if it can, else later (the caller then does not use the cache).
   
   The service registry cache is only an optimization: getCache never throws. 
If the DM bundle cannot be started, the error is reported and the 
DependencyManager is created without cache, so that bundles can still start.
   
   A new unit test, FELIX6874_ParallelStartTest, starts 100 user bundles and 
the DM bundle from a pool of threads, on an embedded Felix framework, with and 
without a filter index. The Felix framework is added as a test dependency for 
it.
   
   Result:
   
   Starting bundles in parallel no longer breaks ServiceRegistryCacheManager. 
The new test fails with the previous code and passes with this fix.
   
   Ref #236


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to