felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r962650 - in /felix/sandbox/rickhall/vb: composite/src/main/java/org/apache/felix/sandbox/composite/ framework-vb/src/main/java/org/apache/felix/framework/
Date Fri, 09 Jul 2010 19:22:39 GMT
Author: rickhall
Date: Fri Jul  9 19:22:38 2010
New Revision: 962650

URL: http://svn.apache.org/viewvc?rev=962650&view=rev
Log:
Merge branch 'composite'

Modified:
    felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Activator.java
    felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/CompositeVirtualModule.java
    felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Manager.java
    felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
    felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java

Modified: felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Activator.java?rev=962650&r1=962649&r2=962650&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Activator.java
(original)
+++ felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Activator.java
Fri Jul  9 19:22:38 2010
@@ -31,6 +31,7 @@ public class Activator implements Bundle
         if (bc instanceof FelixBundleContext)
         {
             m_manager = new Manager((FelixBundleContext) bc);
+            m_manager.start();
 
             Hashtable props = new Hashtable();
             props.put("osgi.command.scope", "composite");
@@ -48,5 +49,6 @@ public class Activator implements Bundle
 
     public void stop(BundleContext bc) throws Exception
     {
+        m_manager.stop();
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/CompositeVirtualModule.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/CompositeVirtualModule.java?rev=962650&r1=962649&r2=962650&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/CompositeVirtualModule.java
(original)
+++ felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/CompositeVirtualModule.java
Fri Jul  9 19:22:38 2010
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.security.SecureClassLoader;
+import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
@@ -53,10 +54,16 @@ public class CompositeVirtualModule impl
     private volatile ClassLoader m_loader = null;
     private volatile PackageProviderVirtualModule m_importToExportVM = null;
 
-    public CompositeVirtualModule(Bundle manager, Map headers)
+    public CompositeVirtualModule(Bundle manager, Dictionary dict)
     {
         m_manager = manager;
-        m_headers = headers;
+        Map map = new HashMap();
+        for (Enumeration<String> keys = dict.keys(); keys.hasMoreElements(); )
+        {
+            String key = keys.nextElement();
+            map.put(key, dict.get(key));
+        }
+        m_headers = map;
     }
 
     public void initialize(VirtualModuleContext vmc) throws BundleException
@@ -90,16 +97,20 @@ public class CompositeVirtualModule impl
             m_loader = new CompositeClassLoader();
             if (m_headers.containsKey("Import-Package"))
             {
-                try
-                {
                 String sn = (String) m_headers.get("Bundle-SymbolicName") + ".PPVM";
                 m_importToExportVM =
                     new PackageProviderVirtualModule(
                         sn, (String) m_headers.get("Import-Package"), m_wires);
-                ((FelixBundleContext) m_fwk.getBundleContext()).installBundle(
-                    sn, m_importToExportVM.getHeaders(), m_importToExportVM);
-                } catch (Exception ex) {
-                    ex.printStackTrace();
+                Bundle vb = getBundle(m_fwk.getBundleContext().getBundles(), sn);
+                if (vb == null)
+                {
+                    ((FelixBundleContext) m_fwk.getBundleContext()).installBundle(
+                        sn, m_importToExportVM.getHeaders(), m_importToExportVM);
+                }
+                else
+                {
+                    ((FelixBundleContext) m_fwk.getBundleContext()).reinstallBundle(
+                        vb, m_importToExportVM);
                 }
             }
         }

Modified: felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Manager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Manager.java?rev=962650&r1=962649&r2=962650&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Manager.java
(original)
+++ felix/sandbox/rickhall/vb/composite/src/main/java/org/apache/felix/sandbox/composite/Manager.java
Fri Jul  9 19:22:38 2010
@@ -25,18 +25,52 @@ import java.util.Properties;
 import org.apache.felix.framework.ext.FelixBundleContext;
 import org.apache.felix.framework.ext.VirtualModuleContext;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
 
 public class Manager
 {
+    private static final String MANAGER_HEADER = "Bundle-Manager";
+    private static final String MANAGER_VALUE = "org.apache.felix.sandbox.composite";
+
     private final FelixBundleContext m_fbc;
+    private final BundleTracker m_tracker;
     private final Map<Bundle, CompositeVirtualModule> m_vmMap =
         new HashMap<Bundle, CompositeVirtualModule>();
 
     public Manager(FelixBundleContext fbc)
     {
         m_fbc = fbc;
+        m_tracker = new BundleTracker(
+            fbc,
+            Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING
+            | Bundle.ACTIVE | Bundle.STOPPING,
+            new Customizer());
+    }
+
+    public void start()
+    {
+        m_tracker.open();
+    }
+
+    public void stop()
+    {
+        m_tracker.close();
+        ServiceReference sr = m_fbc.getServiceReference(PackageAdmin.class.getName());
+        if (sr != null)
+        {
+            PackageAdmin pa = (PackageAdmin) m_fbc.getService(sr);
+            if (pa != null)
+            {
+                Bundle[] bs = m_vmMap.keySet().toArray(new Bundle[m_vmMap.size()]);
+                pa.refreshPackages(bs);
+            }
+        }
     }
 
     public Bundle install(String location, InputStream is) throws BundleException
@@ -51,8 +85,7 @@ public class Manager
                 headers.setProperty(
                     "Bundle-Activator",
                     "org.apache.felix.sandbox.composite.activator.Activator");
-                headers.setProperty(
-                    "Bundle-Manager", "org.apache.felix.sandbox.composite");
+                headers.setProperty(MANAGER_HEADER, MANAGER_VALUE);
             }
             finally
             {
@@ -81,4 +114,68 @@ public class Manager
         }
         return fwk;
     }
+
+    class Customizer implements BundleTrackerCustomizer
+    {
+        public Object addingBundle(Bundle bundle, BundleEvent event)
+        {
+System.out.println("+++ ADDING " + bundle + " " + getStateString(bundle.getState()));
+            if ((bundle.getHeaders().get(MANAGER_HEADER) != null)
+                && bundle.getHeaders().get(MANAGER_HEADER).equals(MANAGER_VALUE))
+            {
+                if (!m_vmMap.containsKey(bundle))
+                {
+                    try
+                    {
+                        CompositeVirtualModule vm = new CompositeVirtualModule(
+                            m_fbc.getBundle(), bundle.getHeaders());
+                        VirtualModuleContext vmc =
+                            m_fbc.reinstallBundle(bundle, vm);
+                        vm.initialize(vmc);
+                        m_vmMap.put(vmc.getBundle(), vm);
+                    }
+                    catch (BundleException ex)
+                    {
+                        System.out.println("Manager error: " + ex);
+                    }
+                }
+            }
+            else
+            {
+                bundle = null;
+            }
+            return bundle;
+        }
+
+        public void modifiedBundle(Bundle bundle, BundleEvent event, Object object)
+        {
+            System.out.println("+++ MODIFIED " + bundle + " " + getStateString(bundle.getState()));
+        }
+
+        public void removedBundle(Bundle bundle, BundleEvent event, Object object)
+        {
+            System.out.println("+++ REMOVED " + bundle + " " + getStateString(bundle.getState()));
+        }
+    }
+
+    private static String getStateString(int i)
+    {
+        switch (i)
+        {
+            case Bundle.INSTALLED:
+                return "Installed";
+            case Bundle.RESOLVED:
+                return "Resolved";
+            case Bundle.STARTING:
+                return "Starting";
+            case Bundle.ACTIVE:
+                return "Active";
+            case Bundle.STOPPING:
+                return "Stopping";
+            case Bundle.UNINSTALLED:
+                return "UNINSTALLED";
+        }
+
+        return "Unknown";
+    }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java?rev=962650&r1=962649&r2=962650&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
Fri Jul  9 19:22:38 2010
@@ -2819,8 +2819,6 @@ ex.printStackTrace();
 
         try
         {
-            Throwable rethrow = null;
-
             if (vb.getCurrentModule() instanceof UnmanagedModuleImpl)
             {
                 ((UnmanagedModuleImpl) vb.getCurrentModule()).setVirtualModule(vm);
@@ -3910,6 +3908,8 @@ ex.printStackTrace();
         {
             // Reset the bundle object and fire UNRESOLVED event.
             ((BundleImpl) bundle).refresh();
+            setBundleStateAndNotify(bundle, Bundle.INSTALLED);
+            fireBundleEvent(BundleEvent.UNRESOLVED, bundle);
         }
         catch (Exception ex)
         {

Modified: felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java?rev=962650&r1=962649&r2=962650&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
(original)
+++ felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
Fri Jul  9 19:22:38 2010
@@ -21,27 +21,14 @@ package org.apache.felix.framework;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
-import org.apache.felix.framework.Felix.FelixResolver;
-import org.apache.felix.framework.capabilityset.Capability;
-import org.apache.felix.framework.capabilityset.Requirement;
 import org.apache.felix.framework.ext.Wire;
 import org.apache.felix.framework.ext.VirtualModule;
 import org.apache.felix.framework.resolver.Content;
-import org.apache.felix.framework.resolver.Module;
-import org.apache.felix.framework.resolver.ResolverWire;
-import org.apache.felix.framework.util.SecureAction;
-import org.apache.felix.framework.util.manifestparser.CapabilityImpl;
-import org.apache.felix.framework.util.manifestparser.R4Library;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleException;
-import org.osgi.framework.Version;
 
 public class UnmanagedModuleImpl extends AbstractModuleImpl
 {
@@ -63,8 +50,16 @@ public class UnmanagedModuleImpl extends
     }
 
     public synchronized void setVirtualModule(VirtualModule vm)
+        throws BundleException
     {
-        m_vm = vm;
+        if (m_vm == null)
+        {
+            m_vm = vm;
+        }
+        else
+        {
+            throw new BundleException("Virtual module is already set.");
+        }
     }
 
     public Content getContent()



Mime
View raw message