[jboss-cvs] JBossAS SVN: r97894 - in projects/jboss-osgi/projects/runtime/framework/trunk: src/main/java/org/jboss/osgi/framework/bundle and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 16 08:52:11 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-16 08:52:10 -0500 (Wed, 16 Dec 2009)
New Revision: 97894

Added:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleService.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleServiceActivator.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/simple-service/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/simple-service/META-INF/
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/simple-service/META-INF/MANIFEST.MF
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
   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
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/a/FailOnStartActivator.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/fail-on-start/META-INF/MANIFEST.MF
Log:
Resurrect ServiceMix test case.
Move bundle.start() preconditions to BundleManager.startBundle()
Add javadoc that descibes how bundle.start() works

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml	2009-12-16 13:50:03 UTC (rev 97893)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml	2009-12-16 13:52:10 UTC (rev 97894)
@@ -12,10 +12,10 @@
   <!-- $Id$ -->
 
   <!-- 
-     Set these VM properties in your IDE debugger 
-    
-    -Dlog4j.output.dir=${workspace_loc:jboss-osgi-framework/target}
-    -Dorg.jboss.osgi.framework.launch.bootstrapPath=bootstrap/jboss-osgi-bootstrap.xml
+     Set these VM properties in your IDE debugger
+     
+     -Dlog4j.output.dir=${workspace_loc:jboss-osgi-framework/target}
+     -Dlog4j.configuration=log4j-console.xml
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -659,8 +659,9 @@
             </property>
           </systemProperties>
           <excludes>
-            <!-- http://community.jboss.org/thread/145863 -->
+            <!-- excludes listed here need to have a jira issue associated 
             <exclude>org/jboss/test/osgi/service/ServiceMixUnitTestCase.class</exclude>
+            -->
           </excludes>
         </configuration>
       </plugin>

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:50:03 UTC (rev 97893)
+++ 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)
@@ -1166,27 +1166,64 @@
    }
 
    /**
-    * Start a bundle
+    * Start a bundle.
     * 
-    * @param bundleState the bundle state
-    * @throws BundleException the bundle exception
+    * 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.
     */
    public void startBundle(OSGiBundleState bundleState) throws BundleException
    {
-      // Resolve all INSTALLED bundles through the PackageAdmin
-      PackageAdmin packageAdmin = getPlugin(PackageAdminPlugin.class);
-      packageAdmin.resolveBundles(null);
+      // 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 started.
+
+      // If this bundle's state is ACTIVE then this method returns immediately. 
+      if (bundleState.getState() == Bundle.ACTIVE)
+         return;
+
+      // [TODO] If the START_TRANSIENT option is not set then set this bundle's autostart setting to Started with declared activation  
+      // if the START_ACTIVATION_POLICY option is set or Started with eager activation if not set. When the Framework is restarted 
+      // and this bundle's autostart setting is not Stopped, this bundle must be automatically started.
+
+      // If this bundle's state is not RESOLVED, an attempt is made to resolve this bundle. If the Framework cannot resolve this bundle, 
+      // a BundleException is thrown.
+      if (bundleState.getState() != Bundle.RESOLVED)
+      {
+         // Resolve all INSTALLED bundles through the PackageAdmin
+         PackageAdmin packageAdmin = getPlugin(PackageAdminPlugin.class);
+         packageAdmin.resolveBundles(null);
+         
+         if (bundleState.getState() != Bundle.RESOLVED)
+            throw new BundleException("Cannot resolve bundle: " + bundleState);
+      }
+
+      // [TODO] If the START_ACTIVATION_POLICY option is set and this bundle's declared activation policy is lazy then:
+      //    * If this bundle's state is STARTING then this method returns immediately.
+      //    * This bundle's state is set to STARTING.
+      //    * A bundle event of type BundleEvent.LAZY_ACTIVATION is fired.
+      //    * This method returns immediately and the remaining steps will be followed when this bundle's activation is later triggered.
+
       try
       {
          DeploymentUnit unit = bundleState.getDeploymentUnit();
          deployerClient.change(unit.getName(), DeploymentStages.INSTALLED);
          deployerClient.checkComplete(unit.getName());
-         
+
          // The potential BundleException is attached by the OSGiBundleActivatorDeployer
          BundleException startEx = unit.removeAttachment(BundleException.class);
          if (startEx != null)
+         {
+            // Reset the deployment unit to stage classloader
+            deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
+            deployerClient.checkComplete(unit.getName());
+
             throw startEx;
+         }
       }
       catch (DeploymentException 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:50:03 UTC (rev 97893)
+++ 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)
@@ -252,9 +252,6 @@
       checkInstalled();
       checkAdminPermission(AdminPermission.EXECUTE);
 
-      if (getState() == ACTIVE)
-         return;
-
       getBundleManager().startBundle(this);
    }
 
