[jboss-cvs] JBossAS SVN: r90244 - projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 16 05:26:50 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-06-16 05:26:50 -0400 (Tue, 16 Jun 2009)
New Revision: 90244

Modified:
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedBundle.java
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
Log:
cache basic remote bundle properties

Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedBundle.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedBundle.java	2009-06-16 08:55:09 UTC (rev 90243)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedBundle.java	2009-06-16 09:26:50 UTC (rev 90244)
@@ -37,10 +37,12 @@
  */
 public class EmbeddedBundle extends OSGiBundle
 {
+   private OSGiRuntimeImpl runtime;
    private Bundle bundle;
 
-   public EmbeddedBundle(Bundle bundle)
+   public EmbeddedBundle(OSGiRuntimeImpl runtime, Bundle bundle)
    {
+      this.runtime = runtime;
       this.bundle = bundle;
    }
 
@@ -105,5 +107,6 @@
    public void uninstall() throws BundleException
    {
       bundle.uninstall();
+      runtime.unregisterBundle(this);
    }
 }

Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java	2009-06-16 08:55:09 UTC (rev 90243)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/EmbeddedRuntime.java	2009-06-16 09:26:50 UTC (rev 90244)
@@ -75,7 +75,7 @@
       service.deploy(bundleURL);
       
       OSGiBundle bundle = getBundle(symbolicName, null);
-      return registerBundleForUninstall(location, bundle);
+      return registerBundle(location, bundle);
    }
 
    public OSGiBundle[] getBundles()
@@ -83,7 +83,7 @@
       List<OSGiBundle> absBundles = new ArrayList<OSGiBundle>();
       for (Bundle bundle : getBundleContext().getBundles())
       {
-         absBundles.add(new EmbeddedBundle(bundle));
+         absBundles.add(new EmbeddedBundle(this, bundle));
       }
       OSGiBundle[] bundleArr = new OSGiBundle[absBundles.size()];
       absBundles.toArray(bundleArr);

Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-06-16 08:55:09 UTC (rev 90243)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-06-16 09:26:50 UTC (rev 90244)
@@ -29,6 +29,8 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
@@ -44,6 +46,7 @@
 import org.jboss.osgi.spi.testing.OSGiRuntime;
 import org.jboss.osgi.spi.testing.OSGiServiceReference;
 import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.service.log.LogReaderService;
@@ -86,12 +89,6 @@
       return logReaderService;
    }
 
-   protected OSGiBundle registerBundleForUninstall(String location, OSGiBundle bundle)
-   {
-      bundles.put(location, bundle);
-      return bundle;
-   }
-
    public void addCapability(Capability capability) throws BundleException
    {
       // Add dependent capabilies
@@ -257,13 +254,43 @@
       return symbolicName;
    }
 
+   OSGiBundle registerBundle(String location, OSGiBundle bundle)
+   {
+      if (bundle == null)
+         throw new IllegalArgumentException("Cannot register null bundle for: " + location);
+      
+      bundles.put(location, bundle);
+      return bundle;
+   }
+
+   void unregisterBundle(OSGiBundle bundle)
+   {
+      if (bundle == null)
+         throw new IllegalArgumentException("Cannot unregister null bundle");
+      
+      if (bundles.containsValue(bundle))
+      {
+         Set<Entry<String, OSGiBundle>> entrySet = bundles.entrySet();
+         for (Entry<String, OSGiBundle> entry : entrySet)
+         {
+            if (bundle.equals(entry.getValue()))
+            {
+               String key = entry.getKey();
+               bundles.remove(key);
+               break;
+            }
+         }
+      }
+   }
+
    private void failsafeUninstall(OSGiBundle bundle)
    {
       if (bundle != null)
       {
          try
          {
-            bundle.uninstall();
+            if (bundle.getState() != Bundle.UNINSTALLED)
+               bundle.uninstall();
          }
          catch (BundleException ex)
          {

Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java	2009-06-16 08:55:09 UTC (rev 90243)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java	2009-06-16 09:26:50 UTC (rev 90244)
@@ -46,11 +46,19 @@
    private boolean uninstalled;
    private String location;
 
+   private long bundleId;
+   private String symbolicName;
+   private String version;
+   
    public RemoteBundle(OSGiRuntimeImpl runtime, ManagedBundleMBean bundle, String location)
    {
       this.runtime = runtime;
       this.bundle = bundle;
       this.location = location;
+      
+      this.bundleId = bundle.getBundleId();
+      this.symbolicName = bundle.getSymbolicName();
+      this.version = getHeaders().get(Constants.BUNDLE_VERSION);
    }
 
    @Override
@@ -60,17 +68,21 @@
    }
 
    @Override
+   public long getBundleId()
+   {
+      return bundleId;
+   }
+
+   @Override
    public String getSymbolicName()
    {
-      assertNotUninstalled();
-      return bundle.getSymbolicName();
+      return symbolicName;
    }
 
    @Override
    public String getVersion()
    {
-      assertNotUninstalled();
-      return getHeaders().get(Constants.BUNDLE_VERSION);
+      return version;
    }
 
    @Override
@@ -81,13 +93,6 @@
    }
 
    @Override
-   public long getBundleId()
-   {
-      assertNotUninstalled();
-      return bundle.getBundleId();
-   }
-
-   @Override
    public String getProperty(String key)
    {
       assertNotUninstalled();
@@ -115,6 +120,7 @@
       try
       {
          runtime.undeploy(location);
+         runtime.unregisterBundle(this);
          uninstalled = true;
       }
       catch (RuntimeException rte)

Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-06-16 08:55:09 UTC (rev 90243)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-06-16 09:26:50 UTC (rev 90244)
@@ -79,7 +79,7 @@
          deploy(location);
          ManagedBundleMBean bundleMBean = getRemoteFramework().getBundle(symbolicName);
          RemoteBundle bundle = new RemoteBundle(this, bundleMBean, location);
-         return registerBundleForUninstall(location, bundle);
+         return registerBundle(location, bundle);
       }
       catch (RuntimeException rte)
       {




More information about the jboss-cvs-commits mailing list