[jboss-cvs] JBossAS SVN: r97895 - projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 16 09:00:27 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-16 09:00:27 -0500 (Wed, 16 Dec 2009)
New Revision: 97895

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
Log:
Move bundle.stop() preconditions to BundleManager.stopBundle()
Add javadoc that descibes how bundle.stop() works

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-16 13:52:10 UTC (rev 97894)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-16 14:00:27 UTC (rev 97895)
@@ -74,6 +74,7 @@
 import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.deployment.deployer.DeploymentFactory;
+import org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.metadata.PackageAttribute;
 import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
@@ -1171,6 +1172,9 @@
     * Stating a bundle is done in an attempt to move the bundle's DeploymentUnit to state INSTALLED.
     * A failure to resolve the bundle is fatal, the bundle should remain in state INSTALLED.
     * A failure in BundleActivator.start() is a normal condition not handled by the deployment layer.
+    * 
+    * @see OSGiBundleActivatorDeployer
+    * @see OSGiBundleState#startInternal()
     */
    public void startBundle(OSGiBundleState bundleState) throws BundleException
    {
@@ -1238,22 +1242,41 @@
    /**
     * Stop a bundle
     * 
-    * @param bundleState the bundle state
-    * @throws BundleException the bundle exception
+    * Stopping a bundle is done in an attempt to move the bundle's DeploymentUnit to state CLASSLOADER.
+    * 
+    * @see OSGiBundleActivatorDeployer
+    * @see OSGiBundleState#stopInternal()
     */
    public void stopBundle(OSGiBundleState bundleState) throws BundleException
    {
+      // If this bundle's state is UNINSTALLED then an IllegalStateException is thrown. 
+      if (bundleState.getState() == Bundle.UNINSTALLED)
+         throw new IllegalStateException("Bundle already uninstalled: " + this);
+
+      // [TODO] If this bundle is in the process of being activated or deactivated then this method must wait for activation or deactivation 
+      // to complete before continuing. If this does not occur in a reasonable time, a BundleException is thrown to indicate this bundle 
+      // was unable to be stopped.
+      
+      // [TODO] If the STOP_TRANSIENT option is not set then then set this bundle's persistent autostart setting to to Stopped. 
+      // When the Framework is restarted and this bundle's autostart setting is Stopped, this bundle must not be automatically started. 
+
+      // If this bundle's state is not STARTING or ACTIVE then this method returns immediately
+      if (bundleState.getState() != Bundle.STARTING && bundleState.getState() != Bundle.ACTIVE)
+         return;
+
       try
       {
-         String name = bundleState.getDeploymentUnit().getName();
-         deployerClient.change(name, DeploymentStages.CLASSLOADER);
+         DeploymentUnit unit = bundleState.getDeploymentUnit();
+         deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
+         deployerClient.checkComplete(unit.getName());
       }
-      catch (DeploymentException e)
+      catch (DeploymentException ex)
       {
-         Throwable t = e.getCause();
-         if (t instanceof BundleException)
-            throw (BundleException)t;
-         throw new BundleException("Error stopping " + bundleState, e);
+         Throwable cause = ex.getCause();
+         if (cause instanceof BundleException)
+            throw (BundleException)cause;
+         
+         throw new BundleException("Error stopping " + bundleState, (cause != null ? cause : ex));
       }
    }
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-16 13:52:10 UTC (rev 97894)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-16 14:00:27 UTC (rev 97895)
@@ -255,15 +255,11 @@
       getBundleManager().startBundle(this);
    }
 
-   // [TODO] options
    public void stop(int options) throws BundleException
    {
       checkInstalled();
       checkAdminPermission(AdminPermission.EXECUTE);
 
-      if (getState() != ACTIVE)
-         return;
-
       getBundleManager().stopBundle(this);
    }
 
@@ -341,25 +337,13 @@
    }
 
    /**
-    * Stop Internal
+    * Stop Internal.
+    * 
+    * This method is triggered by the OSGiBundleActivatorDeployer.
+    * Preconditions are handled in OSGiBundleManager.stopBundle()
     */
    public void stopInternal() throws BundleException
    {
-      // If this bundle's state is UNINSTALLED then an IllegalStateException is thrown. 
-      if (getState() == Bundle.UNINSTALLED)
-         throw new IllegalStateException("Bundle already uninstalled: " + this);
-
-      // [TODO] If this bundle is in the process of being activated or deactivated then this method must wait for activation or deactivation 
-      // to complete before continuing. If this does not occur in a reasonable time, a BundleException is thrown to indicate this bundle 
-      // was unable to be stopped.
-      
-      // [TODO] If the STOP_TRANSIENT option is not set then then set this bundle's persistent autostart setting to to Stopped. 
-      // When the Framework is restarted and this bundle's autostart setting is Stopped, this bundle must not be automatically started. 
-
-      // If this bundle's state is not STARTING or ACTIVE then this method returns immediately
-      if (getState() != Bundle.STARTING && getState() != Bundle.ACTIVE)
-         return;
-
       // This bundle's state is set to STOPPING
       // A bundle event of type BundleEvent.STOPPING is fired
       int priorState = getState();




More information about the jboss-cvs-commits mailing list