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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

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

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


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

commit 93eeec1be307ef66e07c8a7334ae807023aaac54
Author: Grzegorz Grzybek <[hidden email]>
AuthorDate: Fri Jan 11 13:47:08 2019 +0100

    [CAMEL-13049] Use CamelContext's ClassLoader as TCCL for some Karaf commands
   
    (cherry picked from commit da36458fbd564440cec711c80013790cc22dccf9)
---
 .../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 cfd311a..7dc961e 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();
+    }
+
 }