OSGi - Life-cycle

Life-cycle

A Life Cycle layer adds bundles that can be dynamically installed, started, stopped, updated and uninstalled. Bundles rely on the module layer for class loading but add an API to manage the modules in run time. The life cycle layer introduces dynamics that are normally not part of an application. Extensive dependency mechanisms are used to assure the correct operation of the environment. Life cycle operations are fully protected with the security architecture.

Bundle State Description
INSTALLED The bundle has been successfully installed.
RESOLVED All Java classes that the bundle needs are available. This state indicates that the bundle is either ready to be started or has stopped.
STARTING The bundle is being started, the BundleActivator.start method will be called, and this method has not yet returned. When the bundle has an activation policy, the bundle will remain in the STARTING state until the bundle is activated according to its activation policy.
ACTIVE The bundle has been successfully activated and is running; its Bundle Activator start method has been called and returned.
STOPPING The bundle is being stopped. The BundleActivator.stop method has been called but the stop method has not yet returned.
UNINSTALLED The bundle has been uninstalled. It cannot move into another state.

Below is an example of a typical Java class implementing the BundleActivator interface:

package org.wikipedia; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { private BundleContext context; public void start(BundleContext context) throws Exception { System.out.println("Starting: Hello World"); this.context = context; } public void stop(BundleContext context) throws Exception { System.out.println("Stopping: Goodbye Cruel World"); this.context = null; } }

Read more about this topic:  OSGi