Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59F8BDB1F for ; Wed, 15 Aug 2012 13:38:14 +0000 (UTC) Received: (qmail 17621 invoked by uid 500); 15 Aug 2012 13:38:14 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 17589 invoked by uid 500); 15 Aug 2012 13:38:14 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 17582 invoked by uid 99); 15 Aug 2012 13:38:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2012 13:38:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2012 13:38:11 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2DD3A23889CB; Wed, 15 Aug 2012 13:37:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1373402 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Date: Wed, 15 Aug 2012 13:37:27 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120815133727.2DD3A23889CB@eris.apache.org> Author: davsclaus Date: Wed Aug 15 13:37:26 2012 New Revision: 1373402 URL: http://svn.apache.org/viewvc?rev=1373402&view=rev Log: CAMEL-5508: Optimized to eager lookup properties component if in use. Avoids re-lookup at runtime, such as when property placeholder is not used etc. Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.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=1373402&r1=1373401&r2=1373402&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 Wed Aug 15 13:37:26 2012 @@ -182,6 +182,7 @@ public class DefaultCamelContext extends private Map properties = new HashMap(); private FactoryFinderResolver factoryFinderResolver = new DefaultFactoryFinderResolver(); private FactoryFinder defaultFactoryFinder; + private PropertiesComponent propertiesComponent; private final Map factories = new HashMap(); private final Map routeServices = new LinkedHashMap(); private final Map suspendedRouteServices = new LinkedHashMap(); @@ -294,6 +295,11 @@ public class DefaultCamelContext extends for (LifecycleStrategy strategy : lifecycleStrategies) { strategy.onComponentAdd(componentName, component); } + + // keep reference to properties component up to date + if (component instanceof PropertiesComponent && "properties".equals(componentName)) { + propertiesComponent = (PropertiesComponent) component; + } } } @@ -345,6 +351,10 @@ public class DefaultCamelContext extends strategy.onComponentRemove(componentName, answer); } } + // keep reference to properties component up to date + if (answer != null && "properties".equals(componentName)) { + propertiesComponent = null; + } return answer; } } @@ -1530,6 +1540,26 @@ public class DefaultCamelContext extends addService(shutdownStrategy); addService(packageScanClassResolver); + // eager lookup any configured properties component to avoid subsequent lookup attempts which may impact performance + // due we use properties component for property placeholder resolution at runtime + Component existing = hasComponent("properties"); + if (existing == null) { + // no existing properties component so lookup and add as component if possible + propertiesComponent = getRegistry().lookup("properties", PropertiesComponent.class); + if (propertiesComponent != null) { + addComponent("properties", propertiesComponent); + } + } else { + // store reference to the existing properties component + if (existing instanceof PropertiesComponent) { + propertiesComponent = (PropertiesComponent) existing; + } else { + // properties component must be expected type + throw new IllegalArgumentException("Found properties component of type: " + existing.getClass() + " instead of expected: " + PropertiesComponent.class); + } + } + + // start components startServices(components.values()); // setup default thread pool for error handler @@ -1984,7 +2014,7 @@ public class DefaultCamelContext extends } Endpoint existing = existingRoute.getEndpoint(); ServiceStatus status = getRouteStatus(existingRoute.getId()); - if (status != null && status.isStarted() || status.isStarting()) { + if (status != null && (status.isStarted() || status.isStarting())) { existingEndpoints.add(existing); } } @@ -2169,24 +2199,11 @@ public class DefaultCamelContext extends } /** - * Looks up the properties component if one may be resolved or has already been created. - * Returns {@code null} if one was not created or is not in the registry. + * Gets the properties component in use. + * Returns {@code null} if no properties component is in use. */ protected PropertiesComponent getPropertiesComponent() { - Component component = hasComponent("properties"); - if (component == null) { - // then fallback to lookup the component - component = getRegistry().lookup("properties", Component.class); - } - - PropertiesComponent pc = null; - // Ensure that we don't create one if one is not really available. - if (component != null) { - // force component to be created and registered as a component - pc = getComponent("properties", PropertiesComponent.class); - } - - return pc; + return propertiesComponent; } public void setDataFormats(Map dataFormats) {