@@ -271,55 +268,13 @@
    }
 
    /**
-    * Start internal
+    * Start internal.
     * 
-    * [TODO] Start Level Service & START_TRANSIENT? 
-    * [TODO] START_ACTIVATION_POLICY 
-    * [TODO] LAZY_ACTIVATION 
-    * [TODO] locks 
-    * [TODO] options
-    * 
-    * @throws Throwable for any error
+    * This method is triggered by the OSGiBundleActivatorDeployer.
+    * Preconditions are handled in OSGiBundleManager.startBundle()
     */
    public void startInternal() 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 started.
-      
-      // If this bundle's state is ACTIVE then this method returns immediately. 
-      if (getState() == Bundle.ACTIVE)
-         return;
-
-      // [TODO] If the START_TRANSIENT option is not set then set this bundle's autostart setting to Started with declared activation  
-      // if the START_ACTIVATION_POLICY option is set or Started with eager activation if not set. When the Framework is restarted 
-      // and this bundle's autostart setting is not Stopped, this bundle must be automatically started.
-      
-      // If this bundle's state is not RESOLVED, an attempt is made to resolve this bundle. If the Framework cannot resolve this bundle, 
-      // a BundleException is thrown.
-      if (getState() != Bundle.RESOLVED)
-      {
-         try
-         {
-            getBundleManager().resolveBundle(this, true);
-         }
-         catch (RuntimeException ex)
-         {
-            throw new BundleException("Cannot resolve bundle: " + this, ex);
-         }
-      }
-      
-      // [TODO] If the START_ACTIVATION_POLICY option is set and this bundle's declared activation policy is lazy then:
-      //    * If this bundle's state is STARTING then this method returns immediately.
-      //    * This bundle's state is set to STARTING.
-      //    * A bundle event of type BundleEvent.LAZY_ACTIVATION is fired.
-      //    * This method returns immediately and the remaining steps will be followed when this bundle's activation is later triggered.
-      
-      
       // This bundle's state is set to STARTING
       // A bundle event of type BundleEvent.STARTING is fired
       createBundleContext();

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java	2009-12-16 13:50:03 UTC (rev 97893)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java	2009-12-16 13:52:10 UTC (rev 97894)
@@ -25,8 +25,11 @@
 
 import org.jboss.test.osgi.FrameworkTest;
 import org.jboss.test.osgi.bundle.support.a.FailOnStartActivator;
+import org.jboss.test.osgi.bundle.support.b.LifecycleService;
+import org.jboss.test.osgi.bundle.support.b.LifecycleServiceActivator;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
 
 /**
  * BundleLifecycleTestCase.
@@ -46,27 +49,141 @@
       super(name);
    }
 
-   public void testExceptionOnStart() throws Exception
+   /**
+    * Verifies that the service bundle can get started
+    */
+   public void testServiceBundle() throws Exception
    {
-      Bundle bundle = assembleBundle("fail-on-start", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+      Bundle bundleA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class, LifecycleServiceActivator.class);
       try
       {
-         assertBundleState(Bundle.INSTALLED, bundle.getState());
+         assertBundleState(Bundle.INSTALLED, bundleA.getState());
+         
+         bundleA.start();
+         assertBundleState(Bundle.ACTIVE, bundleA.getState());
+         
+         ServiceReference sref = bundleA.getBundleContext().getServiceReference(LifecycleService.class.getName());
+         assertNotNull("Service available", sref);
+      }
+      finally
+      {
+         bundleA.uninstall();
+         assertBundleState(Bundle.UNINSTALLED, bundleA.getState());
+      }
+   }
+   
+   /**
+    * Verifies that the bundle state is RESOLVED after a failure in BundleActivator.start()
+    */
+   public void testServiceNotAvailable() throws Exception
+   {
+      Bundle bundleA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class, LifecycleServiceActivator.class);
+      try
+      {
+         assertBundleState(Bundle.INSTALLED, bundleA.getState());
+         
+         // BundleA not started - service not available  
+         ServiceReference sref = getSystemBundle().getBundleContext().getServiceReference(LifecycleService.class.getName());
+         assertNull("Service not available", sref);
 
+         Bundle bundleB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
          try
          {
-            bundle.start();
+            assertBundleState(Bundle.INSTALLED, bundleB.getState());
+            
+            bundleB.start();
             fail("BundleException expected");
          }
          catch (BundleException ex)
          {
-            assertBundleState(Bundle.RESOLVED, bundle.getState());
+            assertBundleState(Bundle.RESOLVED, bundleB.getState());
          }
+         finally
+         {
+            bundleB.uninstall();
+            assertBundleState(Bundle.UNINSTALLED, bundleB.getState());
+         }
       }
       finally
       {
-         //bundle.uninstall();
-         //assertBundleState(Bundle.UNINSTALLED, bundle.getState());
+         bundleA.uninstall();
+         assertBundleState(Bundle.UNINSTALLED, bundleA.getState());
       }
    }
