[jboss-osgi-commits] JBoss-OSGI SVN: r92673 - in projects/jboss-osgi: projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal and 5 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Fri Aug 21 11:09:37 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-21 11:09:34 -0400 (Fri, 21 Aug 2009)
New Revision: 92673

Modified:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiTestHelper.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/classloading/RuntimeClassLoaderImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleRegistryPluginImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceRegistryPluginImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleEntriesTestCase.java
   projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
JBossMC all examples ok

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiTestHelper.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/OSGiTestHelper.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -47,6 +47,7 @@
 
    // The OSGiBootstrapProvider is a lazy property of the helper
    private OSGiBootstrapProvider bootProvider;
+   private boolean skipCreateBootstrapProvider;
    
    private static String testResourcesDir;
    private static String testArchiveDir;
@@ -59,9 +60,18 @@
 
    public OSGiBootstrapProvider getBootstrapProvider()
    {
-      if (bootProvider == null)
-         bootProvider = OSGiBootstrap.getBootstrapProvider();
-      
+      if (bootProvider == null && skipCreateBootstrapProvider == false)
+      {
+         try
+         {
+            bootProvider = OSGiBootstrap.getBootstrapProvider();
+         }
+         catch (RuntimeException rte)
+         {
+            skipCreateBootstrapProvider = true;
+            throw rte;
+         }
+      }
       return bootProvider;
    }
    

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -143,16 +143,19 @@
    @Override
    public void shutdown()
    {
-      super.shutdown();
       OSGiBootstrapProvider bootProvider = getTestHelper().getBootstrapProvider();
-      try
+      if (bootProvider != null)
       {
-         bootProvider.getFramework().stop();
+         super.shutdown();
+         try
+         {
+            bootProvider.getFramework().stop();
+         }
+         catch (BundleException ex)
+         {
+            log.error("Cannot stop the framework", ex);
+         }
       }
-      catch (BundleException ex)
-      {
-         log.error("Cannot stop the framework", ex);
-      }
    }
    
    public BundleContext getBundleContext()

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -262,7 +262,7 @@
             if (bundle.getState() != Bundle.UNINSTALLED)
                bundle.uninstall();
          }
-         catch (BundleException ex)
+         catch (Exception ex)
          {
             log.warn("Cannot uninstall bundle: " + bundle, ex);
          }

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -35,6 +35,7 @@
 import javax.naming.NamingException;
 
 import org.jboss.osgi.spi.capability.Capability;
+import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 import org.jboss.osgi.spi.management.MBeanProxy;
 import org.jboss.osgi.spi.management.MBeanProxyException;
 import org.jboss.osgi.spi.management.ManagedBundleMBean;
@@ -203,8 +204,12 @@
    @Override
    public void shutdown()
    {
-      super.shutdown();
-      getPackageAdmin().refreshPackages(null);
+      OSGiBootstrapProvider bootProvider = getTestHelper().getBootstrapProvider();
+      if (bootProvider != null)
+      {
+         super.shutdown();
+         getPackageAdmin().refreshPackages(null);
+      }
    }
 
    private RemoteFramework getRemoteFramework()

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -304,4 +304,10 @@
       }
       usedServices.clear();
    }
+
+   @Override
+   public String toString()
+   {
+      return "BundleContext " + bundle;
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -35,6 +35,7 @@
 import org.jboss.osgi.spi.NotImplementedException;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
@@ -54,7 +55,7 @@
    private Dictionary<String, Object> properties;
    private ServiceRegistration registration;
    private Map<Bundle, Long> bundleUseCount = new HashMap<Bundle, Long>();
-   private Map<Bundle, Object> cachedService = new HashMap<Bundle, Object>();
+   private Map<Bundle, Object> cachedServices = new HashMap<Bundle, Object>();
    private boolean unregistered;
    private String toStringCache;
    
@@ -87,15 +88,15 @@
    
    public Object getCachedService(Bundle bundle)
    {
-      return cachedService.get(bundle);
+      return cachedServices.get(bundle);
    }
 
    public void setCachedService(Bundle bundle, Object service)
    {
       if (service != null)
-         cachedService.put(bundle, service);
+         cachedServices.put(bundle, service);
       else
-         cachedService.remove(bundle);
+         cachedServices.remove(bundle);
    }
 
    public boolean isUnregistered()
@@ -164,6 +165,29 @@
       throw new NotImplementedException();
    }
 
