[jboss-osgi-commits] JBoss-OSGI SVN: r96903 - in projects/jboss-osgi/trunk/reactor/framework/src: main/java/org/jboss/osgi/framework/bundle and 3 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Nov 24 19:29:12 EST 2009


Author: alesj
Date: 2009-11-24 19:29:11 -0500 (Tue, 24 Nov 2009)
New Revision: 96903

Added:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/SimpleOSGiServiceAction.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiContextTrackerDeployer.java
Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml
   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/ContextRegistryAction.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/OSGiBundleState.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
   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/OSGiSystemState.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFrameworkFactory.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
Log:
[JBOSGI-141]; remove custom tracking.

Modified: projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml	2009-11-25 00:29:11 UTC (rev 96903)
@@ -136,6 +136,7 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
+  <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
 
   <!--
   ********************************

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-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -32,17 +32,15 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.jboss.logging.Logger;
+import org.jboss.dependency.plugins.tracker.AbstractContextTracker;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
 import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
 import org.jboss.osgi.framework.plugins.LifecycleInterceptorServicePlugin;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.util.ConstantsHelper;
-import org.jboss.util.collection.ConcurrentSet;
 import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
@@ -66,13 +64,11 @@
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Thomas.Diesler at jboss.com
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
-public abstract class AbstractBundleState implements Bundle, BundleContext
+public abstract class AbstractBundleState extends AbstractContextTracker implements Bundle, BundleContext
 {
-   /** The log */
-   private static final Logger log = Logger.getLogger(AbstractBundleState.class);
-
    /** The last modified time stamp */
    private long lastModified = System.currentTimeMillis();
 
@@ -91,12 +87,6 @@
    /** The bundle state */
    private AtomicInteger state = new AtomicInteger(Bundle.UNINSTALLED);
 
-   /** The registered services in use */
-   protected Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
-
-   /** The services in use */
-   protected final Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
-   
    /** The cached symbolic name */
    private String symbolicName;
    
@@ -113,6 +103,7 @@
    {
       if (osgiMetaData == null)
          throw new IllegalArgumentException("Null osgi metadata");
+
       this.osgiMetaData = osgiMetaData;
    }
 
@@ -312,7 +303,7 @@
     */
    void addRegisteredService(OSGiServiceState serviceState)
    {
-      registeredServices.add(serviceState);
+      addUsedBy(serviceState, this);
    }
 
    /**
@@ -322,18 +313,19 @@
     */
    void removeRegisteredService(OSGiServiceState serviceState)
    {
-      registeredServices.remove(serviceState);
+      removeUsedBy(serviceState, this);
    }
 
    public ServiceReference[] getRegisteredServices()
    {
       checkInstalled();
 
-      if (registeredServices.isEmpty())
+      Set<OSGiServiceState> contexts = getUsedContexts(OSGiServiceState.class);
+      if (contexts.isEmpty())
          return null;
 
-      Set<ServiceReference> result = new HashSet<ServiceReference>(registeredServices.size());
-      for (OSGiServiceState service : registeredServices)
+      Set<ServiceReference> result = new HashSet<ServiceReference>();
+      for (OSGiServiceState service : contexts)
       {
          if (service.hasPermission())
             result.add(service.getReferenceInternal());
@@ -351,11 +343,7 @@
     */
    boolean isServiceInUse(OSGiServiceState serviceState)
    {
-      synchronized (servicesInUse)
-      {
-         Integer count = servicesInUse.get(serviceState);
-         return (count != null && count > 0);
-      }
+      return isContextInUse(serviceState);
    }
 
    /**
@@ -365,15 +353,7 @@
     */
    void addServiceInUse(OSGiServiceState serviceState)
    {
-      synchronized (servicesInUse)
-      {
-         Integer count = servicesInUse.get(serviceState);
-         if (count == null)
-            servicesInUse.put(serviceState, 1);
-         else
-            servicesInUse.put(serviceState, ++count);
-      }
-      serviceState.addUsingBundle(this);
+      serviceState.getTarget(this);
    }
 
    /**
@@ -384,47 +364,29 @@
     */
    boolean removeServiceInUse(OSGiServiceState serviceState)
    {
-      synchronized (servicesInUse)
-      {
-         Integer count = servicesInUse.get(serviceState);
-         if (count == null)
-         {
-            return false;
-         }
-         else if (count == 1)
-         {
-            servicesInUse.remove(serviceState);
-            serviceState.removeUsingBundle(this);
-            return false;
-         }
-         else
-         {
-            servicesInUse.put(serviceState, --count);
-         }
-      }
-      return true;
+      serviceState.ungetTarget(this);
+      return isContextInUse(serviceState);
    }
 
    public ServiceReference[] getServicesInUse()
    {
-      checkInstalled();
+      Set<OSGiServiceState> contexts = getUsedContexts(OSGiServiceState.class);
+      if (contexts == null || contexts.isEmpty())
+         return null;
 
-      synchronized (servicesInUse)
+      List<ServiceReference> references = new ArrayList<ServiceReference>();
+      for (OSGiServiceState service : contexts)
       {
-         Collection<OSGiServiceState> inUse = servicesInUse.keySet();
-         if (inUse.isEmpty())
-            return null;
-
-         Set<ServiceReference> result = new HashSet<ServiceReference>(inUse.size());
-         for (OSGiServiceState service : inUse)
+         if (getUsedByCount(service, this) > 0)
          {
             if (service.hasPermission())
-               result.add(service.getReferenceInternal());
+               references.add(service.getReferenceInternal());
          }
-         if (result.isEmpty())
-            return null;
-         return result.toArray(new ServiceReference[result.size()]);
       }
+
+      if (references.isEmpty())
+         return null;      
+      return references.toArray(new ServiceReference[references.size()]);
    }
 
    public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -30,7 +30,7 @@
  *
  * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  */
-class ContextRegistryAction extends OSGiServiceAction
+class ContextRegistryAction extends SimpleOSGiServiceAction
 {
    /**
     * Get context registry.
@@ -68,29 +68,4 @@
          }
       }
    }
-
-   protected void installAction(OSGiServiceState context) throws Throwable
-   {
-      try
-      {
-         handleContext(context, true);
-      }
-      catch (Throwable t)
-      {
-         uninstall(context);
-         throw t;
-      }
-   }
-
-   protected void uninstallAction(OSGiServiceState context)
-   {
-      try
-      {
-         handleContext(context, false);
-      }
-      catch (Throwable t)
-      {
-         log.warn("Ignoring exception at un-registering context: " + t);
-      }
-   }
 }
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java (from rev 96822, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
+
+/**
+ * Describe osgi service, its metadata.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+class DescribeAction extends SimpleOSGiServiceAction
+{
+   protected void handleContext(OSGiServiceState context, boolean install)
+   {
+      Controller controller = context.getController();
+      if (controller instanceof KernelController)
+      {
+         KernelController kc = (KernelController)controller;
+         Kernel kernel = kc.getKernel();
+         KernelMetaDataRepository repository = kernel.getMetaDataRepository();
+         if (install)
+         {
+            repository.addMetaData(context);
+            repository.getMetaData(context); // TODO - remove this once we fix it in MC core
+         }
+         else
+         {
+            repository.removeMetaData(context);
+         }
+      }
+   }
+}
\ No newline at end of file

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-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -21,8 +21,6 @@
 */
 package org.jboss.osgi.framework.bundle;
 
-import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -48,8 +46,8 @@
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.jar.Attributes;
+import java.util.jar.Attributes.Name;
 import java.util.jar.Manifest;
-import java.util.jar.Attributes.Name;
 
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerContext;
@@ -77,6 +75,7 @@
 import org.jboss.osgi.framework.plugins.ResolverPlugin;
 import org.jboss.osgi.framework.plugins.ServicePlugin;
 import org.jboss.osgi.framework.util.NoFilter;
+import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
 import org.jboss.util.collection.ConcurrentSet;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VFSUtils;
@@ -222,7 +221,8 @@
       attributes.put(new Name(Constants.BUNDLE_NAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
       attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
       OSGiMetaData systemMetaData = new AbstractOSGiMetaData(manifest);
-      addBundle(systemBundle = new OSGiSystemState(this, systemMetaData));
+      systemBundle = new OSGiSystemState(systemMetaData);
+      addBundle(systemBundle);
    }
 
    /**

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -25,12 +25,10 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
-import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.logging.Logger;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.plugins.PackageAdminPlugin;
 import org.jboss.virtual.VirtualFile;
@@ -45,13 +43,11 @@
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Thomas.Diesler at jboss.com
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public class OSGiBundleState extends AbstractBundleState
 {
-   /** The log */
-   private static final Logger log = Logger.getLogger(OSGiBundleState.class);
-
    /** Used to generate a unique id */
    private static final AtomicLong bundleIDGenerator = new AtomicLong();
 
@@ -63,7 +59,7 @@
 
    /** The deployment unit */
    private DeploymentUnit unit;
-   
+
    /**
     * Create a new BundleState.
     * 
@@ -80,7 +76,7 @@
          throw new IllegalArgumentException("Null bundle location");
       if (unit == null)
           throw new IllegalArgumentException("Null deployment unit");
-      
+
       this.unit = unit;
       this.location = location;
       
@@ -347,24 +343,10 @@
             }
          }
 
-         for (OSGiServiceState service : registeredServices)
+         for (OSGiServiceState service : getUsedContexts(OSGiServiceState.class))
          {
-            try
+            while (getUsedByCount(service, this) > 0)
             {
-               service.unregister();
-            }
-            catch (Throwable t)
-            {
-               log.debug("Error unregistering service: " + service, t);
-            }
-         }
-
-         for (Map.Entry<OSGiServiceState, Integer> inUse : servicesInUse.entrySet())
-         {
-            OSGiServiceState service = inUse.getKey();
-            Integer count = inUse.getValue();
-            for (int i = 0; i < count; ++i)
-            {
                try
                {
                   getBundleManager().ungetService(this, service);
@@ -374,6 +356,8 @@
                   log.debug("Error ungetting service: " + service, t);
                }
             }
+
+            service.unregister();
          }
 
          if (getState() != STOPPING)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -21,7 +21,7 @@
 */
 package org.jboss.osgi.framework.bundle;
 
-import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.jboss.dependency.plugins.AbstractControllerContextActions;
@@ -50,6 +50,9 @@
     */
    private static Map<ControllerState, ControllerContextAction> getActions()
    {
-      return Collections.<ControllerState, ControllerContextAction>singletonMap(ControllerState.INSTANTIATED, new ContextRegistryAction());
+      Map<ControllerState, ControllerContextAction> map = new HashMap<ControllerState, ControllerContextAction>(2);
+      map.put(ControllerState.DESCRIBED, new DescribeAction());
+      map.put(ControllerState.INSTANTIATED, new ContextRegistryAction());
+      return map;
    }
 }
\ No newline at end of file

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-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -24,9 +24,10 @@
 import java.security.AccessControlContext;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -34,13 +35,18 @@
 
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.spi.ScopeInfo;
 import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
 import org.jboss.osgi.framework.util.CaseInsensitiveDictionary;
 import org.jboss.osgi.spi.util.BundleClassLoader;
-import org.jboss.util.collection.ConcurrentSet;
 import org.jboss.util.id.GUID;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
@@ -91,9 +97,6 @@
    /** The properties */
    private CaseInsensitiveDictionary properties;
 
-   /** The using bundles */
-   private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
-
    /** The bean info */
    private BeanInfo beanInfo;
 
@@ -190,9 +193,49 @@
       else if (clazzes.length == 1)
          className = clazzes[0];
 
-      setScopeInfo(OSGiScopeInfo.createScopeInfo(getName(), className, clazz, this));
+      ScopeInfo info = OSGiScopeInfo.createScopeInfo(getName(), className, clazz, this);
+      setScopeInfo(info);
+
+      ScopeKey scope;
+      ScopeKey mutableScope;
+      if (bundleState instanceof OSGiBundleState)
+      {
+         OSGiBundleState obs = (OSGiBundleState)bundleState;
+         DeploymentUnit unit = obs.getDeploymentUnit();
+         scope = unit.getScope();
+         mutableScope = unit.getMutableScope();
+      }
+      else
+      {
+         // TODO - what to do for system bundle?
+         scope = new ScopeKey(CommonLevels.SERVER, "JBoss");
+         mutableScope = null;
+      }
+      mergeScopes(info.getScope(), scope);
+      mergeScopes(info.getMutableScope(), mutableScope);
    }
 
+   /**
+    * Merge scope keys.
+    *
+    * @param contextKey the context key
+    * @param unitKey the unit key
+    */
+   protected static void mergeScopes(ScopeKey contextKey, ScopeKey unitKey)
+   {
+      if (contextKey == null)
+         return;
+      if (unitKey == null)
+         return;
+
+      Collection<Scope> unitScopes = unitKey.getScopes();
+      if (unitScopes == null || unitScopes.isEmpty())
+         return;
+
+      for (Scope scope : unitScopes)
+         contextKey.addScope(scope);
+   }
+
    @Override
    public Object getTarget()
    {
@@ -373,35 +416,23 @@
       plugin.fireServiceEvent(bundleState, ServiceEvent.MODIFIED, this);
    }
 
-   /**
-    * Mark a bundle as using this service
-    * 
-    * @param bundleState the bundle
-    */
-   void addUsingBundle(AbstractBundleState bundleState)
-   {
-      usingBundles.add(bundleState);
-   }
-
-   /**
-    * Unmark a bundle as using this service
-    * 
-    * @param bundleState the bundle
-    */
-   void removeUsingBundle(AbstractBundleState bundleState)
-   {
-      usingBundles.remove(bundleState);
-   }
-
    public Bundle[] getUsingBundles()
    {
-      if (usingBundles.isEmpty())
+      ContextTracker ct = getContextTracker();
+      if (ct == null)
          return null;
 
-      Set<Bundle> result = new HashSet<Bundle>();
-      for (AbstractBundleState bundleState : usingBundles)
-         result.add(bundleState.getBundleInternal());
-      return result.toArray(new Bundle[result.size()]);
+      Set<Object> users = ct.getUsers(this);
+      List<Bundle> bundles = new ArrayList<Bundle>();
+      for (Object user : users)
+      {
+         if (user instanceof AbstractBundleState && ct.getUsedByCount(this, user) > 0)
+         {
+            AbstractBundleState abs = (AbstractBundleState)user;
+            bundles.add(abs.getBundleInternal());
+         }
+      }
+      return bundles.toArray(new Bundle[bundles.size()]);
    }
 
    public boolean isAssignableTo(Bundle bundle, String className)
@@ -592,8 +623,6 @@
       builder.append(serviceOrFactory instanceof ServiceFactory ? " factory=" : " service=").append(serviceOrFactory);
       if (properties != null)
          builder.append(" properties=").append(properties);
-      if (usingBundles.isEmpty() == false)
-         builder.append(" using=").append(usingBundles);
       builder.append("}");
       return builder.toString();
    }
@@ -612,26 +641,35 @@
     */
    void internalUnregister()
    {
-      if (usingBundles.isEmpty() == false)
+      ContextTracker ct = getContextTracker();
+      if (ct != null) // nobody used us?
       {
-         for (AbstractBundleState using : usingBundles)
+         Set<Object> users = ct.getUsers(this);
+         if (users.isEmpty() == false)
          {
-            if (using.ungetService(this) == false)
+            for (Object user : users)
             {
-               if (serviceOrFactory instanceof ServiceFactory)
+               if (user instanceof AbstractBundleState)
                {
-                  ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
-                  try
+                  AbstractBundleState using = (AbstractBundleState)user;
+                  if (using.ungetService(this) == false)
                   {
-                     Object service = serviceCache.remove(using);
-                     serviceFactory.ungetService(using.getBundle(), getRegistration(), service);
+                     if (serviceOrFactory instanceof ServiceFactory)
+                     {
+                        ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
+                        try
+                        {
+                           Object service = serviceCache.remove(using);
+                           serviceFactory.ungetService(using.getBundle(), getRegistration(), service);
+                        }
+                        catch (Throwable t)
+                        {
+                           log.warn("Error from ungetService for " + this, t);
+                           FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+                           plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
+                        }
+                     }
                   }
-                  catch (Throwable t)
-                  {
-                     log.warn("Error from ungetService for " + this, t);
-                     FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
-                     plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
-                  }
                }
             }
          }

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -26,7 +26,6 @@
 import java.net.URL;
 import java.util.Enumeration;
 
-import org.jboss.logging.Logger;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.osgi.framework.BundleException;
@@ -37,19 +36,16 @@
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Thomas.Diesler at jboss.com
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public class OSGiSystemState extends AbstractBundleState
 {
-   /** The log */
-   private static final Logger log = Logger.getLogger(OSGiSystemState.class);
-   
    /**
     * Create a new OSGiSystemBundle.
-    * @param bundleManager the bundle manager associated with the system bundle 
     * @param osgiMetaData the metadata for the system bundle
     */
-   public OSGiSystemState(OSGiBundleManager bundleManager, OSGiMetaData osgiMetaData)
+   public OSGiSystemState(OSGiMetaData osgiMetaData)
    {
       super(osgiMetaData);
    }

Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/SimpleOSGiServiceAction.java (from rev 96816, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/SimpleOSGiServiceAction.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/SimpleOSGiServiceAction.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+/**
+ * Handle OSGi service context.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class SimpleOSGiServiceAction extends OSGiServiceAction
+{
+   /**
+    * Handle osgi context.
+    *
+    * @param context the context
+    * @param install are we in install phase
+    * @throws Throwable for any error
+    */
+   protected abstract void handleContext(OSGiServiceState context, boolean install) throws Throwable;
+
+   protected void installAction(OSGiServiceState context) throws Throwable
+   {
+      try
+      {
+         handleContext(context, true);
+      }
+      catch (Throwable t)
+      {
+         uninstall(context);
+         throw t;
+      }
+   }
+
+   protected void uninstallAction(OSGiServiceState context)
+   {
+      try
+      {
+         handleContext(context, false);
+      }
+      catch (Throwable t)
+      {
+         log.warn("Ignoring exception at un-installing context: " + t);
+      }
+   }
+}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiContextTrackerDeployer.java (from rev 96803, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiContextTrackerDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiContextTrackerDeployer.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.deployers;
+
+import org.jboss.dependency.spi.tracker.ContextTracker;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+
+/**
+ * Add context tracker to deployment.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class OSGiContextTrackerDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
+{
+   public OSGiContextTrackerDeployer()
+   {
+      super(OSGiBundleState.class);
+      setStage(DeploymentStages.POST_PARSE);      
+   }
+
+   public void deploy(DeploymentUnit unit, OSGiBundleState deployment) throws DeploymentException
+   {
+      // add it to metadata so other non-osgi pieces can use it
+      unit.getMutableMetaData().addMetaData(deployment, ContextTracker.class);
+   }
+
+   @Override
+   public void undeploy(DeploymentUnit unit, OSGiBundleState deployment)
+   {
+      unit.getMutableMetaData().removeMetaData(ContextTracker.class);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFrameworkFactory.java	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFrameworkFactory.java	2009-11-25 00:29:11 UTC (rev 96903)
@@ -92,7 +92,7 @@
       }
 
       // Default bootstrap paths
-      List<String> bootstraps = Arrays.asList("jboss-osgi-bootstrap.xml", "META-INF/jboss-osgi-bootstrap.xml", "META-INF/jboss-osgi-default-bootstrap.xml");
+      List<String> bootstraps = Arrays.asList("jboss-osgi-bootstrap.xml", "bootstrap/jboss-osgi-bootstrap.xml", "META-INF/jboss-osgi-bootstrap.xml", "META-INF/jboss-osgi-default-bootstrap.xml");
 
       // Specified bootstrap path
       String bootstrapPath = getProperty(BOOTSTRAP_PATH);
@@ -107,7 +107,7 @@
          
          if (url == null)
             url = getClass().getResource(xml);
-         
+
          if (url != null)
             break;
       }

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2009-11-25 00:01:26 UTC (rev 96902)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2009-11-25 00:29:11 UTC (rev 96903)
@@ -135,6 +135,7 @@
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
+  <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
 
   <!--
   ********************************



More information about the jboss-osgi-commits mailing list