[jboss-cvs] JBossAS SVN: r97502 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: test/java/org/jboss/test/osgi/service and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 7 07:58:57 EST 2009


Author: alesj
Date: 2009-12-07 07:58:57 -0500 (Mon, 07 Dec 2009)
New Revision: 97502

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   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/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
Log:
Fix getRegisteredServices bug.

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-07 12:58:17 UTC (rev 97501)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-07 12:58:57 UTC (rev 97502)
@@ -299,30 +299,17 @@
    }
 
    /**
-    * Add a registered service
-    * 
-    * @param context the context
+    * Get registered contexts.
+    *
+    * @return the registered contexts
     */
-   void addRegisteredService(ControllerContext context)
-   {
-      addUsedBy(context, this);
-   }
+   protected abstract Set<ControllerContext> getRegisteredContexts();
 
-   /**
-    * Remove a registered service
-    * 
-    * @param context the context
-    */
-   void removeRegisteredService(ControllerContext context)
-   {
-      removeUsedBy(context, this);
-   }
-
    public ServiceReference[] getRegisteredServices()
    {
       checkInstalled();
 
-      Set<ControllerContext> contexts = getUsedContexts(this);
+      Set<ControllerContext> contexts = getRegisteredContexts();
       if (contexts.isEmpty())
          return null;
 

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-07 12:58:17 UTC (rev 97501)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-07 12:58:57 UTC (rev 97502)
@@ -1414,6 +1414,18 @@
    }
 
    /**
+    * Get registered contexts for bundle.
+    *
+    * @param bundleState the owning bundle
+    * @return registered contexts
+    */
+   Set<ControllerContext> getRegisteredContext(OSGiBundleState bundleState)
+   {
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      return registry.getContexts(unit);
+   }
+
+   /**
     * Unregister a service
     * 
     * @param serviceState the service state

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-07 12:58:17 UTC (rev 97501)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-07 12:58:57 UTC (rev 97502)
@@ -25,6 +25,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.jboss.dependency.spi.ControllerContext;
@@ -85,6 +86,11 @@
       unit.getMutableMetaData().addMetaData(unit, DeploymentUnit.class);
    }
 
+   protected Set<ControllerContext> getRegisteredContexts()
+   {
+      return getBundleManager().getRegisteredContext(this);
+   }
+
    public long getBundleId()
    {
       return bundleId;

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-12-07 12:58:17 UTC (rev 97501)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-12-07 12:58:57 UTC (rev 97502)
@@ -656,7 +656,6 @@
    void internalRegister()
    {
       checkPermission("register", true);
-      getBundleState().addRegisteredService(this);
    }
 
    /**
@@ -664,10 +663,6 @@
     */
    void internalUnregister()
    {
-      // let's remove us from our bundle first
-      // so, we're not "mistaken" for a real user
-      getBundleState().removeRegisteredService(this);
-
       ContextTracker ct = getContextTracker();
       if (ct != null) // nobody used us?
       {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-12-07 12:58:17 UTC (rev 97501)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-12-07 12:58:57 UTC (rev 97502)
@@ -25,9 +25,12 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
+import java.util.Set;
 
+import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.spi.NotImplementedException;
+import org.jboss.util.collection.ConcurrentSet;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 
@@ -41,6 +44,9 @@
  */
 public class OSGiSystemState extends AbstractBundleState
 {
+   /** The registred contexts */
+   private Set<ControllerContext> registered = new ConcurrentSet<ControllerContext>();
+
    /**
     * Create a new OSGiSystemBundle.
     * @param osgiMetaData the metadata for the system bundle
@@ -50,6 +56,23 @@
       super(osgiMetaData);
    }
 
+   protected Set<ControllerContext> getRegisteredContexts()
+   {
+      return registered;
+   }
+
+   @Override
+   protected void afterServiceRegistration(OSGiServiceState service)
+   {
+      registered.add(service);
+   }
+
+   @Override
+   protected void beforeServiceUnregistration(OSGiServiceState service)
+   {
+      registered.remove(service);
+   }
+
    public long getBundleId()
    {
       return 0;

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java	2009-12-07 12:58:17 UTC (rev 97501)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java	2009-12-07 12:58:57 UTC (rev 97502)
@@ -283,4 +283,48 @@
          uninstall(bundle1);
       }
    }
+
+   public void testRegisteredServices() throws Exception
+   {
+      Bundle bundle1 = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle1.start();
+         BundleContext bundleContext = bundle1.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+         ServiceReference reference = registration.getReference();
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+
+         Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+
+            actual = bundleContext2.getService(reference);
+            assertEquals(bundleContext, actual);
+
+            ServiceReference[] registered = bundle2.getRegisteredServices();
+            assertNull(registered);
+
+            registered = bundle1.getRegisteredServices();
+            assertEquals(new ServiceReference[]{reference}, registered);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+
+         actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
 }




More information about the jboss-cvs-commits mailing list