org.osgi.service.startlevel
Interface StartLevel


public interface StartLevel

The StartLevel service allows management agents to manage a start level assigned to each bundle and the active start level of the Framework. There is at most one StartLevel service present in the OSGi environment.

A start level is defined to be a state of execution in which the Framework exists. StartLevel values are defined as unsigned integers with 0 (zero) being the state where the Framework is not launched. Progressively higher integral values represent progressively higher start levels. e.g. 2 is a higher start level than 1.

Access to the StartLevel service is protected by corresponding ServicePermission. In addition the AdminPermission that is required to actually modify start level information.

Start Level support in the Framework includes the ability to control the beginning start level of the Framework, to modify the active start level of the Framework and to assign a specific start level to a bundle. How the beginning start level of a Framework is specified is implementation dependent. It may be a command line argument when invoking the Framework implementation.

When the Framework is first started it must be at start level zero. In this state, no bundles are running. This is the initial state of the Framework before it is launched. When the Framework is launched, the Framework will enter start level one and all bundles which are assigned to start level one and are persistently marked to be started are started as described in the Bundle.start method. Within a start level, bundles are started in ascending order by Bundle.getBundleId. The Framework will continue to increase the start level, starting bundles at each start level, until the Framework has reached a beginning start level. At this point the Framework has completed starting bundles and will then broadcast a Framework event of type FrameworkEvent.STARTED to announce it has completed its launch.

The StartLevel service can be used by management bundles to alter the active start level of the framework.

Version:
$Revision: 1.1 $
Author:
BJ Hargrave, IBM Corporation (hargrave@us.ibm.com)

Method Summary
 int getBundleStartLevel(Bundle bundle)
          Return the assigned start level value for the specified Bundle.
 int getInitialBundleStartLevel()
          Return the initial start level value that is assigned to a Bundle when it is first installed.
 int getStartLevel()
          Return the active start level value of the Framework.
 boolean isBundlePersistentlyStarted(Bundle bundle)
          Return the persistent state of the specified bundle.
 void setBundleStartLevel(Bundle bundle, int startlevel)
          Assign a start level value to the specified Bundle.
 void setInitialBundleStartLevel(int startlevel)
          Set the initial start level value that is assigned to a Bundle when it is first installed.
 void setStartLevel(int startlevel)
          Modify the active start level of the Framework.
 

Method Detail

getStartLevel

int getStartLevel()
Return the active start level value of the Framework. If the Framework is in the process of changing the start level this method must return the active start level if this differs from the requested start level.

Returns:
The active start level value of the Framework.

setStartLevel

void setStartLevel(int startlevel)
Modify the active start level of the Framework.

The Framework will move to the requested start level. This method will return immediately to the caller and the start level change will occur asynchronously on another thread.

If the specified start level is higher than the active start level, the Framework will continue to increase the start level until the Framework has reached the specified start level, starting bundles at each start level which are persistently marked to be started as described in the Bundle.start method. At each intermediate start level value on the way to and including the target start level, the framework must:

  1. Change the active start level to the intermediate start level value.
  2. Start bundles at the intermediate start level in ascending order by Bundle.getBundleId.
When this process completes after the specified start level is reached, the Framework will broadcast a Framework event of type FrameworkEvent.STARTLEVEL_CHANGED to announce it has moved to the specified start level.

If the specified start level is lower than the active start level, the Framework will continue to decrease the start level until the Framework has reached the specified start level stopping bundles at each start level as described in the Bundle.stop method except that their persistently recorded state indicates that they must be restarted in the future. At each intermediate start level value on the way to and including the specified start level, the framework must:

  1. Stop bundles at the intermediate start level in descending order by Bundle.getBundleId.
  2. Change the active start level to the intermediate start level value.
When this process completes after the specified start level is reached, the Framework will broadcast a Framework event of type FrameworkEvent.STARTLEVEL_CHANGED to announce it has moved to the specified start level.

If the specified start level is equal to the active start level, then no bundles are started or stopped, however, the Framework must broadcast a Framework event of type FrameworkEvent.STARTLEVEL_CHANGED to announce it has finished moving to the specified start level. This event may arrive before the this method return.

Parameters:
startlevel - The requested start level for the Framework.
Throws:
java.lang.IllegalArgumentException - If the specified start level is less than or equal to zero.
java.lang.SecurityException - If the caller does not have the AdminPermission and the Java runtime environment supports permissions.

getBundleStartLevel

int getBundleStartLevel(Bundle bundle)
Return the assigned start level value for the specified Bundle.

Parameters:
bundle - The target bundle.
Returns:
The start level value of the specified Bundle.
Throws:
java.lang.IllegalArgumentException - If the specified bundle has been uninstalled.

setBundleStartLevel

void setBundleStartLevel(Bundle bundle,
                         int startlevel)
Assign a start level value to the specified Bundle.

The specified bundle will be assigned the specified start level. The start level value assigned to the bundle will be persistently recorded by the Framework. If the new start level for the bundle is lower than or equal to the active start level of the Framework, the Framework will start the specified bundle as described in the Bundle.start method if the bundle is persistently marked to be started. The actual starting of this bundle must occur asynchronously. If the new start level for the bundle is higher than the active start level of the Framework, the Framework will stop the specified bundle as described in the Bundle.stop method except that the persistently recorded state for the bundle indicates that the bundle must be restarted in the future. The actual stopping of this bundle must occur asynchronously.

Parameters:
bundle - The target bundle.
startlevel - The new start level for the specified Bundle.
Throws:
java.lang.IllegalArgumentException - If the specified bundle has been uninstalled or if the specified start level is less than or equal to zero, or the specified bundle is the system bundle.
java.lang.SecurityException - if the caller does not have the AdminPermission and the Java runtime environment supports permissions.

getInitialBundleStartLevel

int getInitialBundleStartLevel()
Return the initial start level value that is assigned to a Bundle when it is first installed.

Returns:
The initial start level value for Bundles.
See Also:
setInitialBundleStartLevel(int)

setInitialBundleStartLevel

void setInitialBundleStartLevel(int startlevel)
Set the initial start level value that is assigned to a Bundle when it is first installed.

The initial bundle start level will be set to the specified start level. The initial bundle start level value will be persistently recorded by the Framework.

When a Bundle is installed via BundleContext.installBundle, it is assigned the initial bundle start level value.

The default initial bundle start level value is 1 unless this method has been called to assign a different initial bundle start level value.

Thie method does not change the start level values of installed bundles.

Parameters:
startlevel - The initial start level for newly installed bundles.
Throws:
java.lang.IllegalArgumentException - If the specified start level is less than or equal to zero.
java.lang.SecurityException - if the caller does not have the AdminPermission and the Java runtime environment supports permissions.

isBundlePersistentlyStarted

boolean isBundlePersistentlyStarted(Bundle bundle)
Return the persistent state of the specified bundle.

This method returns the persistent state of a bundle. The persistent state of a bundle indicates whether a bundle is persistently marked to be started when it's start level is reached.

Returns:
true if the bundle is persistently marked to be started, false if the bundle is not persistently marked to be started.
Throws:
java.lang.IllegalArgumentException - If the specified bundle has been uninstalled.


Copyright © 2009 IKS, ETH Zurich. All Rights Reserved.