[jboss-cvs] JBossAS SVN: r97135 - in projects/jboss-osgi/trunk/reactor/framework/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
Sat Nov 28 17:10:52 EST 2009


Author: alesj
Date: 2009-11-28 17:10:52 -0500 (Sat, 28 Nov 2009)
New Revision: 97135

Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
Log:
Simplify tracking a bit.

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-11-28 22:10:52 UTC (rev 97135)
@@ -342,14 +342,16 @@
     * Increment the use count of a context for this bundle
     * 
     * @param context the context
+    * @return target
     */
-   void addContextInUse(ControllerContext context)
+   Object addContextInUse(ControllerContext context)
    {
       if (context instanceof ContextTracking)
       {
          ContextTracking ct = (ContextTracking)context;
-         ct.getTarget(this);
+         return ct.getTarget(this);
       }
+      return context.getTarget();
    }
 
    /**
@@ -370,12 +372,12 @@
 
    public ServiceReference[] getServicesInUse()
    {
-      Set<org.jboss.dependency.spi.ControllerContext> contexts = getUsedContexts(null);
+      Set<ControllerContext> contexts = getUsedContexts(null);
       if (contexts == null || contexts.isEmpty())
          return null;
 
       List<ServiceReference> references = new ArrayList<ServiceReference>();
-      for (org.jboss.dependency.spi.ControllerContext context : contexts)
+      for (ControllerContext context : contexts)
       {
          if (getUsedByCount(context, this) > 0)
          {
@@ -406,11 +408,6 @@
       return getBundleManager().getService(this, reference);
    }
 
-   Object getService(OSGiServiceState serviceState)
-   {
-      return getBundleManager().getService(this, serviceState);
-   }
-
    public ServiceReference getServiceReference(String clazz)
    {
       checkValidBundleContext();

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-11-28 22:10:52 UTC (rev 97135)
@@ -1387,50 +1387,16 @@
     */
    Object getService(AbstractBundleState bundleState, ServiceReference reference)
    {
-      if (reference instanceof OSGiServiceReferenceWrapper)
-      {
-         OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper)reference;
-         OSGiServiceState serviceState = serviceReference.getServiceState();
-         return getService(bundleState, serviceState);
-      }
-      else
-      {
-         ControllerContextHandle handle = (ControllerContextHandle)reference;
-         ControllerContext context = handle.getContext();
-         Object target = context.getTarget();
-         return getResult(bundleState, context, target);
-      }
-   }
+      ControllerContextHandle handle = (ControllerContextHandle)reference;
+      ControllerContext context = handle.getContext();
+      Controller controller = context.getController();
+      if (controller == null || controller.getStates().isBeforeState(context.getState(), ControllerState.INSTALLED))
+         return null; // we're probably not installed anymore  
 
-   /**
-    * Get a service
-    *
-    * @param bundleState the bundle that requests the service
-    * @param serviceState the service state
-    * @return the service
-    */
-   Object getService(AbstractBundleState bundleState, OSGiServiceState serviceState)
-   {
-      Object result = serviceState.getService(bundleState);
-      return getResult(bundleState, serviceState, result);
+      return bundleState.addContextInUse(context);
    }
 
    /**
-    * Get result.
-    *
-    * @param bundleState the bundle state
-    * @param context the context
-    * @param result the result
-    * @return result
-    */
-   private Object getResult(AbstractBundleState bundleState, ControllerContext context, Object result)
-   {
-      if (result != null)
-         bundleState.addContextInUse(context);
-      return result;
-   }
-
-   /**
     * Unget a service
     * 
     * @param bundleState the bundle state

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-11-28 22:10:52 UTC (rev 97135)
@@ -243,6 +243,16 @@
       return getService(bundleState);
    }
 
+   protected Object getTargetForTracker(ContextTracker tracker)
+   {
+      if (tracker instanceof AbstractBundleState)
+      {
+         AbstractBundleState abs = (AbstractBundleState)tracker;
+         return getService(abs);
+      }
+      return getTarget();
+   }
+
    public Object invoke(String name, Object[] parameters, String[] signature) throws Throwable
    {
       return getBeanInfo().invoke(getTarget(), name, signature, parameters);

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java	2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java	2009-11-28 22:10:52 UTC (rev 97135)
@@ -287,7 +287,7 @@
             assertEquals(new ServiceReference[] { reference }, inUse);
 
             assertNull(factory.ungetBundle);
-            assertNull(factory.ungetRegisation);
+            assertNull(factory.ungetRegistration);
             assertNull(factory.ungetService);
             
             bundleContext.addServiceListener(this);
@@ -306,7 +306,7 @@
             inUse = bundle2.getServicesInUse();
             assertNull(inUse);
 
-            assertEquals(registration, factory.ungetRegisation);
+            assertEquals(registration, factory.ungetRegistration);
             assertEquals(bundleContext, factory.ungetService);
          }
          finally

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java	2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java	2009-11-28 22:10:52 UTC (rev 97135)
@@ -39,10 +39,10 @@
    public int getCount;
    
    public Bundle ungetBundle;
-   public ServiceRegistration ungetRegisation;
+   public ServiceRegistration ungetRegistration;
    public Object ungetService;
    public int ungetCount;
-   
+
    public SimpleServiceFactory(Object service)
    {
       this.service = service;
@@ -58,7 +58,7 @@
    public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
    {
       ungetBundle = bundle;
-      ungetRegisation = registration;
+      ungetRegistration = registration;
       ungetService = service;
       ungetCount++;
    }




More information about the jboss-cvs-commits mailing list