You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gg...@apache.org on 2019/01/11 12:59:51 UTC

[camel] branch camel-2.21.x updated: [CAMEL-13049] Use CamelContext's ClassLoader as TCCL for some Karaf commands

This is an automated email from the ASF dual-hosted git repository.

ggrzybek pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.21.x by this push:
     new da36458  [CAMEL-13049] Use CamelContext's ClassLoader as TCCL for some Karaf commands
da36458 is described below

commit da36458fbd564440cec711c80013790cc22dccf9
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Fri Jan 11 13:47:08 2019 +0100

    [CAMEL-13049] Use CamelContext's ClassLoader as TCCL for some Karaf commands
---
 .../commands/internal/CamelControllerImpl.java     | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
index 4d4bd92..d25bdc6 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
@@ -22,9 +22,11 @@ import java.util.Comparator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.commands.AbstractLocalCamelController;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -100,4 +102,69 @@ public class CamelControllerImpl extends AbstractLocalCamelController {
         return answer;
     }
 
+    @Override
+    public void startContext(String camelContextName) throws Exception {
+        final CamelContext context = getLocalCamelContext(camelContextName);
+        if (context != null) {
+            ObjectHelper.callWithTCCL(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    context.start();
+                    return null;
+                }
+            }, getClassLoader(context));
+        }
+    }
+
+    @Override
+    public void resumeContext(String camelContextName) throws Exception {
+        final CamelContext context = getLocalCamelContext(camelContextName);
+        if (context != null) {
+            ObjectHelper.callWithTCCL(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    context.resume();
+                    return null;
+                }
+            }, getClassLoader(context));
+        }
+    }
+
+    @Override
+    public void startRoute(String camelContextName, final String routeId) throws Exception {
+        final CamelContext context = getLocalCamelContext(camelContextName);
+        if (context != null) {
+            ObjectHelper.callWithTCCL(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    context.startRoute(routeId);
+                    return null;
+                }
+            }, getClassLoader(context));
+        }
+    }
+
+    @Override
+    public void resumeRoute(String camelContextName, final String routeId) throws Exception {
+        final CamelContext context = getLocalCamelContext(camelContextName);
+        if (context != null) {
+            ObjectHelper.callWithTCCL(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    context.resumeRoute(routeId);
+                    return null;
+                }
+            }, getClassLoader(context));
+        }
+    }
+
+    /**
+     * Gets classloader associated with {@link CamelContext}
+     * @param context
+     * @return
+     */
+    private ClassLoader getClassLoader(CamelContext context) {
+        return context.getApplicationContextClassLoader();
+    }
+
 }