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 2012/08/15 15:41:14 UTC
svn commit: r1373406 - in /camel/branches/camel-2.10.x: ./
camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Author: davsclaus
Date: Wed Aug 15 13:41:14 2012
New Revision: 1373406
URL: http://svn.apache.org/viewvc?rev=1373406&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/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1373402
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1373406&r1=1373405&r2=1373406&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed Aug 15 13:41:14 2012
@@ -183,6 +183,7 @@ public class DefaultCamelContext extends
private Map<String, String> properties = new HashMap<String, String>();
private FactoryFinderResolver factoryFinderResolver = new DefaultFactoryFinderResolver();
private FactoryFinder defaultFactoryFinder;
+ private PropertiesComponent propertiesComponent;
private final Map<String, FactoryFinder> factories = new HashMap<String, FactoryFinder>();
private final Map<String, RouteService> routeServices = new LinkedHashMap<String, RouteService>();
private final Map<String, RouteService> suspendedRouteServices = new LinkedHashMap<String, RouteService>();
@@ -295,6 +296,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;
+ }
}
}
@@ -346,6 +352,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;
}
}
@@ -1531,6 +1541,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
@@ -1985,7 +2015,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);
}
}
@@ -2170,24 +2200,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<String, DataFormatDefinition> dataFormats) {