You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2013/08/21 13:12:24 UTC

git commit: avoid possible hang or crash if we try and complete on a component which is not active and hasn't been configured. Also provide an API to lookup components which are active (to avoid forcing lazy create)

Updated Branches:
  refs/heads/master a87a8d129 -> 708c4cd87


avoid possible hang or crash if we try and complete on a component which is not active and hasn't been configured. Also provide an API to lookup components which are active (to avoid forcing lazy create)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/708c4cd8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/708c4cd8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/708c4cd8

Branch: refs/heads/master
Commit: 708c4cd87e3e2cdc0922749e4ab1a660d5337291
Parents: a87a8d1
Author: James Strachan <ja...@gmail.com>
Authored: Wed Aug 21 12:11:40 2013 +0100
Committer: James Strachan <ja...@gmail.com>
Committed: Wed Aug 21 12:11:40 2013 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/CamelContext.java    | 10 ++++++++++
 .../java/org/apache/camel/impl/DefaultCamelContext.java |  4 ++++
 .../camel/management/mbean/ManagedCamelContext.java     | 12 ++++++++----
 3 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/708c4cd8/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 64f4d7a..d8f7894 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -248,6 +248,16 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     Component getComponent(String componentName);
 
     /**
+     * Gets a component from the context by name.
+     *
+     * @param componentName the name of the component
+     * @param autoCreateComponents whether or not the component should
+     *                             be lazily created if it does not already exist
+     * @return the component
+     */
+    Component getComponent(String name, boolean autoCreateComponents);
+
+    /**
      * Gets a component from the context by name and specifying the expected type of component.
      *
      * @param name          the name to lookup

http://git-wip-us.apache.org/repos/asf/camel/blob/708c4cd8/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 7dd64de..9fe8bb1 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -331,6 +331,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
     }
 
     public Component getComponent(String name) {
+        return getComponent(name, autoCreateComponents);
+    }
+
+    public Component getComponent(String name, boolean autoCreateComponents) {
         // synchronize the look up and auto create so that 2 threads can't
         // concurrently auto create the same component.
         synchronized (components) {

http://git-wip-us.apache.org/repos/asf/camel/blob/708c4cd8/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index e643e8d..b41ff35 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -373,10 +373,14 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
         if (completionText == null) {
             completionText = "";
         }
-        Component component = context.getComponent(componentName);
-        ComponentConfiguration configuration = component.createComponentConfiguration();
-        configuration.setParameters(endpointParameters);
-        return configuration.completeEndpointPath(completionText);
+        Component component = context.getComponent(componentName, false);
+        if (component != null) {
+            ComponentConfiguration configuration = component.createComponentConfiguration();
+            configuration.setParameters(endpointParameters);
+            return configuration.completeEndpointPath(completionText);
+        } else {
+            return new ArrayList<String>();
+        }
     }
 
     public String componentParameterJsonSchema(String componentName) throws Exception {