camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r674800 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/management/ test/java/org/apache/camel/management/
Date Tue, 08 Jul 2008 12:36:38 GMT
Author: davsclaus
Date: Tue Jul  8 05:36:37 2008
New Revision: 674800

URL: http://svn.apache.org/viewvc?rev=674800&view=rev
Log:
CAMEL-679: Instrumentation agent should be able to register multiple instances of a processor.
Applied patch with thanks to William Tam.

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java?rev=674800&r1=674799&r2=674800&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
Tue Jul  8 05:36:37 2008
@@ -27,7 +27,6 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Route;
 import org.apache.camel.model.ProcessorType;
-import org.apache.camel.model.RouteType;
 import org.apache.camel.spi.RouteContext;
 
 public class CamelNamingStrategy {
@@ -43,6 +42,8 @@
     public static final String TYPE_PROCESSOR = "processor";
     public static final String TYPE_ROUTE = "route";
     public static final String TYPE_SERVICE = "service";
+    public static final String KEY_NODE_ID = "nodeid";
+    public static final String KEY_INSTANCE = "instance";
 
     protected String domainName;
     protected String hostName = "locahost";
@@ -138,10 +139,10 @@
     /**
      * Implements the naming strategy for a {@link ProcessorType}.
      * The convention used for a {@link ProcessorType} ObjectName is:
-     * <tt>&lt;domain&gt;:context=&lt;context-name&gt;,route=&lt;route-name&gt;,type=processor,name=&lt;processor-name&gt;</tt>
+     * <tt>&lt;domain&gt;:context=&lt;context-name&gt;,route=&lt;route-name&gt;,type=processor,name=&lt;processor-name&gt;,nodeid=&lt;node-id&gt;,instance=&lt;instance-id&gt;</tt>
      */
     public ObjectName getObjectName(RouteContext routeContext, 
-            ProcessorType processor) throws MalformedObjectNameException {
+            ProcessorType processor, Integer instanceCount) throws MalformedObjectNameException
{
         Endpoint<? extends Exchange> ep = routeContext.getEndpoint();
         String ctxid = ep != null ? getContextId(ep.getCamelContext()) : VALUE_UNKNOWN;
         String cid = getComponentId(ep);
@@ -152,6 +153,10 @@
         buffer.append(KEY_CONTEXT + "=").append(ctxid).append(",");
         buffer.append(KEY_ROUTE + "=").append(id).append(",");
         buffer.append(KEY_TYPE + "=" + TYPE_PROCESSOR + ",");
+        buffer.append(KEY_NODE_ID + "=" + processor.getId() + ",");
+        if (instanceCount != null) {
+            buffer.append(KEY_INSTANCE + "=" + instanceCount + ",");
+        }
         buffer.append(KEY_NAME + "=").append(ObjectName.quote(processor.toString()));
         return createObjectName(buffer);
     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=674800&r1=674799&r2=674800&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
Tue Jul  8 05:36:37 2008
@@ -23,6 +23,8 @@
 import java.util.Map;
 
 import javax.management.JMException;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
@@ -167,15 +169,45 @@
         // to InstrumentationProcessor and wrap the appropriate processor
         // by InstrumentationInterceptStrategy.
         RouteType route = routeContext.getRoute();
+        
+        // build a local map for handlng multiple instances of a processor
+        Map<ObjectName, Integer> existingNames = new HashMap<ObjectName, Integer>();
+        Map<ProcessorType, ObjectName> nameMap = new HashMap<ProcessorType, ObjectName>();
+        
         for (ProcessorType processor : route.getOutputs()) {
+            ObjectName name = null;
+            try {
+                name = getNamingStrategy().getObjectName(routeContext, processor, null);
+            } catch (MalformedObjectNameException e) {
+                LOG.warn("Could not register MBean: " + name, e);
+            }
+            
+            if (name != null) {
+                Integer instanceCount = existingNames.get(name);
+                if (instanceCount != null) {
+                    instanceCount++;
+                } else {
+                    instanceCount = new Integer(0);
+                    existingNames.put(name, instanceCount);
+                }
+                
+                try {
+                    name = getNamingStrategy().getObjectName(routeContext, processor, instanceCount);
+                    nameMap.put(processor, name);
+                } catch (MalformedObjectNameException e) {
+                    LOG.warn("Could not register MBean: " + name, e);
+                }
+            }
+        }
+        
+        for (Map.Entry<ProcessorType, ObjectName> entry : nameMap.entrySet()) {
             PerformanceCounter pc = new PerformanceCounter();
             try {
-                agent.register(pc, getNamingStrategy().getObjectName(
-                        routeContext, processor));
+                agent.register(pc, entry.getValue());
             } catch (JMException e) {
-                LOG.warn("Could not register Counter MBean", e);
+                LOG.warn("Could not register PerformanceCounter MBean", e);
             }
-            counterMap.put(processor, pc);
+            counterMap.put(entry.getKey(), pc);
         }
 
         routeContext.addInterceptStrategy(new InstrumentationInterceptStrategy(counterMap));

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java?rev=674800&r1=674799&r2=674800&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
Tue Jul  8 05:36:37 2008
@@ -80,7 +80,7 @@
 
     }
 
-    private void verifyCounter(MBeanServerConnection beanServer, ObjectName name) throws
Exception {
+    protected void verifyCounter(MBeanServerConnection beanServer, ObjectName name) throws
Exception {
         Set s = beanServer.queryNames(name, null);
         assertEquals("Found mbeans: " + s, 1, s.size());
 

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java?rev=674800&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
Tue Jul  8 05:36:37 2008
@@ -0,0 +1,87 @@
+/**
+ * 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 java.util.Set;
+
+import javax.management.ObjectName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * A unit test to verify mbean registration of multi-instances of a processor 
+ *
+ * @version $Revision$
+ */
+public class MultiInstanceProcessorTest extends JmxInstrumentationUsingDefaultsTest {
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").to("mock:end").to("mock:end");
+            }
+        };
+    }
+
+    /**
+     * It retrieves a mbean for each "to" processor instance in the query ":type=processor"
+     */
+    @Override
+    public void testMBeansRegistered() throws Exception {
+        if (!Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
+            assertEquals(domainName, mbsc.getDefaultDomain());
+        }
+
+        resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
+
+        Set s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=endpoint,*"), null);
+        assertEquals("Could not find 2 endpoints: " + s, 2, s.size());
+
+        s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=context,*"), null);
+        assertEquals("Could not find 1 context: " + s, 1, s.size());
+
+        s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=processor,*"), null);
+        assertEquals("Could not find 2 processor: " + s, 2, s.size());
+
+        s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=route,*"), null);
+        assertEquals("Could not find 1 route: " + s, 1, s.size());
+
+    }
+    
+    @Override
+    public void testCounters() throws Exception {
+
+        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
+        resultEndpoint.expectedBodiesReceived(
+                new Object[] {"<hello>world!</hello>", "<hello>world!</hello>"});
+        sendBody("direct:start", "<hello>world!</hello>");
+
+        resultEndpoint.assertIsSatisfied();
+
+        verifyCounter(mbsc, new ObjectName(domainName + ":type=route,*"));
+        verifyCounter(mbsc, new ObjectName(domainName + ":type=processor,instance=0,*"));
+        verifyCounter(mbsc, new ObjectName(domainName + ":type=processor,instance=1,*"));
+
+    }
+
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message