You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by jaredmac <jm...@mathworks.com> on 2008/10/29 18:44:08 UTC

Re: Invalid BundleContext

Hello group, 

Sorry this issue won't go away, but I've accumulated some more information
that might be helpful. 

First, I learned that the "Invalid BundleContext" error is often (but not
always) immediately followed by a "component is already registered" error:

ERROR: org.apache.felix.scr (2): Error while loading components of bundle
com.mathworks.matlab.desktop
java.lang.IllegalStateException: Invalid BundleContext.
	at
org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:453)
	at
org.apache.felix.framework.BundleContextImpl.createFilter(BundleContextImpl.java:102)
	...
ERROR: com.company.product.desktop (1): [foo] Cannot register Component
org.osgi.service.component.ComponentException: The component name 'foo' has
already been registered.
registered.
	at
org.apache.felix.scr.impl.ComponentRegistry.checkComponentName(ComponentRegistry.java:141)
	at
org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:165)
	at
org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:110)
	at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:227)
	at org.apache.felix.scr.impl.Activator.bundleChanged(Activator.java:173)
	at
org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:690)
	at
org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:619)
	at
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:532)
	at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3601)
	at org.apache.felix.framework.Felix._startBundle(Felix.java:1616)
	at org.apache.felix.framework.Felix.startBundle(Felix.java:1544)
	at org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java:1125)
	at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:258)
	at java.lang.Thread.run(Unknown Source)

The second thing I learned is that the problem almost entirely goes away
when I change my utility method that asks for a particular service from:

            result = (T) tracker.waitForService(1000);

to

            result = (T) tracker.waitForService(0);

i.e., I initially had a timeout of one second; when I changed that to be
zero (wait indefinitely), the sporadic failures reduced from about one in
three to one in 26. 

Hoping this is useful,
Jared
-- 
View this message in context: http://www.nabble.com/Invalid-BundleContext-tp19108424p20232208.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Invalid BundleContext

Posted by "Richard S. Hall" <he...@ungoverned.org>.
jaredmac wrote:
> OK, I've almost got it figured out. 
>
> The issue is that stopBundle() is indeed being called on a bundle, and this
> causes its BundleContext to be invalid.
>
> The reason stopBundle() is being called is that I'm using start levels, and
> doing the following:
>
> (1) Installing (and starting) bundles (with default start level of 1)
> (2) Starting Felix (with default start level of 1)
> (3) Adjusting start levels of already started bundles
> (4) Adjusting Felix's start level
>
> So in step (3), I've got a bundle with a current start level of 1 that I
> want to set to 10. Felix therefore correctly stops the bundle. Then in step
> (4) when I set Felix's start level to 10, the bundle is restarted. This is
> an extremely small window, which explains the sporadic behavior of the
> problem.
>
> It seems what I should be doing is getting the start levels in place before
> starting any bundles.
>
> I think there is still a bug in Felix here, though. I think there is a race
> condition between SCR attempting to activate the components of a bundle and
> Felix stopping the bundle, leading to the exception noted above.
>   

I am not sure it is a bug in Felix, but perhaps a bug some place. There 
is no way to lock an active bundle, so if someone is in the middle of 
using the BundleContext and someone else stops the bundle, the 
BundleContext will become invalid. That's just the way it is.

I guess it is possible for SCR to synchronously listen for STOPPING 
events and use this to block the framework from stopping the bundle 
until it is done using the bundle context...I am not sure what it is 
actually doing...or if this is really the issue.

-> richard

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Invalid BundleContext

Posted by jaredmac <jm...@mathworks.com>.
OK, I've almost got it figured out. 

The issue is that stopBundle() is indeed being called on a bundle, and this
causes its BundleContext to be invalid.

The reason stopBundle() is being called is that I'm using start levels, and
doing the following:

(1) Installing (and starting) bundles (with default start level of 1)
(2) Starting Felix (with default start level of 1)
(3) Adjusting start levels of already started bundles
(4) Adjusting Felix's start level

So in step (3), I've got a bundle with a current start level of 1 that I
want to set to 10. Felix therefore correctly stops the bundle. Then in step
(4) when I set Felix's start level to 10, the bundle is restarted. This is
an extremely small window, which explains the sporadic behavior of the
problem.

It seems what I should be doing is getting the start levels in place before
starting any bundles.

I think there is still a bug in Felix here, though. I think there is a race
condition between SCR attempting to activate the components of a bundle and
Felix stopping the bundle, leading to the exception noted above.
-- 
View this message in context: http://www.nabble.com/Invalid-BundleContext-tp19108424p20305353.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org