camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1129601 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/management/ tests/camel-itest/src/test/java/org/apache/camel/itest/issues/
Date Tue, 31 May 2011 10:09:16 GMT
Author: davsclaus
Date: Tue May 31 10:09:16 2011
New Revision: 1129601

URL: http://svn.apache.org/viewvc?rev=1129601&view=rev
Log:
CAMEL-4009: Using JAR cache in package scan resolver to be faster when re-scanning JARs from
the cache.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheHitsTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedEndpointRegistryTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheHitsTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheTest.java
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Tue
May 31 10:09:16 2011
@@ -1420,6 +1420,7 @@ public class DefaultCamelContext extends
         addService(producerServicePool);
         addService(inflightRepository);
         addService(shutdownStrategy);
+        addService(packageScanClassResolver);
 
         startServices(components.values());
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
Tue May 31 10:09:16 2011
@@ -30,7 +30,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -45,17 +44,21 @@ import org.apache.camel.impl.scan.Compos
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.PackageScanFilter;
 import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.LRUSoftCache;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Default implement of {@link org.apache.camel.spi.PackageScanClassResolver}
  */
-public class DefaultPackageScanClassResolver implements PackageScanClassResolver {
+public class DefaultPackageScanClassResolver extends ServiceSupport implements PackageScanClassResolver
{
 
     protected final transient Logger log = LoggerFactory.getLogger(getClass());
     private final Set<ClassLoader> classLoaders = new LinkedHashSet<ClassLoader>();
+    // use a JAR cache to speed up scanning JARs, but let it be soft referenced so it can
claim the data when memory is needed
+    private final Map<String, List<String>> jarCache = new LRUSoftCache<String,
List<String>>(1000);
     private Set<PackageScanFilter> scanFilters;
     private String[] acceptableSchemes = {};
 
@@ -208,15 +211,6 @@ public class DefaultPackageScanClassReso
     }
 
     protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>>
classes) {
-        Map<String, List<String>> jarCache = new LinkedHashMap<String, List<String>>();
-
-        find(test, packageName, loader, classes, jarCache);
-
-        jarCache.clear();
-    }
-
-    protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>>
classes,
-                        Map<String, List<String>> jarCache) {
         if (log.isTraceEnabled()) {
             log.trace("Searching for: {} in package: {} using classloader: {}", 
                     new Object[]{test, packageName, loader.getClass().getName()});
@@ -275,7 +269,7 @@ public class DefaultPackageScanClassReso
                     urlPath = urlPath.substring(0, urlPath.indexOf('!'));
                 }
 
-                log.trace("Scanning for classes in [{}] matching criteria: {}", urlPath,
test);
+                log.trace("Scanning for classes in: {} matching criteria: {}", urlPath, test);
 
                 File file = new File(urlPath);
                 if (file.isDirectory()) {
@@ -398,17 +392,28 @@ public class DefaultPackageScanClassReso
         ObjectHelper.notNull(classes, "classes");
         ObjectHelper.notNull(jarCache, "jarCache");
 
-        List<String> cache = jarCache.get(urlPath);
-        if (cache == null) {
-            cache = doCacheJar(stream, urlPath);
-            jarCache.put(urlPath, cache);
-            log.debug("Cached {} JAR with {} entries", urlPath, cache.size());
+        List<String> entries = jarCache != null ? jarCache.get(urlPath) : null;
+        if (entries == null) {
+            entries = doLoadJarClassEntries(stream, urlPath);
+            if (jarCache != null) {
+                jarCache.put(urlPath, entries);
+                log.trace("Cached {} JAR with {} entries", urlPath, entries.size());
+            }
+        } else {
+            log.trace("Using cached {} JAR with {} entries", urlPath, entries.size());
         }
 
-        doLoadImplementationsInJar(test, parent, cache, classes);
+        doLoadImplementationsInJar(test, parent, entries, classes);
     }
 
-    private List<String> doCacheJar(InputStream stream, String urlPath) {
+    /**
+     * Loads all the class entries from the JAR.
+     *
+     * @param stream  the inputstream of the jar file to be examined for classes
+     * @param urlPath the url of the jar file to be examined for classes
+     * @return all the .class entries from the JAR
+     */
+    private List<String> doLoadJarClassEntries(InputStream stream, String urlPath)
{
         List<String> entries = new ArrayList<String>();
 
         JarInputStream jarStream = null;
@@ -434,6 +439,14 @@ public class DefaultPackageScanClassReso
         return entries;
     }
 
+    /**
+     * Adds all the matching implementations from from the JAR entries to the classes.
+     *
+     * @param test    a Test used to filter the classes that are discovered
+     * @param parent  the parent package under which classes must be in order to be considered
+     * @param entries the .class entries from the JAR
+     * @param classes to add found and matching classes
+     */
     private void doLoadImplementationsInJar(PackageScanFilter test, String parent, List<String>
entries, Set<Class<?>> classes) {
         for (String entry : entries) {
             if (entry.startsWith(parent)) {
@@ -471,12 +484,12 @@ public class DefaultPackageScanClassReso
                 } catch (ClassNotFoundException e) {
                     if (log.isTraceEnabled()) {
                         log.trace("Cannot find class '" + fqn + "' in classloader: " + classLoader
-                                + ". Reason: " + e, e);
+                                + ". Reason: " + e.getMessage(), e);
                     }
                 } catch (NoClassDefFoundError e) {
                     if (log.isTraceEnabled()) {
                         log.trace("Cannot find the class definition '" + fqn + "' in classloader:
" + classLoader
-                            + ". Reason: " + e, e);
+                            + ". Reason: " + e.getMessage(), e);
                     }
                 }
             }
@@ -491,4 +504,12 @@ public class DefaultPackageScanClassReso
         }
     }
 
