KARAF-1794 - Extend Camel plugin with support for suspending/resuming context
authorŁukasz Dywicki <ldywicki@apache.org>
Wed, 5 Sep 2012 22:08:41 +0000 (22:08 +0000)
committerŁukasz Dywicki <ldywicki@apache.org>
Wed, 5 Sep 2012 22:08:41 +0000 (22:08 +0000)
Signed-off-by: Lukasz Dywicki <luke@code-house.org>
git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1381415 13f79535-47bb-0310-9956-ffa450edef68

camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/ContextActionsPanel.java
camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/ContextLink.java [new file with mode: 0644]
camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/ResumeLink.java [new file with mode: 0644]
camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/SuspendLink.java [new file with mode: 0644]

index e6066c0..26109d3 100644 (file)
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.camel.CamelContext;
+import org.apache.karaf.webconsole.camel.internal.context.link.ResumeLink;
+import org.apache.karaf.webconsole.camel.internal.context.link.SuspendLink;
 import org.apache.karaf.webconsole.camel.internal.tracking.TraceContainer;
 import org.apache.karaf.webconsole.core.table.ActionsPanel;
 import org.apache.wicket.Session;
@@ -85,6 +87,16 @@ public class ContextActionsPanel extends ActionsPanel<CamelContext> {
             links.add(link);
         }
 
+        if (!object.isSuspended()) {
+            Link link = new SuspendLink(linkId, getModel());
+            link.add(new Label(labelId, "Suspend"));
+            links.add(link);
+        } else {
+            Link link = new ResumeLink(linkId, getModel());
+            link.add(new Label(labelId, "Resume"));
+            links.add(link);
+        }
+
         return links;
     }
 
diff --git a/camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/ContextLink.java b/camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/ContextLink.java
new file mode 100644 (file)
index 0000000..e240598
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.karaf.webconsole.camel.internal.context.link;
+
+import org.apache.camel.CamelContext;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.IModel;
+
+/**
+ * Base link for context releated stuff.
+ */
+public abstract class ContextLink extends Link<CamelContext> {
+
+    private static final long serialVersionUID = 1L;
+
+    public ContextLink(String id, IModel<CamelContext> model) {
+        super(id, model);
+    }
+
+    @Override
+    public void onClick() {
+        onClick((CamelContext) getDefaultModelObject());
+    }
+
+    protected abstract void onClick(CamelContext context);
+
+}
diff --git a/camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/ResumeLink.java b/camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/ResumeLink.java
new file mode 100644 (file)
index 0000000..df75e6e
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.karaf.webconsole.camel.internal.context.link;
+
+import org.apache.camel.CamelContext;
+import org.apache.wicket.model.IModel;
+
+/**
+ * Link which resume context.
+ */
+public class ResumeLink extends ContextLink {
+
+    private static final long serialVersionUID = 1L;
+
+    public ResumeLink(String id, IModel<CamelContext> model) {
+        super(id, model);
+    }
+
+    @Override
+    protected void onClick(CamelContext context) {
+        try {
+            context.resume();
+            info("Resume context " + context.getName() + " successfull");
+        } catch (Exception e) {
+            warn("Exception during resuming context " + e.getMessage());
+        }
+    }
+
+}
diff --git a/camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/SuspendLink.java b/camel/src/main/java/org/apache/karaf/webconsole/camel/internal/context/link/SuspendLink.java
new file mode 100644 (file)
index 0000000..93b2f8b
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.karaf.webconsole.camel.internal.context.link;
+
+import org.apache.camel.CamelContext;
+import org.apache.wicket.model.IModel;
+
+/**
+ * Link which suspends context.
+ */
+public class SuspendLink extends ContextLink {
+
+    private static final long serialVersionUID = 1L;
+
+    public SuspendLink(String id, IModel<CamelContext> model) {
+        super(id, model);
+    }
+
+    @Override
+    protected void onClick(CamelContext context) {
+        try {
+            context.suspend();
+            info("Suspended context " + context.getName() + " successfull");
+        } catch (Exception e) {
+            warn("Exception during suspending context " + e.getMessage());
+        }
+    }
+
+}