CAMEL-8324: Camel JMX - Allow to configure default management name pattern 
using JVM system property


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

Branch: refs/heads/master
Commit: 5170ccdf17bfe3f29ab04976e2ba3db30b11d0b8
Parents: e7f0126
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Feb 9 08:28:29 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Feb 9 08:28:29 2015 +0100

----------------------------------------------------------------------
 .../impl/DefaultManagementNameStrategy.java     |  3 +-
 .../camel/management/JmxSystemPropertyKeys.java |  5 +-
 ...ManagedNamePatternJvmSystemPropertyTest.java | 64 ++++++++++++++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5170ccdf/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
index efc0be0..85df49c 100644
--- 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
+++ 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
@@ -21,6 +21,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.management.JmxSystemPropertyKeys;
 import org.apache.camel.spi.ManagementNameStrategy;
 import org.apache.camel.util.ObjectHelper;
 
@@ -42,7 +43,7 @@ public class DefaultManagementNameStrategy implements 
ManagementNameStrategy {
     private String namePattern;
 
     public DefaultManagementNameStrategy(CamelContext camelContext) {
-        this(camelContext, "#name#", "#name#-#counter#");
+        this(camelContext, 
System.getProperty(JmxSystemPropertyKeys.MANAGEMENT_NAME_PATTERN, "#name#"), 
"#name#-#counter#");
     }
 
     public DefaultManagementNameStrategy(CamelContext camelContext, String 
defaultPattern, String nextPattern) {

http://git-wip-us.apache.org/repos/asf/camel/blob/5170ccdf/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
 
b/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
index 3db8bfc..14e64ec 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
@@ -59,9 +59,12 @@ public final class JmxSystemPropertyKeys {
     // Whether to remove detected sensitive information (such as passwords) 
from MBean names and attributes.
     public static final String MASK = "org.apache.camel.jmx.mask";
 
-    // Whether to include host name in MBean naes
+    // Whether to include host name in MBean names
     public static final String INCLUDE_HOST_NAME = 
"org.apache.camel.jmx.includeHostName";
 
+    // To configure the default management name pattern using a JVM system 
property
+    public static final String MANAGEMENT_NAME_PATTERN = 
"org.apache.camel.jmx.managementNamePattern";
+
     private JmxSystemPropertyKeys() {
         // not instantiated
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5170ccdf/camel-core/src/test/java/org/apache/camel/management/ManagedNamePatternJvmSystemPropertyTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedNamePatternJvmSystemPropertyTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedNamePatternJvmSystemPropertyTest.java
new file mode 100644
index 0000000..2bd07bc
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedNamePatternJvmSystemPropertyTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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 org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class ManagedNamePatternJvmSystemPropertyTest extends 
ManagementTestSupport {
+
+    @Override
+    protected void setUp() throws Exception {
+        System.setProperty(JmxSystemPropertyKeys.MANAGEMENT_NAME_PATTERN, 
"cool-#name#");
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        System.clearProperty(JmxSystemPropertyKeys.MANAGEMENT_NAME_PATTERN);
+        super.tearDown();
+    }
+
+    public void testManagedNamePattern() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        assertEquals("cool-camel-1", context.getManagementName());
+
+        ObjectName on = 
ObjectName.getInstance("org.apache.camel:context=cool-camel-1,type=context,name=\"camel-1\"");
+        assertTrue("Should be registered", mbeanServer.isRegistered(on));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("mock:result");
+            }
+        };
+    }
+}

Reply via email to