+    protected void doStart() throws Exception {
+        ServiceHelper.startService(jarCache);
+    }
+
+    protected void doStop() throws Exception {
+        ServiceHelper.stopService(jarCache);
+    }
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
Tue May 31 10:09:16 2011
@@ -50,8 +50,8 @@ public class MultipleLifecycleStrategyTe
 
         context.stop();
 
-        assertEquals(11, dummy1.getEvents().size());
-        assertEquals(11, dummy2.getEvents().size());
+        assertEquals(12, dummy1.getEvents().size());
+        assertEquals(12, dummy2.getEvents().size());
 
         assertEquals("onContextStart", dummy1.getEvents().get(0));
         assertEquals("onContextStart", dummy2.getEvents().get(0));
@@ -67,14 +67,16 @@ public class MultipleLifecycleStrategyTe
         assertEquals("onServiceAdd", dummy2.getEvents().get(5));
         assertEquals("onServiceAdd", dummy1.getEvents().get(6));
         assertEquals("onServiceAdd", dummy2.getEvents().get(6));
-        assertEquals("onComponentAdd", dummy1.getEvents().get(7));
-        assertEquals("onComponentAdd", dummy2.getEvents().get(7));
-        assertEquals("onEndpointAdd", dummy1.getEvents().get(8));
-        assertEquals("onEndpointAdd", dummy2.getEvents().get(8));
-        assertEquals("onComponentRemove", dummy1.getEvents().get(9));
-        assertEquals("onComponentRemove", dummy2.getEvents().get(9));
-        assertEquals("onContextStop", dummy1.getEvents().get(10));
-        assertEquals("onContextStop", dummy2.getEvents().get(10));
+        assertEquals("onServiceAdd", dummy1.getEvents().get(7));
+        assertEquals("onServiceAdd", dummy2.getEvents().get(7));
+        assertEquals("onComponentAdd", dummy1.getEvents().get(8));
+        assertEquals("onComponentAdd", dummy2.getEvents().get(8));
+        assertEquals("onEndpointAdd", dummy1.getEvents().get(9));
+        assertEquals("onEndpointAdd", dummy2.getEvents().get(9));
+        assertEquals("onComponentRemove", dummy1.getEvents().get(10));
+        assertEquals("onComponentRemove", dummy2.getEvents().get(10));
+        assertEquals("onContextStop", dummy1.getEvents().get(11));
+        assertEquals("onContextStop", dummy2.getEvents().get(11));
     }
 
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheHitsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheHitsTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheHitsTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheHitsTest.java
Tue May 31 10:09:16 2011
@@ -47,7 +47,6 @@ public class ManagedConsumerCacheHitsTes
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(8, set.size());
         List<ObjectName> list = new ArrayList<ObjectName>(set);
         ObjectName on = null;
         for (ObjectName name : list) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedConsumerCacheTest.java
Tue May 31 10:09:16 2011
@@ -47,7 +47,6 @@ public class ManagedConsumerCacheTest ex
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(8, set.size());
         List<ObjectName> list = new ArrayList<ObjectName>(set);
         ObjectName on = null;
         for (ObjectName name : list) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedEndpointRegistryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedEndpointRegistryTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedEndpointRegistryTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedEndpointRegistryTest.java
Tue May 31 10:09:16 2011
@@ -39,7 +39,6 @@ public class ManagedEndpointRegistryTest
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(7, set.size());
         List<ObjectName> list = new ArrayList<ObjectName>(set);
         ObjectName on = null;
         for (ObjectName name : list) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheHitsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheHitsTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheHitsTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheHitsTest.java
Tue May 31 10:09:16 2011
@@ -41,7 +41,6 @@ public class ManagedProducerCacheHitsTes
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(7, set.size());
         List<ObjectName> list = new ArrayList<ObjectName>(set);
         ObjectName on = null;
         for (ObjectName name : list) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedProducerCacheTest.java
Tue May 31 10:09:16 2011
@@ -39,7 +39,6 @@ public class ManagedProducerCacheTest ex
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(7, set.size());
         List<ObjectName> list = new ArrayList<ObjectName>(set);
         ObjectName on = null;
         for (ObjectName name : list) {

Modified: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java?rev=1129601&r1=1129600&r2=1129601&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java
(original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java
Tue May 31 10:09:16 2011
@@ -19,20 +19,15 @@ package org.apache.camel.itest.issues;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.builder.xml.Namespaces;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
  * @version 
  */
-@Ignore
 public class JettyHttpTest extends CamelTestSupport {
 
-    // TODO: Jetty async producer needs to be implemented before this test can pass
-
     private String targetProducerUri = "http://localhost:8542/someservice?bridgeEndpoint=true&throwExceptionOnFailure=false";
     private String targetConsumerUri = "jetty:http://localhost:8542/someservice?matchOnUriPrefix=true";
     private String sourceUri = "jetty:http://localhost:6323/myservice?matchOnUriPrefix=true";
@@ -55,7 +50,6 @@ public class JettyHttpTest extends Camel
         
         template.sendBody("direct:relative", "");
         assertMockEndpointsSatisfied();
-        
     }
 
     @Override
@@ -63,7 +57,6 @@ public class JettyHttpTest extends Camel
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-
                 from(targetConsumerUri)
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
@@ -82,7 +75,6 @@ public class JettyHttpTest extends Camel
                 from("direct:relative")
                     .to(sourceProducerUri + "/relative")
                     .to("mock:result");
-
             }
         };
     }



Mime
View raw message