Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-09-26 04:26:13 -0400
committerJan Bartel2013-09-29 23:27:05 -0400
commit04002898263b3d408f7f4851906dfcb7185902ee (patch)
tree47886b39b850fb96f7c1a5872eb964556590001b /jetty-osgi/jetty-osgi-boot/src
parent0fd656dcbe0102c7e9deecaac9ac4de1a5016c62 (diff)
downloadorg.eclipse.jetty.project-04002898263b3d408f7f4851906dfcb7185902ee.tar.gz
org.eclipse.jetty.project-04002898263b3d408f7f4851906dfcb7185902ee.tar.xz
org.eclipse.jetty.project-04002898263b3d408f7f4851906dfcb7185902ee.zip
417561 Refactor annotation related code - make annotation phase able to be multithreaded
Diffstat (limited to 'jetty-osgi/jetty-osgi-boot/src')
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java64
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java36
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java15
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java2
4 files changed, 78 insertions, 39 deletions
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java
index e5d2d2cf13..d70d1ea797 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java
@@ -18,7 +18,10 @@
package org.eclipse.jetty.osgi.annotations;
-import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jetty.annotations.AnnotationParser.Handler;
import org.eclipse.jetty.annotations.ClassNameResolver;
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
@@ -34,7 +37,27 @@ import org.osgi.framework.Constants;
*/
public class AnnotationConfiguration extends org.eclipse.jetty.annotations.AnnotationConfiguration
{
+ public class BundleParserTask extends ParserTask
+ {
+
+ public BundleParserTask (AnnotationParser parser, Set<? extends Handler>handlers, Resource resource, ClassNameResolver resolver)
+ {
+ super(parser, handlers, resource, resolver);
+ }
+ public Void call() throws Exception
+ {
+ if (_parser != null)
+ {
+ org.eclipse.jetty.osgi.annotations.AnnotationParser osgiAnnotationParser = (org.eclipse.jetty.osgi.annotations.AnnotationParser)_parser;
+ Bundle bundle = osgiAnnotationParser.getBundle(_resource);
+ osgiAnnotationParser.parse(_handlers, bundle, _resolver);
+ }
+ return null;
+ }
+ }
+
+
/**
* This parser scans the bundles using the OSGi APIs instead of assuming a jar.
*/
@@ -64,7 +87,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
Bundle[] fragAndRequiredBundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles(webbundle);
if (fragAndRequiredBundles != null)
{
- //index:
+ //index and scan fragments
for (Bundle bundle : fragAndRequiredBundles)
{
Resource bundleRes = oparser.indexBundle(bundle);
@@ -72,19 +95,16 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
{
context.getMetaData().addWebInfJar(bundleRes);
}
- }
-
- //scan the fragments
- for (Bundle fragmentBundle : fragAndRequiredBundles)
- {
- if (fragmentBundle.getHeaders().get(Constants.FRAGMENT_HOST) != null)
+
+ if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null)
{
//a fragment indeed:
- parseFragmentBundle(context,oparser,webbundle,fragmentBundle);
+ parseFragmentBundle(context,oparser,webbundle,bundle);
}
}
}
//scan ourselves
+ oparser.indexBundle(webbundle);
parseWebBundle(context,oparser,webbundle);
//scan the WEB-INF/lib
@@ -146,17 +166,21 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
}
protected void parseBundle(WebAppContext context, AnnotationParser parser,
- Bundle webbundle, Bundle bundle) throws Exception
- {
-
- Resource bundleRes = parser.getResource(bundle);
-
- parser.clearHandlers();
- parser.registerHandlers(_discoverableAnnotationHandlers);
- parser.registerHandler(_classInheritanceHandler);
- parser.registerHandlers(_containerInitializerAnnotationHandlers);
-
- parser.parse(bundle,createClassNameResolver(context));
+ Bundle webbundle, Bundle bundle) throws Exception
+ {
+
+ Resource bundleRes = parser.getResource(bundle);
+ Set<Handler> handlers = new HashSet<Handler>();
+ handlers.addAll(_discoverableAnnotationHandlers);
+ if (_classInheritanceHandler != null)
+ handlers.add(_classInheritanceHandler);
+ handlers.addAll(_containerInitializerAnnotationHandlers);
+
+ ClassNameResolver classNameResolver = createClassNameResolver(context);
+ if (_parserTasks != null)
+ _parserTasks.add(new BundleParserTask(parser, handlers, bundleRes, classNameResolver));
+ else
+ parser.parse(handlers, bundle, classNameResolver);
}
/**
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java
index c2c14e3ed7..e502435dac 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java
@@ -29,9 +29,11 @@ import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.annotations.ClassNameResolver;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
+import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.resource.Resource;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
@@ -41,11 +43,12 @@ import org.osgi.framework.Constants;
*/
public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationParser
{
- private Set<URI> _alreadyParsed = new HashSet<URI>();
+ private Set<URI> _alreadyParsed = new ConcurrentHashSet<URI>();
- private Map<URI,Bundle> _uriToBundle = new HashMap<URI, Bundle>();
- private Map<Bundle,Resource> _resourceToBundle = new HashMap<Bundle,Resource>();
- private Map<Bundle,URI> _bundleToUri = new HashMap<Bundle, URI>();
+ private ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<URI, Bundle>();
+ private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<Bundle,Resource>();
+ private ConcurrentHashMap<Resource, Bundle> _resourceToBundle = new ConcurrentHashMap<Resource, Bundle>();
+ private ConcurrentHashMap<Bundle,URI> _bundleToUri = new ConcurrentHashMap<Bundle, URI>();
/**
* Keep track of a jetty URI Resource and its associated OSGi bundle.
@@ -58,9 +61,10 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
File bundleFile = BundleFileLocatorHelper.DEFAULT.getBundleInstallLocation(bundle);
Resource resource = Resource.newResource(bundleFile.toURI());
URI uri = resource.getURI();
- _uriToBundle.put(uri,bundle);
- _bundleToUri.put(bundle,uri);
- _resourceToBundle.put(bundle,resource);
+ _uriToBundle.putIfAbsent(uri,bundle);
+ _bundleToUri.putIfAbsent(bundle,uri);
+ _bundleToResource.putIfAbsent(bundle,resource);
+ _resourceToBundle.putIfAbsent(resource,bundle);
return resource;
}
protected URI getURI(Bundle bundle)
@@ -69,13 +73,19 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
}
protected Resource getResource(Bundle bundle)
{
- return _resourceToBundle.get(bundle);
+ return _bundleToResource.get(bundle);
}
+ protected Bundle getBundle (Resource resource)
+ {
+ return _resourceToBundle.get(resource);
+ }
+
+
/**
*
*/
@Override
- public void parse (URI[] uris, ClassNameResolver resolver)
+ public void parse (Set<? extends Handler> handlers, URI[] uris, ClassNameResolver resolver)
throws Exception
{
for (URI uri : uris)
@@ -89,16 +99,16 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
}
//a jar in WEB-INF/lib or the WEB-INF/classes
//use the behavior of the super class for a standard jar.
- super.parse(new URI[] {uri},resolver);
+ super.parse(handlers, new URI[] {uri},resolver);
}
else
{
- parse(associatedBundle,resolver);
+ parse(handlers, associatedBundle,resolver);
}
}
}
- protected void parse(Bundle bundle, ClassNameResolver resolver)
+ protected void parse(Set<? extends Handler> handlers, Bundle bundle, ClassNameResolver resolver)
throws Exception
{
URI uri = _bundleToUri.get(bundle);
@@ -190,7 +200,7 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
//transform into a classname to pass to the resolver
String shortName = name.replace('/', '.').substring(0,name.length()-6);
if ((resolver == null)|| (!resolver.isExcluded(shortName) && (!isParsed(shortName) || resolver.shouldOverride(shortName))))
- scanClass(getResource(bundle), classUrl.openStream());
+ scanClass(handlers, getResource(bundle), classUrl.openStream());
}
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java
index 197ee2cb2c..b47b8ac908 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java
@@ -21,7 +21,11 @@ package org.eclipse.jetty.osgi.boot;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory;
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
@@ -53,8 +57,8 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
@Override
public void preConfigure(final WebAppContext context) throws Exception
{
- List<Resource> frags = (List<Resource>) context.getAttribute(METAINF_FRAGMENTS);
- List<Resource> resfrags = (List<Resource>) context.getAttribute(METAINF_RESOURCES);
+ Map<Resource, Resource> frags = (Map<Resource, Resource>) context.getAttribute(METAINF_FRAGMENTS);
+ Set<Resource> resfrags = (Set<Resource>) context.getAttribute(METAINF_RESOURCES);
List<Resource> tldfrags = (List<Resource>) context.getAttribute(METAINF_TLDS);
Bundle[] fragments = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE));
@@ -73,10 +77,11 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
if (frags == null)
{
- frags = new ArrayList<Resource>();
+ frags = new HashMap<Resource,Resource>();
context.setAttribute(METAINF_FRAGMENTS, frags);
}
- frags.add(Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(frag).toURI()));
+ frags.put(Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(frag).toURI()),
+ Resource.newResource(webFrag));
}
if (resEnum != null && resEnum.hasMoreElements())
{
@@ -92,7 +97,7 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
if (resfrags == null)
{
- resfrags = new ArrayList<Resource>();
+ resfrags = new HashSet<Resource>();
context.setAttribute(METAINF_RESOURCES, resfrags);
}
resfrags.add(Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(resourcesEntry)));
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java
index b606db40fa..75d79a8fad 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java
@@ -212,7 +212,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
}
}
if (!appendedResourcesPath.isEmpty())
- context.setAttribute(WebInfConfiguration.RESOURCE_URLS, new ArrayList<Resource>(appendedResourcesPath.values()));
+ context.setAttribute(WebInfConfiguration.RESOURCE_DIRS, new HashSet<Resource>(appendedResourcesPath.values()));
}
}

Back to the top