You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/06/07 22:40:21 UTC
svn commit: r952424 [1/3] - in /felix/sandbox/rickhall/framework-vb: ./
src/main/java/org/apache/felix/framework/
src/main/java/org/apache/felix/framework/ext/
src/main/java/org/apache/felix/framework/resolver/
src/main/java/org/apache/felix/framework/...
Author: rickhall
Date: Mon Jun 7 20:40:20 2010
New Revision: 952424
URL: http://svn.apache.org/viewvc?rev=952424&view=rev
Log:
Merge branch 'moduleimpl'
Added:
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/VirtualContentImpl.java
- copied, changed from r951014, felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ModuleImpl.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ext/WireX.java
- copied, changed from r951014, felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ext/Wire.java
Removed:
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ext/Wire.java
felix/sandbox/rickhall/framework-vb/src/test/java/org/apache/felix/framework/BootLoaderTest.java
Modified:
felix/sandbox/rickhall/framework-vb/pom.xml
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ExtensionManager.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/FelixResolverState.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ModuleImpl.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ext/VirtualContent.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/resolver/Module.java
felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/util/FelixConstants.java
Modified: felix/sandbox/rickhall/framework-vb/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb/pom.xml?rev=952424&r1=952423&r2=952424&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-vb/pom.xml (original)
+++ felix/sandbox/rickhall/framework-vb/pom.xml Mon Jun 7 20:40:20 2010
@@ -27,7 +27,7 @@
<packaging>bundle</packaging>
<name>Apache Felix Framework</name>
<artifactId>org.apache.felix.framework</artifactId>
- <version>2.1.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<dependencies>
</dependencies>
<properties>
Modified: felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java?rev=952424&r1=952423&r2=952424&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java (original)
+++ felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java Mon Jun 7 20:40:20 2010
@@ -26,7 +26,7 @@ import org.apache.felix.framework.resolv
class EntryFilterEnumeration implements Enumeration
{
- private final BundleImpl m_bundle;
+ private final Module m_module;
private final List<Enumeration> m_enumerations;
private final List<Module> m_modules;
private int m_moduleIndex = 0;
@@ -38,12 +38,11 @@ class EntryFilterEnumeration implements
private final List<Object> m_nextEntries = new ArrayList(2);
public EntryFilterEnumeration(
- BundleImpl bundle, boolean includeFragments, String path,
+ Module module, boolean includeFragments, String path,
String filePattern, boolean recurse, boolean isURLValues)
{
- m_bundle = bundle;
- Module bundleModule = m_bundle.getCurrentModule();
- List<Module> fragmentModules = ((ModuleImpl) bundleModule).getFragments();
+ m_module = module;
+ List<Module> fragmentModules = ((ModuleImpl) m_module).getFragments();
if (includeFragments && (fragmentModules != null))
{
m_modules = new ArrayList(fragmentModules.size() + 1);
@@ -53,12 +52,14 @@ class EntryFilterEnumeration implements
{
m_modules = new ArrayList(1);
}
- m_modules.add(0, bundleModule);
+ m_modules.add(0, m_module);
m_enumerations = new ArrayList(m_modules.size());
for (int i = 0; i < m_modules.size(); i++)
{
- m_enumerations.add(m_modules.get(i).getContent() != null ?
- m_modules.get(i).getContent().getEntries() : null);
+ VirtualContentImpl vc =
+ (VirtualContentImpl) m_modules.get(i).getVirtualContent();
+ m_enumerations.add(
+ (vc.getContent() != null) ? vc.getContent().getEntries() : null);
}
m_recurse = recurse;
m_isURLValues = isURLValues;
@@ -90,12 +91,12 @@ class EntryFilterEnumeration implements
public synchronized boolean hasMoreElements()
{
- return (m_nextEntries.size() != 0);
+ return (!m_nextEntries.isEmpty());
}
public synchronized Object nextElement()
{
- if (m_nextEntries.size() == 0)
+ if (m_nextEntries.isEmpty())
{
throw new NoSuchElementException("No more entries.");
}
@@ -114,11 +115,11 @@ class EntryFilterEnumeration implements
{
return;
}
- while ((m_moduleIndex < m_enumerations.size()) && (m_nextEntries.size() == 0))
+ while ((m_moduleIndex < m_enumerations.size()) && (m_nextEntries.isEmpty()))
{
while (m_enumerations.get(m_moduleIndex) != null
&& m_enumerations.get(m_moduleIndex).hasMoreElements()
- && m_nextEntries.size() == 0)
+ && m_nextEntries.isEmpty())
{
// Get the current entry to determine if it should be filtered or not.
String entryName = (String) m_enumerations.get(m_moduleIndex).nextElement();
@@ -219,7 +220,7 @@ class EntryFilterEnumeration implements
}
}
}
- if (m_nextEntries.size() == 0)
+ if (m_nextEntries.isEmpty())
{
m_moduleIndex++;
}
Modified: felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ExtensionManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ExtensionManager.java?rev=952424&r1=952423&r2=952424&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ExtensionManager.java (original)
+++ felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/ExtensionManager.java Mon Jun 7 20:40:20 2010
@@ -20,7 +20,6 @@ package org.apache.felix.framework;
import java.io.IOException;
import java.net.InetAddress;
-import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
@@ -33,13 +32,13 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Set;
import org.apache.felix.framework.Felix.FelixResolver;
import org.apache.felix.framework.capabilityset.Attribute;
import org.apache.felix.framework.capabilityset.Capability;
import org.apache.felix.framework.capabilityset.Directive;
+import org.apache.felix.framework.ext.VirtualContent;
import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.StringMap;
@@ -47,6 +46,7 @@ import org.apache.felix.framework.util.U
import org.apache.felix.framework.util.manifestparser.CapabilityImpl;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
import org.apache.felix.framework.resolver.Content;
+import org.apache.felix.framework.resolver.Wire;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
@@ -78,7 +78,7 @@ import org.osgi.framework.Version;
// with the parent classloader and one instance per framework instance that
// keeps track of extension bundles and systembundle exports for that framework
// instance.
-class ExtensionManager extends URLStreamHandler implements Content
+class ExtensionManager extends URLStreamHandler implements VirtualContent
{
// The private instance that is added to Felix.class.getClassLoader() -
// will be null if extension bundles are not supported (i.e., we are not
@@ -475,7 +475,9 @@ class ExtensionManager extends URLStream
{
try
{
- result = ((ModuleImpl) ((BundleImpl) extBundle).getCurrentModule()).getResourceLocal(path);
+ result = ((VirtualContentImpl)
+ ((BundleImpl) extBundle).getCurrentModule()
+ .getVirtualContent()).getResourceLocal(path);
}
catch (Exception ex)
{
@@ -545,47 +547,95 @@ class ExtensionManager extends URLStream
}
}
- public void close()
+ //
+ // VirtualContent methods.
+ //
+
+ public void resolve(List<Wire> wires) throws BundleException
{
- // Do nothing on close, since we have nothing open.
+
}
- public Enumeration getEntries()
+ public BundleActivator getActivator()
{
- return new Enumeration()
+ return null;
+ }
+
+ public Class loadClass(String name) throws ClassNotFoundException
+ {
+ Class clazz = null;
+ String pkgName = Util.getClassPackage(name);
+// TODO: VB - System bundle boot delegation is now broken since it the info
+// it needs have been moved to VirtualContentImpl.
+/*
+ if (VirtualContentImpl.shouldBootDelegate(bootPkgs, wildcards, pkgName))
{
- public boolean hasMoreElements()
+ try
{
- return false;
+ // Get the appropriate class loader for delegation.
+ ClassLoader bdcl = getBootDelegationClassLoader();
+ clazz = bdcl.loadClass(name);
+ // If this is a java.* package, then always terminate the
+ // search; otherwise, continue to look locally if not found.
+ if (pkgName.startsWith("java.") || (clazz != null))
+ {
+ return clazz;
+ }
}
-
- public Object nextElement() throws NoSuchElementException
+ catch (ClassNotFoundException ex)
+ {
+ // If this is a java.* package, then always terminate the
+ // search; otherwise, continue to look locally if not found.
+ if (pkgName.startsWith("java."))
+ {
+ throw ex;
+ }
+ }
+ }
+*/
+ if (clazz == null)
+ {
+ synchronized (ExtensionManager.this)
{
- throw new NoSuchElementException();
+ if (!m_exportNames.contains(Util.getClassPackage(name)))
+ {
+ throw new ClassNotFoundException(name);
+ }
}
- };
+
+ clazz = getClass().getClassLoader().loadClass(name);
+ }
+ return clazz;
}
- public boolean hasEntry(String name) {
- return false;
+ public URL getResource(String name)
+ {
+ return getClass().getClassLoader().getResource(name);
}
- public byte[] getEntryAsBytes(String name)
+ public Enumeration getResources(String name)
{
- return null;
+ try
+ {
+ return getClass().getClassLoader().getResources(name);
+ }
+ catch (IOException ex)
+ {
+ return null;
+ }
}
- public InputStream getEntryAsStream(String name) throws IOException
+ public URL getEntry(String entry)
{
return null;
}
- public Content getEntryAsContent(String name)
+ public Enumeration<String> getEntryPaths(String path)
{
return null;
}
- public String getEntryAsNativeLibrary(String name)
+ public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse)
{
return null;
}
@@ -633,62 +683,17 @@ class ExtensionManager extends URLStream
public Class getClassByDelegation(String name) throws ClassNotFoundException
{
- Class clazz = null;
- String pkgName = Util.getClassPackage(name);
- if (shouldBootDelegate(pkgName))
- {
- try
- {
- // Get the appropriate class loader for delegation.
- ClassLoader bdcl = getBootDelegationClassLoader();
- clazz = bdcl.loadClass(name);
- // If this is a java.* package, then always terminate the
- // search; otherwise, continue to look locally if not found.
- if (pkgName.startsWith("java.") || (clazz != null))
- {
- return clazz;
- }
- }
- catch (ClassNotFoundException ex)
- {
- // If this is a java.* package, then always terminate the
- // search; otherwise, continue to look locally if not found.
- if (pkgName.startsWith("java."))
- {
- throw ex;
- }
- }
- }
- if (clazz == null)
- {
- synchronized (ExtensionManager.this)
- {
- if (!m_exportNames.contains(Util.getClassPackage(name)))
- {
- throw new ClassNotFoundException(name);
- }
- }
-
- clazz = getClass().getClassLoader().loadClass(name);
- }
- return clazz;
+ return loadClass(name);
}
public URL getResourceByDelegation(String name)
{
- return getClass().getClassLoader().getResource(name);
+ return getResource(name);
}
public Enumeration getResourcesByDelegation(String name)
{
- try
- {
- return getClass().getClassLoader().getResources(name);
- }
- catch (IOException ex)
- {
- return null;
- }
+ return getResourcesByDelegation(name);
}
public Logger getLogger()
@@ -717,7 +722,7 @@ class ExtensionManager extends URLStream
// Nothing needed here.
}
- public Content getContent()
+ public VirtualContent getVirtualContent()
{
return ExtensionManager.this;
}
@@ -727,15 +732,5 @@ class ExtensionManager extends URLStream
// There is no content for the system bundle, so return null.
return null;
}
-
- public boolean hasInputStream(int index, String urlPath)
- {
- return (getClass().getClassLoader().getResource(urlPath) != null);
- }
-
- public InputStream getInputStream(int index, String urlPath)
- {
- return getClass().getClassLoader().getResourceAsStream(urlPath);
- }
}
}
Modified: felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/Felix.java?rev=952424&r1=952423&r2=952424&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/Felix.java Mon Jun 7 20:40:20 2010
@@ -1477,7 +1477,8 @@ ex.printStackTrace();
// Use the entry filter enumeration to search the bundle content
// recursively for matching entries and return URLs to them.
Enumeration enumeration =
- new EntryFilterEnumeration(bundle, false, name, "*", true, true);
+ new EntryFilterEnumeration(
+ bundle.getCurrentModule(), false, name, "*", true, true);
// If the enumeration has elements, then that means we need
// to synthesize the directory entry.
if (enumeration.hasMoreElements())
@@ -1509,7 +1510,8 @@ ex.printStackTrace();
// Get the entry enumeration from the module content and
// create a wrapper enumeration to filter it.
Enumeration enumeration =
- new EntryFilterEnumeration(bundle, false, path, "*", false, false);
+ new EntryFilterEnumeration(
+ bundle.getCurrentModule(), false, path, "*", false, false);
// Return the enumeration if it has elements.
return (!enumeration.hasMoreElements()) ? null : enumeration;
@@ -1527,7 +1529,8 @@ ex.printStackTrace();
// Get the entry enumeration from the module content and
// create a wrapper enumeration to filter it.
Enumeration enumeration =
- new EntryFilterEnumeration(bundle, true, path, filePattern, recurse, true);
+ new EntryFilterEnumeration(
+ bundle.getCurrentModule(), true, path, filePattern, recurse, true);
// Return the enumeration if it has elements.
return (!enumeration.hasMoreElements()) ? null : enumeration;
@@ -4027,12 +4030,13 @@ ex.printStackTrace();
// dynamically importing the package, which can happen if two
// threads are racing to do so. If we have an existing wire,
// then just return it instead.
- List<Wire> wires = module.getWires();
- for (int i = 0; (wires != null) && (i < wires.size()); i++)
+ List<Wire> oldWires = module.getWires();
+ List<Wire> newWires = oldWires;
+ for (int i = 0; (oldWires != null) && (i < oldWires.size()); i++)
{
- if (wires.get(i).hasPackage(pkgName))
+ if (oldWires.get(i).hasPackage(pkgName))
{
- return wires.get(i);
+ return oldWires.get(i);
}
}
@@ -4044,17 +4048,32 @@ ex.printStackTrace();
List<Wire> dynamicWires = wireMap.remove(module);
candidateWire = dynamicWires.get(0);
+ // First verify we can inject dynamic wire.
+ if (candidateWire != null)
+ {
+ newWires = new ArrayList(oldWires.size() + 1);
+ newWires.addAll(oldWires);
+ newWires.add(candidateWire);
+ ((ModuleImpl) module).resolve(newWires);
+ }
+
// Mark all modules as resolved.
- markResolvedModules(wireMap);
+ try
+ {
+ markResolvedModules(wireMap);
+ }
+ catch (ResolveException ex)
+ {
+ // If we couldn't resolve all dependent modules then
+ // revert to our old wires.
+ ((ModuleImpl) module).resolve(oldWires);
+ throw ex;
+ }
- // Dynamically add new wire to importing module.
+ // Print wire for debugging purposes.
if (candidateWire != null)
{
- wires = new ArrayList(wires.size() + 1);
- wires.addAll(module.getWires());
- wires.add(candidateWire);
- ((ModuleImpl) module).setWires(wires);
-m_logger.log(Logger.LOG_DEBUG, "DYNAMIC WIRE: " + wires.get(wires.size() - 1));
+m_logger.log(Logger.LOG_DEBUG, "DYNAMIC WIRE: " + newWires.get(newWires.size() - 1));
}
}
}
@@ -4134,18 +4153,45 @@ m_logger.log(Logger.LOG_DEBUG, "DYNAMIC
}
private void markResolvedModules(Map<Module, List<Wire>> wireMap)
+ throws ResolveException
{
if (wireMap != null)
{
Iterator<Entry<Module, List<Wire>>> iter = wireMap.entrySet().iterator();
- // Iterate over the map to mark the modules as resolved and
- // update our resolver data structures.
+ List<Module> resolved = new ArrayList<Module>();
+
+ // We need to mark the modules resolved in two passes since
+ // during the first pass the virtual content may throw an
+ // exception. In the first pass, we inject the wires into
+ // each module, in the second pass we set its state to resolved.
+
+ // First pass.
while (iter.hasNext())
{
Entry<Module, List<Wire>> entry = iter.next();
Module module = entry.getKey();
List<Wire> wires = entry.getValue();
+ try
+ {
+ ((ModuleImpl) module).resolve(wires);
+ resolved.add(module);
+ }
+ catch (ResolveException ex)
+ {
+ for (Module m : resolved)
+ {
+ ((ModuleImpl) module).resolve(null);
+ }
+ throw ex;
+ }
+ }
+
+ // Second pass.
+ for (Module m : resolved)
+ {
+ List<Wire> wires = m.getWires();
+
// Only add wires attribute if some exist; export
// only modules may not have wires.
for (int wireIdx = 0; wireIdx < wires.size(); wireIdx++)
@@ -4154,10 +4200,9 @@ m_logger.log(Logger.LOG_DEBUG, "DYNAMIC
Logger.LOG_DEBUG,
"WIRE: " + wires.get(wireIdx));
}
- ((ModuleImpl) module).setWires(wires);
// Resolve all attached fragments.
- List<Module> fragments = ((ModuleImpl) module).getFragments();
+ List<Module> fragments = ((ModuleImpl) m).getFragments();
for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
{
((ModuleImpl) fragments.get(i)).setResolved();
@@ -4165,13 +4210,13 @@ m_logger.log(Logger.LOG_DEBUG, "DYNAMIC
markBundleResolved(fragments.get(i));
m_logger.log(
Logger.LOG_DEBUG,
- "FRAGMENT WIRE: " + fragments.get(i) + " -> hosted by -> " + module);
+ "FRAGMENT WIRE: " + fragments.get(i) + " -> hosted by -> " + m);
}
// Update the resolver state to show the module as resolved.
- ((ModuleImpl) module).setResolved();
- m_resolverState.moduleResolved(module);
+ ((ModuleImpl) m).setResolved();
+ m_resolverState.moduleResolved(m);
// Update the state of the module's bundle to resolved as well.
- markBundleResolved(module);
+ markBundleResolved(m);
}
}
}
Modified: felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/FelixResolverState.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/FelixResolverState.java?rev=952424&r1=952423&r2=952424&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/FelixResolverState.java (original)
+++ felix/sandbox/rickhall/framework-vb/src/main/java/org/apache/felix/framework/FelixResolverState.java Mon Jun 7 20:40:20 2010
@@ -542,7 +542,7 @@ public class FelixResolverState implemen
}
// Set wires to null, which will remove the module from all
// of its dependent modules.
- ((ModuleImpl) host).setWires(null);
+ ((ModuleImpl) host).resolve(null);
}
private List<Module> getMatchingFragments(Module host)
@@ -819,7 +819,8 @@ public class FelixResolverState implemen
String entryName = libs.get(libIdx).getEntryName();
if (entryName != null)
{
- if (!module.getContent().hasEntry(entryName))
+ if (!((VirtualContentImpl) module.getVirtualContent())
+ .getContent().hasEntry(entryName))
{
msg = "Native library does not exist: " + entryName;
}