camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r950891 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/management/DefaultManagementAgent.java main/java/org/apache/camel/spi/ManagementAgent.java test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java
Date Thu, 03 Jun 2010 07:12:04 GMT
Author: davsclaus
Date: Thu Jun  3 07:12:04 2010
New Revision: 950891

URL: http://svn.apache.org/viewvc?rev=950891&view=rev
Log:
CAMEL-2786: Easier to set JMX agent options from Java using setters, instead of having to
use JVM system properties.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java
      - copied, changed from r950883, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRegisterEndpointTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementAgent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementAgent.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementAgent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementAgent.java?rev=950891&r1=950890&r2=950891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementAgent.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementAgent.java
Thu Jun  3 07:12:04 2010
@@ -390,6 +390,10 @@ public class DefaultManagementAgent exte
     }
 
     protected void createJmxConnector(String host) throws IOException {
+        ObjectHelper.notEmpty(serviceUrlPath, "serviceUrlPath");
+        ObjectHelper.notNull(registryPort, "registryPort");
+
+
         try {
             LocateRegistry.createRegistry(registryPort);
             if (LOG.isDebugEnabled()) {
@@ -399,14 +403,15 @@ public class DefaultManagementAgent exte
             // The registry may had been created, we could get the registry instead
         }
 
+        // must start with leading slash
+        String path = serviceUrlPath.startsWith("/") ? serviceUrlPath : "/" + serviceUrlPath;
         // Create an RMI connector and start it
         final JMXServiceURL url;
         if (connectorPort > 0) {
             url = new JMXServiceURL("service:jmx:rmi://" + host + ":" + connectorPort + "/jndi/rmi://"
+ host
-                                    + ":" + registryPort + serviceUrlPath);
+                                    + ":" + registryPort + path);
         } else {
-            url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + registryPort
-                                    + serviceUrlPath);
+            url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + registryPort
+ path);
         }
 
         cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementAgent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementAgent.java?rev=950891&r1=950890&r2=950891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementAgent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementAgent.java Thu Jun
 3 07:12:04 2010
@@ -91,4 +91,33 @@ public interface ManagementAgent extends
      */
     String getMBeanObjectDomainName();
 
+    void setRegistryPort(Integer value);
+
+    Integer getRegistryPort();
+
+    void setConnectorPort(Integer value);
+
+    Integer getConnectorPort();
+
+    void setMBeanServerDefaultDomain(String value);
+
+    String getMBeanServerDefaultDomain();
+
+    void setMBeanObjectDomainName(String value);
+
+    void setServiceUrlPath(String value);
+
+    String getServiceUrlPath();
+
+    void setCreateConnector(Boolean flag);
+
+    Boolean getCreateConnector();
+
+    void setUsePlatformMBeanServer(Boolean flag);
+
+    Boolean getUsePlatformMBeanServer();
+
+    Boolean getOnlyRegisterProcessorWithCustomId();
+
+    void setOnlyRegisterProcessorWithCustomId(Boolean onlyRegisterProcessorWithCustomId);
 }

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java
(from r950883, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRegisterEndpointTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRegisterEndpointTest.java&r1=950883&r2=950891&rev=950891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRegisterEndpointTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java
Thu Jun  3 07:12:04 2010
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.management;
 
-import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
@@ -26,7 +29,10 @@ import org.apache.camel.builder.RouteBui
 /**
  * @version $Revision$
  */
-public class ManagedRegisterEndpointTest extends ContextTestSupport {
+public class ManagedServiceUrlPathTest extends ContextTestSupport {
+
+    private static final String JMXSERVICEURL = "service:jmx:rmi:///jndi/rmi://localhost:2113/foo/bar";
+    private JMXConnector clientConnector;
 
     @Override
     protected boolean useJmx() {
@@ -39,11 +45,31 @@ public class ManagedRegisterEndpointTest
         DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context.getManagementStrategy().getManagementNamingStrategy();
         naming.setHostName("localhost");
         naming.setDomainName("org.apache.camel");
+
+        // START SNIPPET: e1
+        context.getManagementStrategy().getManagementAgent().setServiceUrlPath("/foo/bar");
+        context.getManagementStrategy().getManagementAgent().setRegistryPort(2113);
+        context.getManagementStrategy().getManagementAgent().setCreateConnector(true);
+        // END SNIPPET: e1
+
         return context;
     }
 
-    public void testLookupEndpointsByName() throws Exception {
-        MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        try {
+            if (clientConnector != null) {
+                clientConnector.close();
+            }
+        } catch (Throwable e) {
+            // ignore
+        }
+    }
+
+    public void testConnectToJmx() throws Exception {
+        clientConnector = JMXConnectorFactory.connect(new JMXServiceURL(JMXSERVICEURL), null);
+        MBeanServerConnection mbeanServer = clientConnector.getMBeanServerConnection();
 
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"direct://start\"");
         String uri = (String) mbeanServer.getAttribute(name, "EndpointUri");
@@ -74,4 +100,4 @@ public class ManagedRegisterEndpointTest
         };
     }
 
-}
+}
\ No newline at end of file



Mime
View raw message