Author: rickhall
Date: Sat Jun 12 03:02:09 2010
New Revision: 953931

URL: http://svn.apache.org/viewvc?rev=953931&view=rev
Log:
Prepare to track virtual bundle dependencies and support caching and
reloading virtual bundle headers.

Modified:
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/AbstractModuleImpl.java
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/BundleImpl.java
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/Felix.java
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/VirtualRevision.java
    
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/resolver/Module.java

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/AbstractModuleImpl.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/AbstractModuleImpl.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/AbstractModuleImpl.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/AbstractModuleImpl.java
 Sat Jun 12 03:02:09 2010
@@ -68,6 +68,7 @@ abstract class AbstractModuleImpl implem
     private List<Module> m_dependentHosts = new ArrayList<Module>(0);
     private List<Module> m_dependentImporters = new ArrayList<Module>(0);
     private List<Module> m_dependentRequirers = new ArrayList<Module>(0);
+    private List<Module> m_dependentVirtuals = new ArrayList<Module>(0);
     private volatile boolean m_isResolved = false;
 
     private ProtectionDomain m_protectionDomain = null;
@@ -232,6 +233,11 @@ abstract class AbstractModuleImpl implem
         }
     }
 
+    public boolean isResolvable()
+    {
+        return m_isResolved;
+    }
+
     public boolean isResolved()
     {
         return m_isResolved;
@@ -246,12 +252,12 @@ abstract class AbstractModuleImpl implem
     // Dependency management methods.
     //
 
-    public synchronized List<Module> getDependentHosts()
+    synchronized List<Module> getDependentHosts()
     {
         return m_dependentHosts;
     }
 
-    public synchronized void addDependentHost(Module module)
+    synchronized void addDependentHost(Module module)
     {
         if (!m_dependentHosts.contains(module))
         {
@@ -259,17 +265,17 @@ abstract class AbstractModuleImpl implem
         }
     }
 
-    public synchronized void removeDependentHost(Module module)
+    synchronized void removeDependentHost(Module module)
     {
         m_dependentHosts.remove(module);
     }
 
-    public synchronized List<Module> getDependentImporters()
+    synchronized List<Module> getDependentImporters()
     {
         return m_dependentImporters;
     }
 
-    public synchronized void addDependentImporter(Module module)
+    private synchronized void addDependentImporter(Module module)
     {
         if (!m_dependentImporters.contains(module))
         {
@@ -277,17 +283,17 @@ abstract class AbstractModuleImpl implem
         }
     }
 
-    public synchronized void removeDependentImporter(Module module)
+    private synchronized void removeDependentImporter(Module module)
     {
         m_dependentImporters.remove(module);
     }
 
-    public synchronized List<Module> getDependentRequirers()
+    synchronized List<Module> getDependentRequirers()
     {
         return m_dependentRequirers;
     }
 
-    public synchronized void addDependentRequirer(Module module)
+    private synchronized void addDependentRequirer(Module module)
     {
         if (!m_dependentRequirers.contains(module))
         {
@@ -295,18 +301,38 @@ abstract class AbstractModuleImpl implem
         }
     }
 
-    public synchronized void removeDependentRequirer(Module module)
+    private synchronized void removeDependentRequirer(Module module)
     {
         m_dependentRequirers.remove(module);
     }
 
+    private synchronized List<Module> getDependentVirtual()
+    {
+        return m_dependentVirtuals;
+    }
+
+    synchronized void addDependentVirtual(Module module)
+    {
+        if (!m_dependentVirtuals.contains(module))
+        {
+            m_dependentVirtuals.add(module);
+        }
+    }
+
+    synchronized void removeDependentVirtual(Module module)
+    {
+        m_dependentVirtuals.remove(module);
+    }
+
     public synchronized List<Module> getDependents()
     {
         List<Module> dependents = new ArrayList<Module>
-            (m_dependentHosts.size() + m_dependentImporters.size() + 
m_dependentRequirers.size());
+            (m_dependentHosts.size() + m_dependentImporters.size()
+            + m_dependentRequirers.size() + m_dependentVirtuals.size());
         dependents.addAll(m_dependentHosts);
         dependents.addAll(m_dependentImporters);
         dependents.addAll(m_dependentRequirers);
+        dependents.addAll(m_dependentVirtuals);
         return dependents;
     }
 

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/BundleImpl.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/BundleImpl.java
 Sat Jun 12 03:02:09 2010
@@ -1172,8 +1172,7 @@ class BundleImpl implements Bundle
                 if (id != getBundleId())
                 {
                     String sym = bundles[i].getSymbolicName();
-                    Version ver = ((ModuleImpl)
-                        ((BundleImpl) 
bundles[i]).getCurrentModule()).getVersion();
+                    Version ver = ((BundleImpl) 
bundles[i]).getCurrentModule().getVersion();
                     if ((symName != null) && (sym != null) && 
symName.equals(sym) && bundleVersion.equals(ver))
                     {
                         throw new BundleException(

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/Felix.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/Felix.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/Felix.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/Felix.java
 Sat Jun 12 03:02:09 2010
@@ -177,6 +177,9 @@ public class Felix extends BundleImpl im
     // Security Manager created by the framework
     private SecurityManager m_securityManager = null;
 
+    // TODO: VB - Fix this hack to track dependencies.
+    private final Map<Bundle, List<Bundle>> m_vbDeps = new HashMap<Bundle, 
List<Bundle>>();
+
     /**
      * <p>
      * This constructor creates a framework instance with a specified 
<tt>Map</tt>

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/UnmanagedModuleImpl.java
 Sat Jun 12 03:02:09 2010
@@ -67,10 +67,19 @@ public class UnmanagedModuleImpl extends
     }
 
     @Override
+    public boolean isResolvable()
+    {
+        return (m_vm != null);
+    }
+
+    @Override
     public synchronized void resolve(List<VBWire> wires)
         throws BundleException
     {
-        m_vm.resolve(wires);
+        if (m_vm != null)
+        {
+            m_vm.resolve(wires);
+        }
         super.resolve(wires);
     }
 

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/BundleArchive.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
 Sat Jun 12 03:02:09 2010
@@ -1018,6 +1018,15 @@ public class BundleArchive
         File revisionRootDir = new File(m_archiveRootDir,
             REVISION_DIRECTORY + getRefreshCount() + "." + getRevisionCount());
 
+        // Check if this is a virtual bundle.
+// TODO: VB - Fix this hack.
+        File headerFile = new File(revisionRootDir, 
VirtualRevision.HEADERS_FILE);
+        if (headerFile.exists())
+        {
+            return new VirtualRevision(m_logger, m_configMap, revisionRootDir, 
location);
+        }
+
+        // Otherwise, figure out the revision from the locaiton.
         BundleRevision result = null;
 
         try

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/VirtualRevision.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/VirtualRevision.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/VirtualRevision.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/cache/VirtualRevision.java
 Sat Jun 12 03:02:09 2010
@@ -18,23 +18,28 @@
  */
 package org.apache.felix.framework.cache;
 
+import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.resolver.Content;
+import org.apache.felix.framework.util.StringMap;
 
 public class VirtualRevision extends BundleRevision
 {
-    private static final String HEADERS_FILE = "headers.map";
+    static final String HEADERS_FILE = "headers.map";
 
-    private final Map m_headers;
+    private final Map<String, String> m_headers;
 
     public VirtualRevision(
         Logger logger, Map configMap, File revisionRootDir,
-        String location, Map headers)
+        String location, Map<String, String> headers)
         throws Exception
     {
         super(logger, configMap, revisionRootDir, location);
@@ -43,32 +48,85 @@ public class VirtualRevision extends Bun
         initialize();
 
         File headerFile = new File(revisionRootDir, HEADERS_FILE);
+        saveHeaders(headerFile, m_headers);
+    }
+
+    public VirtualRevision(
+        Logger logger, Map configMap, File revisionRootDir, String location)
+        throws Exception
+    {
+        super(logger, configMap, revisionRootDir, location);
+        File headerFile = new File(revisionRootDir, HEADERS_FILE);
+        m_headers = loadHeaders(headerFile);
+    }
+
+    @Override
+    public Map getManifestHeader() throws Exception
+    {
+        return m_headers;
+    }
+
+    @Override
+    public Content getContent() throws Exception
+    {
+        return null;
+    }
+
+    @Override
+    protected void close() throws Exception
+    {
+    }
+
+    private void initialize() throws IOException
+    {
+        // If the revision directory does not exist, then create it.
+        if (!BundleCache.getSecureAction().fileExists(getRevisionRootDir()))
+        {
+            if (!BundleCache.getSecureAction().mkdir(getRevisionRootDir()))
+            {
+                getLogger().log(
+                    Logger.LOG_ERROR,
+                    getClass().getName() + ": Unable to create revision 
directory.");
+                throw new IOException("Unable to create archive directory.");
+            }
+        }
+    }
+
+    private static void saveHeaders(File file, Map<String, String> headers)
+        throws IOException
+    {
         FileWriter fw = null;
         BufferedWriter bw = null;
         try
         {
-            fw = new FileWriter(headerFile);
+            fw = new FileWriter(file);
             bw = new BufferedWriter(fw);
-            bw.write(headers.toString());
+            for (Entry<String, String> entry : headers.entrySet())
+            {
+                bw.write(entry.getKey());
+                bw.newLine();
+                bw.write(entry.getValue());
+                bw.newLine();
+            }
         }
         finally
         {
-            if (fw != null)
+            if (bw != null)
             {
                 try
                 {
-                    fw.close();
+                    bw.close();
                 }
                 catch (IOException ex)
                 {
                     // Not much we can do.
                 }
             }
-            if (bw != null)
+            if (fw != null)
             {
                 try
                 {
-                    bw.close();
+                    fw.close();
                 }
                 catch (IOException ex)
                 {
@@ -78,35 +136,53 @@ public class VirtualRevision extends Bun
         }
     }
 
-    @Override
-    public Map getManifestHeader() throws Exception
+    private static Map<String, String> loadHeaders(File file)
+        throws IOException
     {
-        return m_headers;
-    }
-
-    @Override
-    public Content getContent() throws Exception
-    {
-        return null;
-    }
-
-    @Override
-    protected void close() throws Exception
-    {
-    }
-
-    private void initialize() throws IOException
-    {
-        // If the revision directory does not exist, then create it.
-        if (!BundleCache.getSecureAction().fileExists(getRevisionRootDir()))
+        Map<String, String> headers = (Map<String, String>) new 
StringMap(false);
+        FileReader fr = null;
+        BufferedReader br = null;
+        try
         {
-            if (!BundleCache.getSecureAction().mkdir(getRevisionRootDir()))
+            fr = new FileReader(file);
+            br = new BufferedReader(fr);
+            String key, value;
+            do
             {
-                getLogger().log(
-                    Logger.LOG_ERROR,
-                    getClass().getName() + ": Unable to create revision 
directory.");
-                throw new IOException("Unable to create archive directory.");
+                key = br.readLine();
+                value = br.readLine();
+                if (key != null)
+                {
+                    headers.put(key, value);
+                }
+            }
+            while (key != null);
+        }
+        finally
+        {
+            if (br != null)
+            {
+                try
+                {
+                    br.close();
+                }
+                catch (IOException ex)
+                {
+                    // Not much we can do.
+                }
+            }
+            if (fr != null)
+            {
+                try
+                {
+                    fr.close();
+                }
+                catch (IOException ex)
+                {
+                    // Not much we can do.
+                }
             }
         }
+        return headers;
     }
 }
\ No newline at end of file

Modified: 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/resolver/Module.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/resolver/Module.java?rev=953931&r1=953930&r2=953931&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/resolver/Module.java
 (original)
+++ 
felix/sandbox/rickhall/framework-vb-2/src/main/java/org/apache/felix/framework/resolver/Module.java
 Sat Jun 12 03:02:09 2010
@@ -55,6 +55,7 @@ public interface Module extends VirtualM
     List<VBWire> getWires();
     void resolve(List<VBWire> wires) throws BundleException;
     boolean isResolved();
+    boolean isResolvable();
     Object getSecurityContext();
 
     // Content access methods.


Reply via email to