[jboss-cvs] JBossAS SVN: r100796 - in projects/jboss-osgi: projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 10 06:38:19 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-02-10 06:38:18 -0500 (Wed, 10 Feb 2010)
New Revision: 100796

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/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceReferenceWrapper.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ControllerContextPlugin.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
[JBOSGi-278] Revisit ControllerContext handling
Move more of the context bleed into ServiceManagerPlugin

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	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-02-10 11:38:18 UTC (rev 100796)
@@ -525,13 +525,11 @@
       checkValidBundleContext();
       ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
       OSGiServiceState serviceState = (OSGiServiceState)plugin.registerService(this, clazzes, service, properties);
-      afterServiceRegistration(serviceState);
       return serviceState.getRegistration();
    }
 
    void unregisterService(OSGiServiceState serviceState)
    {
-      beforeServiceUnregistration(serviceState);
       ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
       plugin.unregisterService(serviceState);
    }
@@ -543,20 +541,6 @@
       return plugin.ungetService(this, reference);
    }
 
-   /**
-    * After service registration callback.
-    */
-   protected void afterServiceRegistration(OSGiServiceState service)
-   {
-   }
-
-   /**
-    * Before service unregistration callback.
-    */
-   protected void beforeServiceUnregistration(OSGiServiceState service)
-   {
-   }
-
    boolean ungetContext(ControllerContext context)
    {
       return removeContextInUse(context);

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	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-02-10 11:38:18 UTC (rev 100796)
@@ -30,7 +30,6 @@
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
@@ -39,7 +38,7 @@
 import org.jboss.osgi.framework.classloading.OSGiClassLoadingMetaData;
 import org.jboss.osgi.framework.classloading.OSGiClassLoadingMetaData.FragmentHostMetaData;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.plugins.ControllerContextPlugin;
+import org.jboss.osgi.framework.plugins.ServiceManagerPlugin;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
@@ -132,13 +131,6 @@
       return false;
    }
 
