Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 68b95249e -> ed5ea52ce
  refs/heads/master e24509968 -> ea2863e13


[CAMEL-7261] camel:context-suspend and camel:context-resume commands

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

Branch: refs/heads/master
Commit: 97aa17c2731ab2c72e26ecbffb54956ca58e4b9b
Parents: 9ea05aa
Author: Grzegorz Grzybek <gr.grzy...@gmail.com>
Authored: Mon Mar 3 10:16:20 2014 +0100
Committer: Grzegorz Grzybek <gr.grzy...@gmail.com>
Committed: Mon Mar 3 10:57:52 2014 +0100

----------------------------------------------------------------------
 .../karaf/commands/AbstractContextCommand.java  | 44 ++++++++++++++++++++
 .../camel/karaf/commands/ContextResume.java     | 33 +++++++++++++++
 .../camel/karaf/commands/ContextStart.java      | 15 ++-----
 .../camel/karaf/commands/ContextStop.java       | 15 ++-----
 .../camel/karaf/commands/ContextSuspend.java    | 33 +++++++++++++++
 .../OSGI-INF/blueprint/camel-commands.xml       | 18 ++++++++
 .../src/main/resources/OSGI-INF/bundle.info     |  2 +
 7 files changed, 136 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractContextCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractContextCommand.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractContextCommand.java
new file mode 100644
index 0000000..7cd3625
--- /dev/null
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractContextCommand.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.karaf.commands;
+
+import org.apache.camel.CamelContext;
+import org.apache.felix.gogo.commands.Argument;
+
+public abstract class AbstractContextCommand extends CamelCommandSupport {
+
+    @Argument(index = 0, name = "context", description = "The name of the 
Camel context.", required = true, multiValued = false)
+    String context;
+
+    public Object doExecute() throws Exception {
+        CamelContext camelContext = camelController.getCamelContext(context);
+        if (camelContext == null) {
+            System.err.println("Camel context " + context + " not found.");
+            return null;
+        }
+        performContextCommand(camelContext);
+        return null;
+    }
+
+    /**
+     * Perform Context-specific command
+     *
+     * @param camelContext non-null {@link CamelContext}
+     */
+    protected abstract void performContextCommand(CamelContext camelContext) 
throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextResume.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextResume.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextResume.java
new file mode 100644
index 0000000..7c8580e
--- /dev/null
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextResume.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.karaf.commands;
+
+import org.apache.camel.CamelContext;
+import org.apache.felix.gogo.commands.Command;
+
+/**
+ * Command to resume a Camel context.
+ */
+@Command(scope = "camel", name = "context-resume", description = "Resumes a 
Camel context.")
+public class ContextResume extends AbstractContextCommand {
+
+    @Override
+    protected void performContextCommand(CamelContext camelContext) throws 
Exception {
+        camelContext.resume();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStart.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStart.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStart.java
index 229ccc6..e2d3e0f 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStart.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStart.java
@@ -17,26 +17,17 @@
 package org.apache.camel.karaf.commands;
 
 import org.apache.camel.CamelContext;
-import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 
 /**
  * Command to start a Camel context.
  */
 @Command(scope = "camel", name = "context-start", description = "Start a Camel 
context.")
-public class ContextStart extends CamelCommandSupport {
+public class ContextStart extends AbstractContextCommand {
 
-    @Argument(index = 0, name = "context", description = "The name of the 
Camel context.", required = true, multiValued = false)
-    String context;
-
-    public Object doExecute() throws Exception {
-        CamelContext camelContext = camelController.getCamelContext(context);
-        if (camelContext == null) {
-            System.err.println("Camel context " + context + " not found.");
-            return null;
-        }
+    @Override
+    protected void performContextCommand(CamelContext camelContext) throws 
Exception {
         camelContext.start();
-        return null;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStop.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStop.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStop.java
index 7503602..6e46f2e 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStop.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextStop.java
@@ -17,26 +17,17 @@
 package org.apache.camel.karaf.commands;
 
 import org.apache.camel.CamelContext;
-import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 
 /**
  * Command to stop a Camel context.
  */
 @Command(scope = "camel", name = "context-stop", description = "Stop a Camel 
context.")
-public class ContextStop extends CamelCommandSupport {
+public class ContextStop extends AbstractContextCommand {
 
-    @Argument(index = 0, name = "context", description = "The name of the 
Camel context.", required = true, multiValued = false)
-    String context;
-
-    public Object doExecute() throws Exception {
-        CamelContext camelContext = camelController.getCamelContext(context);
-        if (camelContext == null) {
-            System.err.println("The Camel context " + camelContext + " is not 
found.");
-            return null;
-        }
+    @Override
+    protected void performContextCommand(CamelContext camelContext) throws 
Exception {
         camelContext.stop();
-        return null;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextSuspend.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextSuspend.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextSuspend.java
new file mode 100644
index 0000000..db24b9d
--- /dev/null
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextSuspend.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.karaf.commands;
+
+import org.apache.camel.CamelContext;
+import org.apache.felix.gogo.commands.Command;
+
+/**
+ * Command to suspend a Camel context.
+ */
+@Command(scope = "camel", name = "context-suspend", description = "Suspends a 
Camel context.")
+public class ContextSuspend extends AbstractContextCommand {
+
+    @Override
+    protected void performContextCommand(CamelContext camelContext) throws 
Exception {
+        camelContext.suspend();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
 
b/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
index 1cfec50..6eb8bce 100644
--- 
a/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
+++ 
b/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
@@ -50,6 +50,24 @@
                 <null/>
             </completers>
         </command>
+        <command name="camel/context-suspend">
+            <action class="org.apache.camel.karaf.commands.ContextSuspend">
+                <property name="camelController" ref="camelController"/>
+            </action>
+            <completers>
+                <ref component-id="camelContextCompleter"/>
+                <null/>
+            </completers>
+        </command>
+        <command name="camel/context-resume">
+            <action class="org.apache.camel.karaf.commands.ContextResume">
+                <property name="camelController" ref="camelController"/>
+            </action>
+            <completers>
+                <ref component-id="camelContextCompleter"/>
+                <null/>
+            </completers>
+        </command>
         <command name="camel/route-list">
             <action class="org.apache.camel.karaf.commands.RouteList">
                 <property name="camelController" ref="camelController"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/97aa17c2/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info 
b/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
index efa527b..15deb4d 100644
--- a/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
+++ b/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
@@ -14,6 +14,8 @@
     \u001B[36mcamel:context-list\u001B[0m Lists all Camel contexts.
     \u001B[36mcamel:context-start\u001B[0m Start a Camel context.
     \u001B[36mcamel:context-stop\u001B[0m Stops a Camel context.
+    \u001B[36mcamel:context-suspend\u001B[0m Suspends a Camel context.
+    \u001B[36mcamel:context-resume\u001B[0m Resumes a Camel context.
     \u001B[36mcamel:route-info\u001B[0m Display information about a Camel 
route.
     \u001B[36mcamel:route-list\u001B[0m Lists the Camel routes.
     \u001B[36mcamel:route-resume\u001B[0m Resume a Camel route.

Reply via email to