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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 4 10:21:15 EST 2009


Author: alesj
Date: 2009-12-04 10:21:15 -0500 (Fri, 04 Dec 2009)
New Revision: 97462

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/OSGiServiceState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/d/D.java
Log:
Fix the order of install/register/uninstall/unregister.

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-04 15:01:02 UTC (rev 97461)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-04 15:21:15 UTC (rev 97462)
@@ -1395,8 +1395,6 @@
    OSGiServiceState registerService(AbstractBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
    {
       OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
-      result.internalRegister();
-
       try
       {
          Controller controller = kernel.getController();
@@ -1405,9 +1403,9 @@
       catch (Throwable t)
       {
          fireError(bundleState, "installing service to MC in", t);
-         result.internalUnregister();
          throw new RuntimeException(t);
       }
+      result.internalRegister();
 
       FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
       plugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
@@ -1422,13 +1420,13 @@
     */
    void unregisterService(OSGiServiceState serviceState)
    {
-      Controller controller = kernel.getController();
-      controller.uninstall(serviceState.getName());
+      serviceState.internalUnregister();
 
       FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
       plugin.fireServiceEvent(serviceState.getBundleState(), ServiceEvent.UNREGISTERING, serviceState);
 
-      serviceState.internalUnregister();
+      Controller controller = kernel.getController();
+      controller.uninstall(serviceState.getName());
    }
 
    /**

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-04 15:01:02 UTC (rev 97461)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-12-04 15:21:15 UTC (rev 97462)
@@ -615,6 +615,10 @@
     */
    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?
       {
@@ -653,7 +657,6 @@
          }
       }
 
-      getBundleState().removeRegisteredService(this);
       serviceOrFactory = null;
    }
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2009-12-04 15:01:02 UTC (rev 97461)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2009-12-04 15:21:15 UTC (rev 97462)
@@ -24,6 +24,7 @@
 import java.lang.reflect.Method;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Set;
 
 import junit.framework.Test;
 
@@ -257,17 +258,19 @@
                ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), d, table);
                assertNotNull(reg1);
 
+               Object a1 = null;
+               Object a2 = null;
                try
                {
                   checkComplete();
 
                   Object c1 = getBean("C1");
-                  Object a1 = invoke(c1, "getA", "C1");
+                  a1 = invoke(c1, "getA", "C1");
                   Object msg1 = invoke(a1, "getMsg", "A1");
                   assertEquals(msg1, getBundle(bean1).getSymbolicName());
 
                   Object c2 = getBean("C2");
-                  Object a2 = invoke(c2, "getA", "C2");
+                  a2 = invoke(c2, "getA", "C2");
                   Object msg2 = invoke(a2, "getMsg", "A2");
                   assertEquals(msg2, getBundle(bean2).getSymbolicName());
                }
@@ -275,6 +278,11 @@
                {
                   reg1.unregister();
                }
+
+               Set as = assertInstanceOf(invoke(d, "getAs", "A"), Set.class);
+               assertNotNull(as);
+               assertTrue(as.contains(a1));
+               assertTrue(as.contains(a2));
             }
             finally
             {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/d/D.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/d/D.java	2009-12-04 15:01:02 UTC (rev 97461)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/service/support/d/D.java	2009-12-04 15:21:15 UTC (rev 97462)
@@ -21,6 +21,9 @@
  */
 package org.jboss.test.osgi.service.support.d;
 
+import java.util.Set;
+import java.util.HashSet;
+
 import org.jboss.test.osgi.service.support.a.A;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
@@ -31,6 +34,8 @@
  */
 public class D implements ServiceFactory
 {
+   private Set<Object> as = new HashSet<Object>();
+
    public Object getService(Bundle bundle, ServiceRegistration registration)
    {
       A a = new A();
@@ -40,5 +45,11 @@
 
    public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
    {
+      as.add(service);
    }
+
+   public Set<Object> getAs()
+   {
+      return as;
+   }
 }




More information about the jboss-cvs-commits mailing list