Difference between revisions of "OSGi Concepts Bundle Life-Cycle"
(Created page with '<h2>[http://confluence.atlassian.com/display/PLUGINFRAMEWORK/Lifecycle+of+a+Bundle Status of an OSGi Bundle]</h2> '''INSTALLED''' - The bundle has been installed into the OSGi c…') |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <h2>[http://confluence.atlassian.com/display/PLUGINFRAMEWORK/Lifecycle+of+a+Bundle | + | {{Ecl_menu}}<h2>[http://confluence.atlassian.com/display/PLUGINFRAMEWORK/Lifecycle+of+a+Bundle Lifecycle of an OSGi Bundle]</h2> |
'''INSTALLED''' - The bundle has been installed into the OSGi container, but some of the bundle's dependencies have not yet been met. The bundle requires packages that have not been exported by any currently installed bundle. | '''INSTALLED''' - The bundle has been installed into the OSGi container, but some of the bundle's dependencies have not yet been met. The bundle requires packages that have not been exported by any currently installed bundle. | ||
Line 5: | Line 5: | ||
'''RESOLVED''' - The bundle is installed, and the OSGi system has connected up all the dependencies at a class level and made sure they are all resolved. The bundle is ready to be started. If a bundle is started and all of the bundle's dependencies are met, the bundle skips this state. | '''RESOLVED''' - The bundle is installed, and the OSGi system has connected up all the dependencies at a class level and made sure they are all resolved. The bundle is ready to be started. If a bundle is started and all of the bundle's dependencies are met, the bundle skips this state. | ||
− | '''STARTING''' - A temporary state that the bundle goes through while the bundle is starting, after all dependencies have been resolved. | + | '''STARTING''' - A temporary state that the bundle goes through while the bundle is starting, after all dependencies have been resolved. the <code>[http://www.osgi.org/javadoc/r4v41/org/osgi/framework/BundleActivator.html#start(org.osgi.framework.BundleContext) BundleActivator.start]</code> method will be called and this method has not yet returned. |
'''ACTIVE''' - The bundle is running. Disabled while Spring is doing its stuff. Spring scans the Spring configuration and builds the context, then hands the context to the plugin. The plugin needs the context in order to create instances of each plugin module. | '''ACTIVE''' - The bundle is running. Disabled while Spring is doing its stuff. Spring scans the Spring configuration and builds the context, then hands the context to the plugin. The plugin needs the context in order to create instances of each plugin module. | ||
− | '''STOPPING''' - A temporary state that the bundle goes through while the bundle is stopping. | + | '''STOPPING''' - A temporary state that the bundle goes through while the bundle is stopping. The <code>[http://www.osgi.org/javadoc/r4v41/org/osgi/framework/BundleActivator.html#stop(org.osgi.framework.BundleContext) BundleActivator.stop]</code> method has been called but the stop method has not yet returned. |
'''UNINSTALLED''' - The bundle has been removed from the OSGi container. | '''UNINSTALLED''' - The bundle has been removed from the OSGi container. | ||
+ | |||
+ | [[Image:bundle-lifecycle.png|thumb100px| ]] [http://static.springsource.org/s2-dmserver/2.0.x/getting-started/htmlsingle/getting-started.html SpringSource® dm Server™] | ||
+ | |||
+ | For instance a typical Java class implementing the <code>[http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html BundleActivator]</code> interface is shown below in the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-serviceprovider/src/cs/ecl/osgi/simple/bookfinderservice/Activator.java Sample Bundle from your course]: | ||
+ | <source lang="java"> | ||
+ | |||
+ | package cs.ecl.osgi.simple.bookfinderservice; | ||
+ | |||
+ | import org.osgi.framework.BundleActivator; | ||
+ | import org.osgi.framework.BundleContext; | ||
+ | |||
+ | import cs.ecl.osgi.simple.bookfinder.BookFinder; | ||
+ | import cs.ecl.osgi.simple.bookfinderservice.internals.BookFinderImplementation; | ||
+ | |||
+ | |||
+ | public class Activator implements BundleActivator { | ||
+ | |||
+ | private static BundleContext context; | ||
+ | |||
+ | static BundleContext getContext() { | ||
+ | return context; | ||
+ | } | ||
+ | |||
+ | public void start(BundleContext bundleContext) throws Exception { | ||
+ | Activator.context = bundleContext; | ||
+ | BookFinder bookService = new BookFinderImplementation(); | ||
+ | |||
+ | context.registerService(BookFinder.class.getName(), bookService, null); | ||
+ | System.out.println(" Bookfinder service registered "); | ||
+ | } | ||
+ | |||
+ | public void stop(BundleContext bundleContext) throws Exception { | ||
+ | Activator.context = null; | ||
+ | System.out.println(" Bookfinder service stopped "); | ||
+ | } | ||
+ | } | ||
+ | </source> |
Latest revision as of 13:41, 21 January 2011
Main Page · Course Description · Course Topics · Schedule, Students, Teams · Course Resources · Course Projects
Lifecycle of an OSGi Bundle
INSTALLED - The bundle has been installed into the OSGi container, but some of the bundle's dependencies have not yet been met. The bundle requires packages that have not been exported by any currently installed bundle.
RESOLVED - The bundle is installed, and the OSGi system has connected up all the dependencies at a class level and made sure they are all resolved. The bundle is ready to be started. If a bundle is started and all of the bundle's dependencies are met, the bundle skips this state.
STARTING - A temporary state that the bundle goes through while the bundle is starting, after all dependencies have been resolved. the BundleActivator.start
method will be called and this method has not yet returned.
ACTIVE - The bundle is running. Disabled while Spring is doing its stuff. Spring scans the Spring configuration and builds the context, then hands the context to the plugin. The plugin needs the context in order to create instances of each plugin module.
STOPPING - A temporary state that the bundle goes through while the bundle is stopping. The BundleActivator.stop
method has been called but the stop method has not yet returned.
UNINSTALLED - The bundle has been removed from the OSGi container.
For instance a typical Java class implementing the BundleActivator
interface is shown below in the Sample Bundle from your course:
package cs.ecl.osgi.simple.bookfinderservice;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import cs.ecl.osgi.simple.bookfinder.BookFinder;
import cs.ecl.osgi.simple.bookfinderservice.internals.BookFinderImplementation;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
BookFinder bookService = new BookFinderImplementation();
context.registerService(BookFinder.class.getName(), bookService, null);
System.out.println(" Bookfinder service registered ");
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
System.out.println(" Bookfinder service stopped ");
}
}