You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/06/30 09:45:41 UTC

svn commit: r789598 - in /camel/branches/camel-1.x: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/ components/camel-jetty/src/test/java/org/apache/camel/component/jetty/

Author: davsclaus
Date: Tue Jun 30 07:45:41 2009
New Revision: 789598

URL: http://svn.apache.org/viewvc?rev=789598&view=rev
Log:
CAMEL-1771: Using LRUCache for endpoint registry in CamelContext to avoid eating to much memory when using a lot of unique endpoints such as the http endpoints with lenient properties.

Added:
    camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java   (with props)
Modified:
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=789598&r1=789597&r2=789598&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Tue Jun 30 07:45:41 2009
@@ -58,6 +58,7 @@
 import org.apache.camel.spi.Registry;
 import org.apache.camel.util.FactoryFinder;
 import org.apache.camel.util.NoFactoryAvailableException;
+import org.apache.camel.util.LRUCache;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ReflectionInjector;
 import org.apache.camel.util.SystemHelper;
@@ -78,7 +79,7 @@
     private static int nameSuffix;
     private boolean routeDefinitionInitiated;
     private String name;
-    private final Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
+    private final Map<String, Endpoint> endpoints = new LRUCache<String, Endpoint>(1000);
     private final Map<String, Component> components = new HashMap<String, Component>();
     private List<Route> routes;
     private List<Service> servicesToClose = new ArrayList<Service>();

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java?rev=789598&r1=789597&r2=789598&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java Tue Jun 30 07:45:41 2009
@@ -189,7 +189,12 @@
         String uri = ep.getEndpointUri();
         int pos = uri.indexOf('?');
         String id = (pos == -1) ? uri : uri.substring(0, pos);
-        id += "?id=0x" + Integer.toHexString(ep.hashCode());
+
+        // if non singleton then add hashcode
+        if (!ep.isSingleton()) {
+            id += "?id=0x" + Integer.toHexString(ep.hashCode());
+        }
+
         return id;
     }
 

Added: camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java?rev=789598&view=auto
==============================================================================
--- camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java (added)
+++ camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java Tue Jun 30 07:45:41 2009
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision$
+ */
+public class HttpProducerJMXBeansIssueTest extends ContextTestSupport {
+
+private static final Log LOG = LogFactory.getLog(HttpProducerJMXBeansIssueTest.class);
+
+    @Override
+    public void setUp() throws Exception {
+        // to enable the JMX connector
+        enableJMX();
+        System.setProperty("org.apache.camel.jmx.createRmiConnector", "True");
+        super.setUp();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty:http://localhost:9080/leak").transform(constant("Bye World"));
+
+                from("direct:leak").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        LOG.debug("URL is: " + exchange.getIn().getHeader("url"));
+                    }
+                }).recipientList(header("url"));
+            }
+        };
+    }
+
+    public void testNothing() {
+        // do nothing as this test is manual
+    }
+
+    // TODO: disabled as its a manual test
+    public void xxxtestSendAlot() throws Exception {
+        Endpoint ep = context.getEndpoint("direct:leak");
+        Producer p = ep.createProducer();
+        p.start();
+
+        for (int i = 0; i < 10000; i++) {
+            Exchange ex = ep.createExchange();
+            ex.getIn().setHeader("url", "http://localhost:9080/leak?id=" + i);
+            p.process(ex);
+        }
+
+        p.stop();
+    }
+
+}

Propchange: camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date