Re: [equinox-dev] Caused by: org.osgi.framework.BundleException: State change in progress for bundle...by thread "OSGi Console"
Hi Lukasz's solution assumes that the bundle you are installing will eventually enter the RESOLVED state. This is not going to happen automatically. You would have to run a PackageAdmin.resolveBundles to make the bundle resolve. The actual exception seems to be occurring because the second bundle you are installing and starting is trying to start the original bundle again. Since this is all happening on the same thread the Framework does not allow the second lifecycle operation proceed because the thread is already in the process of starting the first bundle. Tom From: Lukasz Bobowiec <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Cc: equinox-dev@eclipse.org Date: 04/04/2008 05:41 AM Subject:Re: [equinox-dev] Caused by: org.osgi.framework.BundleException: State change in progress for bundle...by thread "OSGi Console" Hi Jacek, I think this is some threading issue. First of all remember that in the start/stop methods of BundleActivator you shouldn't spawn a long running task (just use a new Thread to do this). In the javadoc to org.osgi.framework.BundleActivator#start() method is written: Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start this bundle. This method can be used to register services or to allocate any resources that this bundle needs. This method must complete and return to its caller in a timely manner. Otherwise you can block the OSGi console thread. I suspect that installing and resolving the Spring bundle may consume some amount of time and it should be in the "start" method. Moreover nesting a start of another bundle in your bundle is not the best idea. I am wondering if you are using OSGi console and you are able to install and start your bundle why you don't install and start the spring bundle? Anyway I think that BundleListener resolves your issue: package pl.jaceklaskowski.osgi; import java.util.logging.Level; import java.util.logging.Logger; import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; import org.osgi.framework.BundleListener; public class AktywatorPakunku implements BundleActivator, BundleListener { Logger log = Logger.getLogger(AktywatorPakunku.class.getName()); private Bundle bundle; public void start(BundleContext bundleContext) throws Exception { // add bundle listener bundleContext.addBundleListener(this); bundle = bundleContext.installBundle( " file:c:/projs/osgi/spring-osgi-activationpolicy/target/spring-osgi-activationpolicy-1.0.jar "); long bundleId = bundle.getBundleId(); String bundleLocation = bundle.getLocation(); String bundleSymbolicName = bundle.getSymbolicName(); System.out.println(""); System.out.println("Charakterystyka zainstalowanego pakunku:"); System.out.println(" Identyfikator: " + bundleId); System.out.println(" Identyfikator położenia: " + bundleLocation); System.out.println(" Nazwa symboliczna: " + bundleSymbolicName); System.out.println(""); } public void stop(BundleContext bundleContext) throws Exception { // remove bundle listener bundleContext.removeBundleListener(this); log.info("stop() wykonano - czyszczę po sobie"); } public void bundleChanged(BundleEvent even
Re: [equinox-dev] Caused by: org.osgi.framework.BundleException: State change in progress for bundle...by thread "OSGi Console"
Hi Jacek, I think this is some threading issue. First of all remember that in the start/stop methods of BundleActivator you shouldn't spawn a long running task (just use a new Thread to do this). In the javadoc to org.osgi.framework.BundleActivator#start() method is written: Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start this bundle. This method can be used to register services or to allocate any resources that this bundle needs. This method must complete and return to its caller in a timely manner. Otherwise you can block the OSGi console thread. I suspect that installing and resolving the Spring bundle may consume some amount of time and it should be in the "start" method. Moreover nesting a start of another bundle in your bundle is not the best idea. I am wondering if you are using OSGi console and you are able to install and start your bundle why you don't install and start the spring bundle? Anyway I think that BundleListener resolves your issue: package pl.jaceklaskowski.osgi; import java.util.logging.Level; import java.util.logging.Logger; import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; import org.osgi.framework.BundleListener; public class AktywatorPakunku implements BundleActivator, BundleListener { Logger log = Logger.getLogger(AktywatorPakunku.class.getName()); private Bundle bundle; public void start(BundleContext bundleContext) throws Exception { // add bundle listener bundleContext.addBundleListener(this); bundle = bundleContext.installBundle( "file:c:/projs/osgi/spring-osgi-activationpolicy/target/spring-osgi-activationpolicy-1.0.jar" ); long bundleId = bundle.getBundleId(); String bundleLocation = bundle.getLocation(); String bundleSymbolicName = bundle.getSymbolicName(); System.out.println(""); System.out.println("Charakterystyka zainstalowanego pakunku:"); System.out.println(" Identyfikator: " + bundleId); System.out.println(" Identyfikator położenia: " + bundleLocation); System.out.println(" Nazwa symboliczna: " + bundleSymbolicName); System.out.println(""); } public void stop(BundleContext bundleContext) throws Exception { // remove bundle listener bundleContext.removeBundleListener(this); log.info("stop() wykonano - czyszczę po sobie"); } public void bundleChanged(BundleEvent event) { if (event.getType() == Bundle.RESOLVED && event.getBundle() == bundle) { try { System.out.println("Startuję pakunek " + bundle.getSymbolicName()); bundle.start(); } catch (BundleException e) { log.log(Level.SEVERE, e.getMessage()); } } } } --- Best regards, Lukasz Bobowiec Software Engineer, Common Agent Services [EMAIL PROTECTED] (+48 12) 628 9882 IBM SWG Lab, Cracow, Poland IBM Polska Sp. z o.o. oddział w Krakowie ul. Armii Krajowej 18 30 -150 Kraków NIP: 526-030-07-24 Sąd Rejonowy dla m.st. Warszawy, XIII Wydział Gospodarczy KRS KRS 012941, Kapitał zakładowy: 3.073.600 PLN "Jacek Laskowski" <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 2008-04-04 08:55 Please respond to [EMAIL PROTECTED]; Please respond to Equinox development mailing list To equinox-dev@eclipse.org cc Subject [equinox-dev] Caused by: org.osgi.framework.BundleException: State change in progress for bundle...by thread "OSGi Console" Hi, Why do I face the following exception: [EMAIL PROTECTED] /cygdrive/c/projs/osgi/spring-osgi-install $ java -jar c:/apps/eclipse/plugins/org.eclipse.osgi_3.4.0.v20080205.jar -console osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.4.0.v20080205 osgi> install file:c:/projs/osgi/spring-osgi-install/target/spring-osgi-install-1.0.jar Bundle id is 1 osgi> start 1 2008-04-03 22:26:06 pl.jaceklaskowski.osgi.AktywatorPakunku start Charakterystyka zainstalowanego pakunku: Identyfikator: 2 Identyfikator położenia: file:c:/projs/osgi/spring-osgi-activationpolicy/target/spring-osgi-activationpolicy-1.0.jar Nazwa symboliczna: pl.jaceklaskowski.osgi.spring-osgi-activationpolicy Startuj?Ö pakunek pl.jaceklaskowski.osgi.spring-osgi-activationpolicy 2008-04-03 22:26:07 pl.jaceklaskowski.osgi.AktywatorPakunku start
[equinox-dev] Caused by: org.osgi.framework.BundleException: State change in progress for bundle...by thread "OSGi Console"
Hi, Why do I face the following exception: [EMAIL PROTECTED] /cygdrive/c/projs/osgi/spring-osgi-install $ java -jar c:/apps/eclipse/plugins/org.eclipse.osgi_3.4.0.v20080205.jar -console osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.4.0.v20080205 osgi> install file:c:/projs/osgi/spring-osgi-install/target/spring-osgi-install-1.0.jar Bundle id is 1 osgi> start 1 2008-04-03 22:26:06 pl.jaceklaskowski.osgi.AktywatorPakunku start Charakterystyka zainstalowanego pakunku: Identyfikator: 2 Identyfikator położenia: file:c:/projs/osgi/spring-osgi-activationpolicy/target/spring-osgi-activationpolicy-1.0.jar Nazwa symboliczna: pl.jaceklaskowski.osgi.spring-osgi-activationpolicy Startuj¦Ö pakunek pl.jaceklaskowski.osgi.spring-osgi-activationpolicy 2008-04-03 22:26:07 pl.jaceklaskowski.osgi.AktywatorPakunku start Charakterystyka zainstalowanego pakunku: Identyfikator: 2 Identyfikator położenia: file:c:/projs/osgi/spring-osgi-activationpolicy/target/spring-osgi-activationpolicy-1.0.jar Nazwa symboliczna: pl.jaceklaskowski.osgi.spring-osgi-activationpolicy Startuję pakunek pl.jaceklaskowski.osgi.spring-osgi-activationpolicy org.osgi.framework.BundleException: Exception in pl.jaceklaskowski.osgi.AktywatorPakunku.start() of bundle pl.jaceklaskowski.osgi.spring-osgi-install. at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1018) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:257) at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:257) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:298) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:283) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:219) at java.lang.Thread.run(Thread.java:595) Caused by: org.osgi.framework.BundleException: Exception in pl.jaceklaskowski.osgi.AktywatorPakunku.start() of bundle pl.jaceklaskowski.osgi.spring-osgi-activationpolicy. at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1018) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:257) at pl.jaceklaskowski.osgi.AktywatorPakunku.start(AktywatorPakunku.java:26) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993) ... 14 more Caused by: org.osgi.framework.BundleException: State change in progress for bundle "file:c:/projs/osgi/spring-osgi-activationpolicy/target/spring-osgi-activationpolicy-1.0.jar" by thread "OSGi Console". at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1143) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:263) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:257) at pl.jaceklaskowski.osgi.AktywatorPakunku.start(AktywatorPakunku.java:26) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993) ... 22 more C