org.eclipse.osgi.framework.internal.core
Class StartLevelManager

java.lang.Object
  extended by org.eclipse.osgi.framework.internal.core.StartLevelManager
All Implemented Interfaces:
java.util.EventListener, EventDispatcher, ServiceFactory

public class StartLevelManager
extends java.lang.Object
implements EventDispatcher, java.util.EventListener, ServiceFactory

StartLevel service implementation for the OSGi specification. Framework service which allows management of framework and bundle startlevels. This class also acts as the StartLevel service factory class, providing StartLevel objects to those requesting org.osgi.service.startlevel.StartLevel service. If present, there will only be a single instance of this service registered in the framework.


Field Summary
protected static EventManager eventManager
           
protected static Framework framework
           
protected  int frameworkBeginningStartLevel
          The framework beginning startlevel.
protected  int initialBundleStartLevel
          The initial bundle start level for newly installed bundles
protected static EventListeners startLevelListeners
           
 
Constructor Summary
protected StartLevelManager(Framework framework)
          This constructor is called by the Framework
 
Method Summary
protected  void cleanup()
           
protected  void decFWSL(int decToSL, AbstractBundle[] shutdown)
          Decrement the active startlevel by one
 void dispatchEvent(java.lang.Object listener, java.lang.Object listenerObject, int eventAction, java.lang.Object eventObject)
          This method is the call back that is called once for each listener.
 int getBundleStartLevel(Bundle bundle)
          Return the assigned start level value for the specified Bundle.
 int getFrameworkStartLevel()
          Return the initial start level used when the framework is started.
 int getInitialBundleStartLevel()
          Return the initial start level value that is assigned to a Bundle when it is first installed.
 java.lang.Object getService(Bundle owner, ServiceRegistration registration)
          Returns a StartLevel object, created for each requesting bundle.
 int getStartLevel()
          Return the active start level value of the Framework.
protected  void incFWSL(int incToSL, AbstractBundle callerBundle)
          Increment the active startlevel by one
protected  void initialize()
           
 boolean isBundleActivationPolicyUsed(Bundle bundle)
           
 boolean isBundlePersistentlyStarted(Bundle bundle)
          Return the persistent state of the specified bundle.
 boolean isSettingStartLevel()
           
protected  void launch(int startlevel)
          Internal method to allow the framework to be launched synchronously by calling the StartLevelListener worker calls directly This method does not return until all bundles that should be started are started
protected  void saveActiveStartLevel(int newSL)
          This method is used within the package to save the actual active startlevel value for the framework.
protected  void setBundleSL(org.eclipse.osgi.framework.internal.core.StartLevelEvent startLevelEvent)
          Set the bundle's startlevel to the new value This may cause the bundle to start or stop based on the active framework startlevel
 void setBundleStartLevel(Bundle bundle, int newSL)
          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.
protected  void setStartLevel(int newSL)
           
 void setStartLevel(int newSL, Bundle callerBundle)
          Modify the active start level of the Framework.
protected  void shutdown()
          Internal method to shut down the framework synchronously by setting the startlevel to zero and calling the StartLevelListener worker calls directly This method does not return until all bundles are stopped and the framework is shut down.
 void ungetService(Bundle owner, ServiceRegistration registration, java.lang.Object service)
          Does nothing, as the StartLevel bundle does not keep references to StartLevel objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

framework

protected static Framework framework

eventManager

protected static EventManager eventManager

startLevelListeners

protected static EventListeners startLevelListeners

frameworkBeginningStartLevel

protected int frameworkBeginningStartLevel
The framework beginning startlevel. Default is 1


initialBundleStartLevel

protected int initialBundleStartLevel
The initial bundle start level for newly installed bundles

Constructor Detail

StartLevelManager

protected StartLevelManager(Framework framework)
This constructor is called by the Framework

Method Detail

initialize

protected void initialize()

cleanup

protected void cleanup()