-   protected Set<ControllerContext> getRegisteredContexts()
-   {
-      OSGiBundleManager manager = getBundleManager();
-      ControllerContextPlugin plugin = manager.getPlugin(ControllerContextPlugin.class);
-      return plugin.getRegisteredContexts(this);
-   }
-
    public Class<?> loadClass(String name) throws ClassNotFoundException
    {
       checkInstalled();
@@ -314,8 +306,8 @@
       Throwable rethrow = null;
       if (priorState == Bundle.ACTIVE)
       {
-         BundleActivator bundleActivator = getDeploymentUnit().getAttachment(BundleActivator.class);
          BundleContext bundleContext = getBundleContext();
+         BundleActivator bundleActivator = getDeploymentUnit().getAttachment(BundleActivator.class);
          if (bundleActivator != null && bundleContext != null)
          {
             try
@@ -330,9 +322,8 @@
       }
 
       // Any services registered by this bundle must be unregistered
-      OSGiBundleManager manager = getBundleManager();
-      ControllerContextPlugin plugin = manager.getPlugin(ControllerContextPlugin.class);
-      plugin.unregisterContexts(this);
+      ServiceManagerPlugin plugin = getBundleManager().getPlugin(ServiceManagerPlugin.class);
+      plugin.unregisterServices(this);
 
       // Any services used by this bundle must be released
       for (ControllerContext context : getUsedContexts(this))
@@ -407,20 +398,4 @@
 
       return super.getHeaders(locale);
    }
-
-   @Override
-   protected void afterServiceRegistration(OSGiServiceState service)
-   {
-      OSGiBundleManager manager = getBundleManager();
-      ControllerContextPlugin plugin = manager.getPlugin(ControllerContextPlugin.class);
-      plugin.putContext(service, getDeploymentUnit());
-   }
-
-   @Override
-   protected void beforeServiceUnregistration(OSGiServiceState service)
-   {
-      OSGiBundleManager manager = getBundleManager();
-      ControllerContextPlugin plugin = manager.getPlugin(ControllerContextPlugin.class);
-      plugin.removeContext(service, getDeploymentUnit());
-   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceReferenceWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceReferenceWrapper.java	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceReferenceWrapper.java	2010-02-10 11:38:18 UTC (rev 100796)
@@ -49,11 +49,6 @@
       this.serviceState = serviceState;
    }
 
-   ControllerContext getContext()
-   {
-      return getServiceState();
-   }
-
    public Bundle getBundle()
    {
       return serviceState.getBundle();
@@ -102,13 +97,13 @@
       return serviceState.toString();
    }
 
-   /**
-    * Get the serviceState.
-    * 
-    * @return the serviceState.
-    */
    OSGiServiceState getServiceState()
    {
       return serviceState;
    }
+
+   ControllerContext getContext()
+   {
+      return getServiceState();
+   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	2010-02-10 11:38:18 UTC (rev 100796)
@@ -35,6 +35,8 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.deployers.structure.spi.DeploymentRegistry;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.qualifier.QualifierMatchers;
@@ -57,6 +59,7 @@
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * A plugin that manages OSGi services.
@@ -78,12 +81,20 @@
    private Kernel kernel;
    /** The previous context tracker */
    private ContextTracker previousTracker;
+   /** The deployment registry */
+   private DeploymentRegistry registry;
+
    /** Enable MDR usage */
    private boolean enableMDRUsage = true;
    
-   public ServiceManagerPluginImpl(OSGiBundleManager bundleManager)
+   public ServiceManagerPluginImpl(OSGiBundleManager bundleManager, DeploymentRegistry registry)
    {
       super(bundleManager);
+      
+      if (registry == null)
+         throw new IllegalArgumentException("Null deployment registry");
+
+      this.registry = registry;
    }
 
    public void setEnableMDRUsage(boolean mdrUsage)
@@ -106,8 +117,7 @@
 
    public ServiceReference[] getRegisteredServices(AbstractBundleState bundleState)
    {
-      ControllerContextPlugin plugin = getBundleManager().getPlugin(ControllerContextPlugin.class);
-      Set<ControllerContext> contexts = plugin.getRegisteredContexts(bundleState);
+      Set<ControllerContext> contexts = getRegisteredContexts(bundleState);
       if (contexts.isEmpty())
          return null;
 
@@ -218,19 +228,27 @@
          throw new RuntimeException(t);
       }
 
-      FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
-      plugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
+      if (bundleState instanceof OSGiBundleState)
+      {
+         putContext(result, ((OSGiBundleState)bundleState).getDeploymentUnit());
+      }
 
+      FrameworkEventsPlugin eventsPlugin = getPlugin(FrameworkEventsPlugin.class);
+      eventsPlugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
+      
       return result;
    }
 
    public void unregisterService(OSGiServiceState serviceState)
    {
       AbstractBundleState bundleState = serviceState.getBundleState();
-      
+      if (bundleState instanceof OSGiBundleState)
+      {
+         removeContext(serviceState, ((OSGiBundleState)bundleState).getDeploymentUnit());
+      }
+
       Controller controller = kernel.getController();
       controller.uninstall(serviceState.getName());
-
       serviceState.internalUnregister();
 
       FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
@@ -250,6 +268,11 @@
       return bundleState.removeContextInUse(context);
    }
 
+   public void unregisterServices(AbstractBundleState bundleState)
+   {
+      unregisterContexts(bundleState);
+   }
+
    /**
     * Apply OSGi's MDR usage:
     * - add/remove system bundle as default context tracker
@@ -410,4 +433,40 @@
       }
       return true;
    }
+
+   private DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit)
+   {
+      return registry.putContext(context, unit);
+   }
+
+   private DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit)
+   {
+      return registry.removeContext(context, unit);
+   }
+
+   private Set<ControllerContext> getRegisteredContexts(AbstractBundleState bundleState)
+   {
+      if (bundleState instanceof OSGiBundleState == false)
+         return Collections.emptySet();
+
+      DeploymentUnit unit = ((OSGiBundleState)bundleState).getDeploymentUnit();
+      return registry.getContexts(unit);
+   }
+
+   private void unregisterContexts(AbstractBundleState bundleState)
+   {
+      if (bundleState instanceof OSGiBundleState)
+      {
+         DeploymentUnit unit = ((OSGiBundleState)bundleState).getDeploymentUnit();
+         Set<ControllerContext> contexts = registry.getContexts(unit);
+         for (ControllerContext context : contexts)
+         {
+            if (context instanceof ServiceRegistration)
+            {
+               ServiceRegistration service = (ServiceRegistration)context;
+               service.unregister();
+            }
+         }
+      }
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ControllerContextPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ControllerContextPlugin.java	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ControllerContextPlugin.java	2010-02-10 11:38:18 UTC (rev 100796)
@@ -21,10 +21,7 @@
  */
 package org.jboss.osgi.framework.plugins;
 
-import java.util.Set;
-
 import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
 
 
@@ -37,39 +34,6 @@
 public interface ControllerContextPlugin extends Plugin
 {
    /**
-    * Put context to deployment mapping.
-    *
-    * @param context the context
-    * @param unit the deployment
-    * @return previous mapping value
-    */
-   DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit);
-
-   /**
-    * Remove context to deployment mapping.
-    *
-    * @param context the context
-    * @param unit the deployment
-    * @return is previous mapping value same as unit param
-    */
-   DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit);
-
-   /**
-    * Get registered contexts for bundle.
-    *
-    * @param bundleState the owning bundle
-    * @return registered contexts
-    */
-   Set<ControllerContext> getRegisteredContexts(AbstractBundleState bundleState);
-
-   /**
-    * Unregister contexts.
-    *
-    * @param bundleState the stopping bundle
-    */
-   void unregisterContexts(AbstractBundleState bundleState);
-   
-   /**
     * Get bundle for user tracker.
     *
     * @param user the user tracker object

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ServiceManagerPlugin.java	2010-02-10 11:38:18 UTC (rev 100796)
@@ -140,4 +140,10 @@
     * 
     */
    void unregisterService(OSGiServiceState serviceState);