+   public void unregister()
+   {
+      // For each bundle whose use count for this service is greater than zero:
+      // 1. The bundle's use count for this service is set to zero.
+      // 2. If the service was registered with a ServiceFactory object, the ServiceFactory.ungetService method is called to release the service object for the bundle.
+      for (Bundle bundle : bundleUseCount.keySet())
+      {
+         Long count = bundleUseCount.get(bundle);
+         if (count > 0)
+         {
+            if (service instanceof ServiceFactory)
+            {
+               ServiceFactory factory = (ServiceFactory)service;
+               Object cachedService = cachedServices.remove(bundle);
+               factory.ungetService(bundle, registration, cachedService);
+            }
+         }
+      }
+      
+      bundleUseCount = null;
+      cachedServices = null;
+   }
+   
    @Override
    public String toString()
    {

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/classloading/RuntimeClassLoaderImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/classloading/RuntimeClassLoaderImpl.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/classloading/RuntimeClassLoaderImpl.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -165,11 +165,11 @@
          Class<?> clazz;
          try
          {
-            clazz = parent.loadClass(name);
+            clazz = super.loadClass(name);
          }
          catch (ClassNotFoundException ex)
          {
-            clazz = super.loadClass(name);
+            clazz = parent.loadClass(name);
          }
 
          return clazz;

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleRegistryPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleRegistryPluginImpl.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleRegistryPluginImpl.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -68,7 +68,8 @@
       
       registry.put(bundle.getLocation(), bundle);
       
-      return bundle.getBundleId();
+      long bundleId = bundle.getBundleId();
+      return bundleId;
    }
 
    public void unregisterBundle(Bundle bundle)

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceRegistryPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceRegistryPluginImpl.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceRegistryPluginImpl.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -85,6 +85,7 @@
 
    public void unregisterService(ServiceRegistration registration)
    {
+      // 1. The service is removed from the Framework service registry so that it can no longer be obtained.
       ServiceReference sref = registration.getReference();
       String[] clazzes = (String[])sref.getProperty(Constants.OBJECTCLASS);
       for (String clazz : clazzes)
@@ -101,6 +102,16 @@
             }
          }
       }
+      
+      // 2. A service event of type ServiceEvent.UNREGISTERING is fired so that bundles using this service can release their use of the service.
+      ServiceEventsPlugin serviceEvents = getPlugin(ServiceEventsPlugin.class);
+      serviceEvents.fireServiceEvent(new ServiceEvent(ServiceEvent.UNREGISTERING, sref));
+      
+      // 3. For each bundle whose use count for this service is greater than zero: 
+      //    The bundle's use count for this service is set to zero.
+      //    If the service was registered with a ServiceFactory object, the ServiceFactory.ungetService method is called to release the service object for the bundle.
+      ServiceReferenceImpl srefImpl = (ServiceReferenceImpl)sref;
+      srefImpl.unregister();
    }
 
    public ServiceReference getServiceReference(String clazz)

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleEntriesTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleEntriesTestCase.java	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/test/java/org/jboss/test/osgi/jbossmc/simple/BundleEntriesTestCase.java	2009-08-21 15:09:34 UTC (rev 92673)
@@ -29,7 +29,7 @@
 import java.net.URL;
 import java.util.Enumeration;
 
-import org.jboss.osgi.spi.testing.OSGiTest;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
 import org.jboss.osgi.spi.util.ServiceLoader;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -46,9 +46,10 @@
  * @author thomas.diesler at jboss.com
  * @since 18-Aug-2009
  */
-public class BundleEntriesTestCase extends OSGiTest
+public class BundleEntriesTestCase 
 {
    private static Framework framework;
+   private static Bundle bundle;
    
    /*
     * /META-INF/
@@ -70,6 +71,10 @@
       FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
       framework = factory.newFramework(null);
       framework.start();
+      
+      BundleContext sysContext = framework.getBundleContext();
+      URL bundleURL = new OSGiTestHelper().getTestArchiveURL("simple-bundle.jar");
+      bundle = sysContext.installBundle(bundleURL.toExternalForm());
    }
    
    @AfterClass
@@ -81,10 +86,6 @@
    @Test
    public void testGetEntryPaths() throws Exception
    {
-      BundleContext sysContext = framework.getBundleContext();
-      String location = getTestArchiveURL("simple-bundle.jar").toString();
-      Bundle bundle = sysContext.installBundle(location);
-
       String path = "/";
       assertEquals(11, countEntryPaths(bundle.getEntryPaths(path)));
 
@@ -94,23 +95,19 @@
       path = "org/jboss/test/osgi/jbossmc/simple/bundle";
       assertEquals(2, countEntryPaths(bundle.getEntryPaths(path)));
       
-      bundle.uninstall();
+      //bundle.uninstall();
    }
 
    @SuppressWarnings("unchecked")
    @Test
    public void testFindEntries() throws Exception
    {
-      BundleContext sysContext = framework.getBundleContext();
-      String location = getTestArchiveURL("simple-bundle.jar").toString();
-      Bundle bundle = sysContext.installBundle(location);
-
       Enumeration entries = bundle.findEntries("META-INF", "M*.*", false);
       assertTrue("One entry", entries.hasMoreElements());
       URL entryURL = (URL)entries.nextElement();
       assertTrue("Ends with MANIFEST.MF", entryURL.toExternalForm().endsWith("simple-bundle.jar/META-INF/MANIFEST.MF"));
       
-      bundle.uninstall();
+      //bundle.uninstall();
    }
 
    @SuppressWarnings("unchecked")

Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml	2009-08-21 14:35:19 UTC (rev 92672)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml	2009-08-21 15:09:34 UTC (rev 92673)
@@ -195,7 +195,7 @@
       </dependencies>
       -->
       
-      <!-- default to felix --> 
+      <!-- default to felix -->  
       <dependencies>
         <dependency>
           <groupId>org.jboss.osgi</groupId>
@@ -204,6 +204,7 @@
           <scope>provided</scope>
         </dependency>
       </dependencies>
+      
     </profile>
 
     <!--
@@ -272,7 +273,7 @@
 
     <!--
       Name: framework-jbossmc
-      Descr: Setup for Knopflerfish framework integration testing
+      Descr: Setup for JBossMC framework integration testing
     -->
     <profile>
       <id>framework-jbossmc</id>



More information about the jboss-osgi-commits mailing list