getInitialBundleStartLevel

public 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)

getFrameworkStartLevel

public int getFrameworkStartLevel()
Return the initial start level used when the framework is started.

Returns:
The framework start level.

setInitialBundleStartLevel

public 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.

This 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.

getStartLevel

public 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

public void setStartLevel(int newSL,
                          Bundle callerBundle)
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:
newSL - 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.

setStartLevel

protected void setStartLevel(int newSL)

launch

protected void launch(int startlevel)
Internal method to allow the framework to be launched synchronously by calling the StartLevelListener worker calls directly This method does not return until all bundles that should be started are started


shutdown

protected void shutdown()
Internal method to shut down the framework synchronously by setting the startlevel to zero and calling the StartLevelListener worker calls directly This method does not return until all bundles are stopped and the framework is shut down.


saveActiveStartLevel

protected void saveActiveStartLevel(int newSL)
This method is used within the package to save the actual active startlevel value for the framework. Externally the setStartLevel method must be used.

Parameters:
newSL - - the new startlevel to save

isBundlePersistentlyStarted

public 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.

isBundleActivationPolicyUsed

public boolean isBundleActivationPolicyUsed(Bundle bundle)

getBundleStartLevel

public 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

public void setBundleStartLevel(Bundle bundle,
                                int newSL)
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.
newSL - 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.

dispatchEvent

public void dispatchEvent(java.lang.Object listener,
                          java.lang.Object listenerObject,
                          int eventAction,
                          java.lang.Object eventObject)
This method is the call back that is called once for each listener. This method must cast the EventListener object to the appropriate listener class for the event type and call the appropriate listener method.

Specified by:
dispatchEvent in interface EventDispatcher
Parameters:
listener - This listener must be cast to the appropriate listener class for the events created by this source and the appropriate listener method must then be called.
listenerObject - This is the optional object that was passed to EventListeners.addListener when the listener was added to the EventListeners.
eventAction - This value was passed to the ListenerQueue object via one of its dispatchEvent* method calls. It can provide information (such as which listener method to call) so that this method can complete the delivery of the event to the listener.
eventObject - This object was passed to the ListenerQueue object via one of its dispatchEvent* method calls. This object was created by the event source and is passed to this method. It should contain all the necessary information (such as what event object to pass) so that this method can complete the delivery of the event to the listener.

incFWSL

protected void incFWSL(int incToSL,
                       AbstractBundle callerBundle)
Increment the active startlevel by one


decFWSL

protected void decFWSL(int decToSL,
                       AbstractBundle[] shutdown)
Decrement the active startlevel by one

Parameters:
decToSL - - the startlevel value to set the framework to

setBundleSL

protected void setBundleSL(org.eclipse.osgi.framework.internal.core.StartLevelEvent startLevelEvent)
Set the bundle's startlevel to the new value This may cause the bundle to start or stop based on the active framework startlevel

Parameters:
startLevelEvent - - the event requesting change in bundle startlevel

getService

public java.lang.Object getService(Bundle owner,
                                   ServiceRegistration registration)
Returns a StartLevel object, created for each requesting bundle.

Specified by:
getService in interface ServiceFactory
Parameters:
owner - bundle, requested to get StartLevel service.
registration - ServiceRegistration of the StartLevel service
Returns:
StartLevel object
See Also:
BundleContext.getService(org.osgi.framework.ServiceReference)

ungetService

public void ungetService(Bundle owner,
                         ServiceRegistration registration,
                         java.lang.Object service)
Does nothing, as the StartLevel bundle does not keep references to StartLevel objects.

Specified by:
ungetService in interface ServiceFactory
Parameters:
owner - bundle requesting to unget StartLevel service.
registration - ServiceRegistration of StartLevel
service - Service object, already been got by this bundle.
See Also:
BundleContext.ungetService(org.osgi.framework.ServiceReference)

isSettingStartLevel

public boolean isSettingStartLevel()