+
+   /**
+    * Unregister all services that were registered on behalf of the given bundle. 
+    * @param bundleState The bundle that registered the services.
+    */
+   void unregisterServices(AbstractBundleState bundleState);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2010-02-10 11:38:18 UTC (rev 100796)
@@ -61,7 +61,10 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiServiceManagerPlugin" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
-    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <constructor>
+      <parameter><inject bean="OSGiBundleManager" /></parameter>
+      <parameter><inject bean="OSGiDeploymentRegistry" /></parameter>
+    </constructor>
   </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2010-02-10 11:38:18 UTC (rev 100796)
@@ -110,7 +110,10 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
-    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <constructor>
+      <parameter><inject bean="OSGiBundleManager" /></parameter>
+      <parameter><inject bean="OSGiDeploymentRegistry" /></parameter>
+    </constructor>
     <property name="enableMDRUsage">false</property>
   </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-02-10 11:38:18 UTC (rev 100796)
@@ -85,7 +85,10 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiServiceManager" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
-    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <constructor>
+      <parameter><inject bean="OSGiBundleManager" /></parameter>
+      <parameter><inject bean="OSGiDeploymentRegistry" /></parameter>
+    </constructor>
   </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-02-10 11:07:51 UTC (rev 100795)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2010-02-10 11:38:18 UTC (rev 100796)
@@ -70,7 +70,10 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiServiceManagerPlugin" class="org.jboss.osgi.framework.bundle.ServiceManagerPluginImpl">
-    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <constructor>
+      <parameter><inject bean="OSGiBundleManager" /></parameter>
+      <parameter><inject bean="OSGiDeploymentRegistry" /></parameter>
+    </constructor>
   </bean>
   <bean name="OSGiStoragePlugin" class="org.jboss.osgi.framework.plugins.internal.BundleStoragePluginImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>




More information about the jboss-cvs-commits mailing list