+
+   /**
+    * Verifies that BundleB can get started when the service is available
+    */
+   public void testServiceAvailable() throws Exception
+   {
+      Bundle bundleA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class, LifecycleServiceActivator.class);
+      try
+      {
+         bundleA.start();
+         assertBundleState(Bundle.ACTIVE, bundleA.getState());
+
+         Bundle bundleB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+         try
+         {
+            bundleB.start();
+            assertBundleState(Bundle.ACTIVE, bundleB.getState());
+         }
+         finally
+         {
+            bundleB.uninstall();
+            assertBundleState(Bundle.UNINSTALLED, bundleB.getState());
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+         assertBundleState(Bundle.UNINSTALLED, bundleA.getState());
+      }
+   }
+
+   /**
+    * Verifies that BundleB can get started when the service is made available 
+    */
+   public void testServiceMakeAvailable() throws Exception
+   {
+      Bundle bundleA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class, LifecycleServiceActivator.class);
+      try
+      {
+         assertBundleState(Bundle.INSTALLED, bundleA.getState());
+         
+         Bundle bundleB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+         try
+         {
+            assertBundleState(Bundle.INSTALLED, bundleB.getState());
+            
+            try
+            {
+               bundleB.start();
+               fail("BundleException expected");
+            }
+            catch (BundleException ex)
+            {
+               assertBundleState(Bundle.RESOLVED, bundleB.getState());
+               
+               // Now, make the service available
+               bundleA.start();
+               assertBundleState(Bundle.ACTIVE, bundleA.getState());
+            }
+            
+            // BundleB can now be started
+            bundleB.start();
+            assertBundleState(Bundle.ACTIVE, bundleB.getState());
+         }
+         finally
+         {
+            bundleB.uninstall();
+            assertBundleState(Bundle.UNINSTALLED, bundleB.getState());
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+         assertBundleState(Bundle.UNINSTALLED, bundleA.getState());
+      }
+   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/a/FailOnStartActivator.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/a/FailOnStartActivator.java	2009-12-16 13:50:03 UTC (rev 97893)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/a/FailOnStartActivator.java	2009-12-16 13:52:10 UTC (rev 97894)
@@ -23,6 +23,7 @@
 
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 
 /**
  * A BundleActivator that fails on start.
@@ -35,7 +36,9 @@
 
    public void start(BundleContext context) throws Exception
    {
-      throw new IllegalStateException("fail on start");
+      ServiceReference sref = context.getServiceReference("org.jboss.test.osgi.bundle.support.b.LifecycleService");
+      if (sref == null)
+         throw new IllegalStateException("Cannot obtain: LifecycleService");
    }
 
    public void stop(BundleContext context) throws Exception

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleService.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleService.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleService.java	2009-12-16 13:52:10 UTC (rev 97894)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle.support.b;
+
+
+/**
+ * A marker service.
+ *
+ * @author thomas.Diesler at jboss.com
+ * @since 15-Dec-2009
+ */
+public interface LifecycleService
+{
+}

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleServiceActivator.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/support/b/LifecycleServiceActivator.java	2009-12-16 13:52:10 UTC (rev 97894)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle.support.b;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A BundleActivator that registers the LifecycleService.
+ *
+ * @author thomas.Diesler at jboss.com
+ * @since 15-Dec-2009
+ */
+public class LifecycleServiceActivator implements BundleActivator
+{
+
+   public void start(BundleContext context) throws Exception
+   {
+      context.registerService(LifecycleService.class.getName(), new LifecycleService(){}, null);
+   }
+
+   public void stop(BundleContext context) throws Exception
+   {
+   }
+}

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/fail-on-start/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/fail-on-start/META-INF/MANIFEST.MF	2009-12-16 13:50:03 UTC (rev 97893)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/fail-on-start/META-INF/MANIFEST.MF	2009-12-16 13:52:10 UTC (rev 97894)
@@ -1,4 +1,5 @@
 Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.jboss.test.osgi.failstart
+Bundle-SymbolicName: lifecycle-failstart
+Import-Package: org.jboss.test.osgi.bundle.support.b
 Bundle-Activator: org.jboss.test.osgi.bundle.support.a.FailOnStartActivator
 

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/simple-service/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/simple-service/META-INF/MANIFEST.MF	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bundles/lifecycle/simple-service/META-INF/MANIFEST.MF	2009-12-16 13:52:10 UTC (rev 97894)
@@ -0,0 +1,5 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: lifecycle-service
+Export-Package: org.jboss.test.osgi.bundle.support.b
+Bundle-Activator: org.jboss.test.osgi.bundle.support.b.LifecycleServiceActivator
+




More information about the jboss-cvs-commits mailing list