camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/6] camel git commit: CAMEL-8526: Add more EIP as specialized mbeans
Date Tue, 21 Jul 2015 14:07:40 GMT
CAMEL-8526: Add more EIP as specialized mbeans


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

Branch: refs/heads/master
Commit: 1ee9b41dab972a73d618bba72121aa2437235a64
Parents: f19c32c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jul 21 14:38:14 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jul 21 14:38:14 2015 +0200

----------------------------------------------------------------------
 .../api/management/mbean/ManagedLoopMBean.java  | 29 +++++++
 .../DefaultManagementObjectStrategy.java        |  4 +
 .../camel/management/mbean/ManagedLoop.java     | 48 +++++++++++
 .../apache/camel/processor/LoopProcessor.java   |  4 +
 .../camel/management/ManagedLoopTest.java       | 89 ++++++++++++++++++++
 5 files changed, 174 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1ee9b41d/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedLoopMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedLoopMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedLoopMBean.java
new file mode 100644
index 0000000..0449bf7
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedLoopMBean.java
@@ -0,0 +1,29 @@
+/**
+ * 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.api.management.mbean;
+
+import org.apache.camel.api.management.ManagedAttribute;
+
+public interface ManagedLoopMBean extends ManagedProcessorMBean {
+
+    @ManagedAttribute(description = "Expression to define how many times we should loop")
+    String getExpression();
+
+    @ManagedAttribute(description = "Whether a copy of the input Exchange is used for each
iteration")
+    Boolean isCopy();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1ee9b41d/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
index 0265623..eda6441 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
@@ -45,6 +45,7 @@ import org.apache.camel.management.mbean.ManagedErrorHandler;
 import org.apache.camel.management.mbean.ManagedEventNotifier;
 import org.apache.camel.management.mbean.ManagedFilter;
 import org.apache.camel.management.mbean.ManagedIdempotentConsumer;
+import org.apache.camel.management.mbean.ManagedLoop;
 import org.apache.camel.management.mbean.ManagedPollEnricher;
 import org.apache.camel.management.mbean.ManagedProcessor;
 import org.apache.camel.management.mbean.ManagedProducer;
@@ -66,6 +67,7 @@ import org.apache.camel.processor.DynamicRouter;
 import org.apache.camel.processor.Enricher;
 import org.apache.camel.processor.ErrorHandler;
 import org.apache.camel.processor.FilterProcessor;
+import org.apache.camel.processor.LoopProcessor;
 import org.apache.camel.processor.PollEnricher;
 import org.apache.camel.processor.RoutingSlip;
 import org.apache.camel.processor.SendDynamicProcessor;
@@ -201,6 +203,8 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
                 answer = new ManagedRoutingSlip(context, (RoutingSlip) target, definition);
             } else if (target instanceof FilterProcessor) {
                 answer = new ManagedFilter(context, (FilterProcessor) target, definition);
+            } else if (target instanceof LoopProcessor) {
+                answer = new ManagedLoop(context, (LoopProcessor) target, definition);
             } else if (target instanceof WireTapProcessor) {
                 answer = new ManagedWireTapProcessor(context, (WireTapProcessor) target,
definition);
             } else if (target instanceof SendDynamicProcessor) {

http://git-wip-us.apache.org/repos/asf/camel/blob/1ee9b41d/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedLoop.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedLoop.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedLoop.java
new file mode 100644
index 0000000..8d791c7
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedLoop.java
@@ -0,0 +1,48 @@
+/**
+ * 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.management.mbean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedLoopMBean;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.LoopProcessor;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed Loop")
+public class ManagedLoop extends ManagedProcessor implements ManagedLoopMBean {
+    private final LoopProcessor processor;
+    private final String uri;
+
+    public ManagedLoop(CamelContext context, LoopProcessor processor, ProcessorDefinition<?>
definition) {
+        super(context, processor, definition);
+        this.processor = processor;
+        this.uri = processor.getExpression().toString();
+    }
+
+    @Override
+    public String getExpression() {
+        return uri;
+    }
+
+    @Override
+    public Boolean isCopy() {
+        return processor.isCopy();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1ee9b41d/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
index 124ba89..7b2c6d6 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
@@ -183,6 +183,10 @@ public class LoopProcessor extends DelegateAsyncProcessor implements
Traceable,
         return expression;
     }
 
+    public boolean isCopy() {
+        return copy;
+    }
+
     public String getTraceLabel() {
         return "loop[" + expression + "]";
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1ee9b41d/camel-core/src/test/java/org/apache/camel/management/ManagedLoopTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedLoopTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedLoopTest.java
new file mode 100644
index 0000000..bbacb6d
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedLoopTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version 
+ */
+public class ManagedLoopTest extends ManagementTestSupport {
+
+    public void testManageLoop() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MockEndpoint foo = getMockEndpoint("mock:foo");
+        foo.expectedMessageCount(2);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "2");
+
+        assertMockEndpointsSatisfied();
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+
+        // get the object name for the delayer
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
+
+        // should be on route1
+        String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+        assertEquals("route1", routeId);
+
+        String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
+        assertEquals("camel-1", camelId);
+
+        String state = (String) mbeanServer.getAttribute(on, "State");
+        assertEquals(ServiceStatus.Started.name(), state);
+
+        String uri = (String) mbeanServer.getAttribute(on, "Expression");
+        assertEquals("header{foo}", uri);
+
+        TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{false},
new String[]{"boolean"});
+        assertNotNull(data);
+        assertEquals(2, data.size());
+
+        data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{true}, new String[]{"boolean"});
+        assertNotNull(data);
+        assertEquals(5, data.size());
+
+        String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
+        assertNotNull(json);
+        assertTrue(json.contains("\"description\": \"Processes a message multiple times"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .loop(header("foo")).id("mysend")
+                        .to("mock:foo");
+            }
+        };
+    }
+
+}


Mime
View raw message