Repository: camel
Updated Branches:
  refs/heads/master 0092f2cb4 -> 4de78cea6


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/b7b463b9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7b463b9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7b463b9

Branch: refs/heads/master
Commit: b7b463b984a721b14035243280e3ea804f186e9e
Parents: 0092f2c
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Jul 21 14:01:42 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Jul 21 14:01:42 2015 +0200

----------------------------------------------------------------------
 .../management/mbean/ManagedFilterMBean.java    | 26 ++++++
 .../DefaultManagementObjectStrategy.java        |  4 +
 .../camel/management/mbean/ManagedFilter.java   | 41 +++++++++
 .../camel/management/ManagedFilterTest.java     | 89 ++++++++++++++++++++
 4 files changed, 160 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b7b463b9/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFilterMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFilterMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFilterMBean.java
new file mode 100644
index 0000000..f2451c0
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFilterMBean.java
@@ -0,0 +1,26 @@
+/**
+ * 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 ManagedFilterMBean extends ManagedProcessorMBean {
+
+    @ManagedAttribute(description = "Predicate to determine if the message 
should be filtered or not.")
+    String getFilter();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b7b463b9/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 705fc2b..bb2426c 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
@@ -42,6 +42,7 @@ import org.apache.camel.management.mbean.ManagedEndpoint;
 import org.apache.camel.management.mbean.ManagedEnricher;
 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.ManagedPollEnricher;
 import org.apache.camel.management.mbean.ManagedProcessor;
@@ -61,6 +62,7 @@ import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.processor.Delayer;
 import org.apache.camel.processor.Enricher;
 import org.apache.camel.processor.ErrorHandler;
+import org.apache.camel.processor.FilterProcessor;
 import org.apache.camel.processor.PollEnricher;
 import org.apache.camel.processor.SendDynamicProcessor;
 import org.apache.camel.processor.SendProcessor;
@@ -189,6 +191,8 @@ public class DefaultManagementObjectStrategy implements 
ManagementObjectStrategy
                 answer = new ManagedDelayer(context, (Delayer) target, 
definition);
             } else if (target instanceof Throttler) {
                 answer = new ManagedThrottler(context, (Throttler) target, 
definition);
+            } else if (target instanceof FilterProcessor) {
+                answer = new ManagedFilter(context, (FilterProcessor) 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/b7b463b9/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFilter.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFilter.java 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFilter.java
new file mode 100644
index 0000000..c25c36b
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFilter.java
@@ -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.camel.management.mbean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedFilterMBean;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.FilterProcessor;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed Filter")
+public class ManagedFilter extends ManagedProcessor implements 
ManagedFilterMBean {
+    private final FilterProcessor processor;
+
+    public ManagedFilter(CamelContext context, FilterProcessor processor, 
ProcessorDefinition<?> definition) {
+        super(context, processor, definition);
+        this.processor = processor;
+    }
+
+    @Override
+    public String getFilter() {
+        return processor.getPredicate().toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b7b463b9/camel-core/src/test/java/org/apache/camel/management/ManagedFilterTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedFilterTest.java 
b/camel-core/src/test/java/org/apache/camel/management/ManagedFilterTest.java
new file mode 100644
index 0000000..6591c35
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedFilterTest.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 ManagedFilterTest extends ManagementTestSupport {
+
+    public void testManageFilter() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MockEndpoint foo = getMockEndpoint("mock:foo");
+        foo.expectedMessageCount(1);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", 
"123");
+
+        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, "Filter");
+        assertEquals("header{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(4, data.size());
+
+        String json = (String) mbeanServer.invoke(on, "informationJson", null, 
null);
+        assertNotNull(json);
+        assertTrue(json.contains("\"description\": \"Filter out messages based 
using a predicate"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .filter(header("foo")).id("mysend")
+                        .to("mock:foo");
+            }
+        };
+    }
+
+}

Reply via email to