You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cs...@apache.org on 2013/01/21 17:23:32 UTC

svn commit: r1436456 - in /camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands: AbstractRouteCommand.java RouteResume.java RouteStart.java RouteStop.java RouteSuspend.java

Author: cschneider
Date: Mon Jan 21 16:23:32 2013
New Revision: 1436456

URL: http://svn.apache.org/viewvc?rev=1436456&view=rev
Log:
CAMEL-5968 Set thread context classloader to bundle classloader for route commands, consolidate route commands code

Added:
    camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
      - copied, changed from r1436431, camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
Modified:
    camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
    camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
    camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
    camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java

Copied: camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java (from r1436431, camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java?p2=camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java&p1=camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java&r1=1436431&r2=1436456&rev=1436456&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java (original)
+++ camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java Mon Jan 21 16:23:32 2013
@@ -16,11 +16,8 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.util.List;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
-import org.apache.camel.karaf.commands.internal.RegexUtil;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 
@@ -40,16 +37,21 @@ public abstract class AbstractRouteComma
     public abstract void executeOnRoute(CamelContext camelContext, Route camelRoute) throws Exception;
     
     public Object doExecute() throws Exception {
-        List<Route> camelRoutes = camelController.getRoutes(context, RegexUtil.wildcardAsRegex(route));
-        if (camelRoutes == null || camelRoutes.isEmpty()) {
-            System.err.println("Camel routes using " + route + " not found.");
+        Route camelRoute = camelController.getRoute(route, context);
+        if (camelRoute == null) {
+            System.err.println("Camel route " + route + " not found.");
             return null;
         }
-        for (Route camelRoute : camelRoutes) {
-            CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-            executeOnRoute(camelContext, camelRoute);
+        CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
+        // Setting thread context classloader to the bundle classloader to enable
+        // legacy code that relies on it 
+        ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(camelContext.getApplicationContextClassLoader());
+        try {
+        	executeOnRoute(camelContext, camelRoute);
+        } finally {
+        	Thread.currentThread().setContextClassLoader(oldClassloader);
         }
-
         return null;
     }
 }

Modified: camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java?rev=1436456&r1=1436455&r2=1436456&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java (original)
+++ camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java Mon Jan 21 16:23:32 2013
@@ -18,37 +18,17 @@ package org.apache.camel.karaf.commands;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
-import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
 
 /**
  * Command to resume a route.
  */
 @Command(scope = "camel", name = "route-resume", description = "Resume a Camel route.")
-public class RouteResume extends OsgiCommandSupport {
+public class RouteResume extends AbstractRouteCommand {
 
-    @Argument(index = 0, name = "route", description = "The Camel route ID.", required = true, multiValued = false)
-    String route;
-
-    @Argument(index = 1, name = "context", description = "The Camel context name.", required = false, multiValued = false)
-    String context;
-
-    private CamelController camelController;
-
-    public void setCamelController(CamelController camelController) {
-        this.camelController = camelController;
-    }
-
-    public Object doExecute() throws Exception {
-        Route camelRoute = camelController.getRoute(route, context);
-        if (camelRoute == null) {
-            System.err.println("Camel route " + route + " not found.");
-            return null;
-        }
-        CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-        camelContext.resumeRoute(route);
-        return null;
-    }
+	@Override
+	public void executeOnRoute(CamelContext camelContext, Route camelRoute) throws Exception {
+		camelContext.resumeRoute(route);
+	}
 
 }

Modified: camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java?rev=1436456&r1=1436455&r2=1436456&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java (original)
+++ camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java Mon Jan 21 16:23:32 2013
@@ -16,51 +16,19 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.util.List;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
 
 /**
  * Command to start a route.
  */
 @Command(scope = "camel", name = "route-start", description = "Start a Camel route.")
-public class RouteStart extends OsgiCommandSupport {
-
-    @Argument(index = 0, name = "route", description = "The Camel route ID.", required = true, multiValued = false)
-    String route;
-
-    @Argument(index = 1, name = "context", description = "The Camel context name.", required = false, multiValued = false)
-    String context;
-
-    private CamelController camelController;
-
-    public void setCamelController(CamelController camelController) {
-        this.camelController = camelController;
-    }
+public class RouteStart extends AbstractRouteCommand {
 
-    public Object doExecute() throws Exception {
-        Route camelRoute = camelController.getRoute(route, context);
-        if (camelRoute == null) {
-            List<CamelContext> camelContexts = camelController.getCamelContexts();
-            for (CamelContext camelContext : camelContexts) {
-                RouteDefinition routeDefinition = camelContext.getRouteDefinition(route);
-                if (routeDefinition != null) {
-                    camelContext.startRoute(routeDefinition.getId());
-                    return null;
-                }
-            }
-            System.err.println("Camel route " + route + " not found.");
-            return null;
-        } else {
-            CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-            camelContext.startRoute(route);
-        }
-        return null;
-    }
+	@Override
+	public void executeOnRoute(CamelContext camelContext, Route camelRoute) throws Exception {
+		camelContext.startRoute(route);
+	}
 
 }

Modified: camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java?rev=1436456&r1=1436455&r2=1436456&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java (original)
+++ camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java Mon Jan 21 16:23:32 2013
@@ -18,37 +18,17 @@ package org.apache.camel.karaf.commands;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
-import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
 
 /**
  * Command to stop a route.
  */
 @Command(scope = "camel", name = " route-stop", description = "Stop a Camel route.")
-public class RouteStop extends OsgiCommandSupport {
+public class RouteStop extends AbstractRouteCommand {
 
-    @Argument(index = 0, name = "route", description = "The Camel route ID.", required = true, multiValued = false)
-    String route;
-
-    @Argument(index = 1, name = "context", description = "The Camel context name.", required = false, multiValued = false)
-    String context;
-
-    private CamelController camelController;
-
-    public void setCamelController(CamelController camelController) {
-        this.camelController = camelController;
-    }
-
-    public Object doExecute() throws Exception {
-        Route camelRoute = camelController.getRoute(route, context);
-        if (camelRoute == null) {
-            System.err.println("Camel route " + route + " not found.");
-            return null;
-        }
-        CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-        camelContext.stopRoute(route);
-        return null;
-    }
+	@Override
+	public void executeOnRoute(CamelContext camelContext, Route camelRoute) throws Exception {
+		camelContext.stopRoute(route);
+	}
 
 }

Modified: camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java?rev=1436456&r1=1436455&r2=1436456&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java (original)
+++ camel/branches/camel-2.9.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java Mon Jan 21 16:23:32 2013
@@ -18,37 +18,17 @@ package org.apache.camel.karaf.commands;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
-import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
 
 /**
  * Command to suspend a route.
  */
 @Command(scope = "camel", name = " route-suspend", description = "Suspend a Camel route.")
-public class RouteSuspend extends OsgiCommandSupport {
+public class RouteSuspend extends AbstractRouteCommand {
 
-    @Argument(index = 0, name = "route", description = "The Camel route ID.", required = true, multiValued = false)
-    String route;
-
-    @Argument(index = 1, name = "context", description = "The Camel context name.", required = false, multiValued = false)
-    String context;
-
-    private CamelController camelController;
-
-    public void setCamelController(CamelController camelController) {
-        this.camelController = camelController;
-    }
-
-    public Object doExecute() throws Exception {
-        Route camelRoute = camelController.getRoute(route, context);
-        if (camelRoute == null) {
-            System.err.println("Camel route " + route + " not found.");
-            return null;
-        }
-        CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-        camelContext.suspendRoute(route);
-        return null;
-    }
+	@Override
+	public void executeOnRoute(CamelContext camelContext, Route camelRoute) throws Exception {
+		camelContext.suspendRoute(route);
+	}
 
 }