[jboss-osgi-commits] JBoss-OSGI SVN: r99652 - in projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework: plugins and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Jan 20 06:17:28 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-20 06:17:27 -0500 (Wed, 20 Jan 2010)
New Revision: 99652

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/ControllerContextPluginImpl.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/OSGiSystemState.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
Log:
Simplify ControllerContext handling

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-01-20 10:44:03 UTC (rev 99651)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-01-20 11:17:27 UTC (rev 99652)
@@ -29,7 +29,6 @@
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -39,7 +38,6 @@
 import java.util.MissingResourceException;
 import java.util.PropertyResourceBundle;
 import java.util.ResourceBundle;
-import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.jboss.dependency.plugins.tracker.AbstractContextTracker;
@@ -419,16 +417,6 @@
       plugin.removeServiceListener(this, listener);
    }
 
-   /**
-    * Get registered contexts.
-    *
-    * @return the registered contexts
-    */
-   protected Set<ControllerContext> getRegisteredContexts()
-   {
-      return Collections.emptySet();
-   }
-
    public ServiceReference[] getRegisteredServices()
    {
       checkInstalled();

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java	2010-01-20 10:44:03 UTC (rev 99651)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java	2010-01-20 11:17:27 UTC (rev 99652)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import java.util.Collections;
 import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
@@ -49,10 +50,10 @@
 {
    // Provide logging
    final Logger log = Logger.getLogger(ControllerContextPluginImpl.class);
-   
+
    /** The deployment registry */
    private DeploymentRegistry registry;
-   
+
    public ControllerContextPluginImpl(OSGiBundleManager bundleManager, DeploymentRegistry registry)
    {
       super(bundleManager);
@@ -73,9 +74,12 @@
       return registry.removeContext(context, unit);
    }
 
-   public Set<ControllerContext> getRegisteredContext(AbstractDeployedBundleState bundleState)
+   public Set<ControllerContext> getRegisteredContexts(AbstractBundleState bundleState)
    {
-      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      if (bundleState instanceof OSGiBundleState == false)
+         return Collections.emptySet();
+
+      DeploymentUnit unit = ((OSGiBundleState)bundleState).getDeploymentUnit();
       return registry.getContexts(unit);
    }
 
@@ -154,22 +158,20 @@
     *
     * @param bundleState the stopping bundle
     */
-   public void unregisterContexts(AbstractDeployedBundleState bundleState)
+   public void unregisterContexts(AbstractBundleState bundleState)
    {
-      DeploymentUnit unit = bundleState.getDeploymentUnit();
-      Set<ControllerContext> contexts = registry.getContexts(unit);
-      for (ControllerContext context : contexts)
+      if (bundleState instanceof OSGiBundleState)
       {
-         unregisterContext(context);
+         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();
+            }
+         }
       }
    }
-
-   private void unregisterContext(ControllerContext context)
-   {
-      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/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-01-20 10:44:03 UTC (rev 99651)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-01-20 11:17:27 UTC (rev 99652)
@@ -136,7 +136,7 @@
    {
       OSGiBundleManager manager = getBundleManager();
       ControllerContextPlugin plugin = manager.getPlugin(ControllerContextPlugin.class);
-      return plugin.getRegisteredContext(this);
+      return plugin.getRegisteredContexts(this);
    }
 
    public Class<?> loadClass(String name) throws ClassNotFoundException

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	2010-01-20 10:44:03 UTC (rev 99651)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2010-01-20 11:17:27 UTC (rev 99652)
@@ -25,15 +25,12 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
-import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
 import java.util.jar.Attributes.Name;
 
-import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
-import org.jboss.util.collection.ConcurrentSet;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 
@@ -47,8 +44,6 @@
  */
 public class OSGiSystemState extends AbstractBundleState
 {
-   /** The registred contexts */
-   private Set<ControllerContext> registered = new ConcurrentSet<ControllerContext>();
    /** The osgi metadata */
    private OSGiMetaData osgiMetaData;
 
@@ -74,23 +69,6 @@
       return false;
    }
    
-   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/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-01-20 10:44:03 UTC (rev 99651)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java	2010-01-20 11:17:27 UTC (rev 99652)
@@ -92,7 +92,8 @@
 
    public ServiceReference[] getRegisteredServices(AbstractBundleState bundleState)
    {
-      Set<ControllerContext> contexts = bundleState.getRegisteredContexts();
+      ControllerContextPlugin plugin = getBundleManager().getPlugin(ControllerContextPlugin.class);
+      Set<ControllerContext> contexts = plugin.getRegisteredContexts(bundleState);
       if (contexts.isEmpty())
          return null;
 

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-01-20 10:44:03 UTC (rev 99651)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/plugins/ControllerContextPlugin.java	2010-01-20 11:17:27 UTC (rev 99652)
@@ -26,7 +26,6 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
 
 
 /**
@@ -61,14 +60,14 @@
     * @param bundleState the owning bundle
     * @return registered contexts
     */
-   Set<ControllerContext> getRegisteredContext(AbstractDeployedBundleState bundleState);
+   Set<ControllerContext> getRegisteredContexts(AbstractBundleState bundleState);
 
    /**
     * Unregister contexts.
     *
     * @param bundleState the stopping bundle
     */
-   void unregisterContexts(AbstractDeployedBundleState bundleState);
+   void unregisterContexts(AbstractBundleState bundleState);
    
    /**
     * Get bundle for user tracker.



More information about the jboss-osgi-commits mailing list