cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r816208 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/management/ rt/management/src/main/java/org/apache/cxf/management/jmx/ systests/uncategorized/src/test/java/org/apache/cxf/systest/management/
Date Thu, 17 Sep 2009 14:24:55 GMT
Author: eglynn
Date: Thu Sep 17 14:24:54 2009
New Revision: 816208

URL: http://svn.apache.org/viewvc?rev=816208&view=rev
Log:
Allow a peristent Bus ID to be configured for instrumentation purposes.

Added:
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java?rev=816208&r1=816207&r2=816208&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
Thu Sep 17 14:24:54 2009
@@ -91,4 +91,7 @@
      */
     MBeanServer getMBeanServer();
 
+    String getPersistentBusId();
+    
+    void setPersistentBusId(String id);
 }

Modified: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java?rev=816208&r1=816207&r2=816208&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
(original)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
Thu Sep 17 14:24:54 2009
@@ -65,6 +65,8 @@
     private MBeanServer mbs;
     private Set<ObjectName> busMBeans = new HashSet<ObjectName>();
     private boolean connectFailed;
+    private String persistentBusId;
+    
     /**
      * For backward compatibility, {@link #createMBServerConnectorFactory} is <code>true</code>
by default.
      */
@@ -164,7 +166,7 @@
         }
         //Try to register as a Standard MBean
         try {
-            registerMBeanWithServer(obj, name, forceRegistration);           
+            registerMBeanWithServer(obj, persist(name), forceRegistration);           
         } catch (NotCompliantMBeanException e) {        
             //If this is not a "normal" MBean, then try to deploy it using JMX annotations
             ModelMBeanAssembler assembler = new ModelMBeanAssembler();
@@ -189,7 +191,7 @@
     
     public void unregister(ManagedComponent component) throws JMException {
         ObjectName name = component.getObjectName();
-        unregister(name);
+        unregister(persist(name));
     }
     
     public void unregister(ObjectName name) throws JMException {  
@@ -255,7 +257,7 @@
         } catch (InvalidTargetObjectTypeException itotex) {
             throw new JMException(itotex.getMessage());
         }
-        registerMBeanWithServer(rtMBean, name, forceRegistration);
+        registerMBeanWithServer(rtMBean, persist(name), forceRegistration);
     }
 
     private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration)

@@ -276,7 +278,42 @@
             busMBeans.add(name);
         }
     }
-    
 
+    public String getPersistentBusId() {
+        return persistentBusId;
+    }
+
+    public void setPersistentBusId(String id) {
+        persistentBusId = sanitize(id);
+    }
+    
+    private ObjectName persist(ObjectName original) throws JMException {
+        ObjectName persisted = original;
+        if (!(persistentBusId == null 
+              || "".equals(persistentBusId) 
+              || persistentBusId.startsWith("${"))) {
+            String originalStr = original.toString();
+            if (originalStr.indexOf(ManagementConstants.BUS_ID_PROP) != -1) {
+                String persistedStr = 
+                    originalStr.replaceFirst(ManagementConstants.BUS_ID_PROP + "=" + bus.getId(),

+                                             ManagementConstants.BUS_ID_PROP + "=" + persistentBusId);
+                persisted = new ObjectName(persistedStr);
+            }
+        }
+        return persisted;
+    }
+    
+    private String sanitize(String in) {
+        String result = null;
+        if (in != null) {
+            result = in.replace(':', '_');
+            result = result.replace('/', '_');
+            result = result.replace('\\', '_');
+            result = result.replace('?', '_');
+            result = result.replace('=', '_');
+            result = result.replace(',', '_');
+        }
+        return result;
+    }
 }
 

Modified: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java?rev=816208&r1=816207&r2=816208&view=diff
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
(original)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
Thu Sep 17 14:24:54 2009
@@ -54,15 +54,27 @@
         
         bus.shutdown(true);
     }
-    
+        
     @Test
-    public void testManagedBusWithConfig() throws Exception {
+    public void testManagedBusWithTransientId() throws Exception {
         SpringBusFactory factory = new SpringBusFactory();
         Bus bus = factory.createBus("org/apache/cxf/systest/management/managed-spring.xml",
true);
+        doManagedBusTest(bus, bus.getId(), "cxf_managed_bus_test", 9916);
+    }
+    
+    @Test
+    public void testManagedBusWithPersistentId() throws Exception {
+        SpringBusFactory factory = new SpringBusFactory();
+        Bus bus = factory.createBus("org/apache/cxf/systest/management/persistent-id.xml",
true);
+        doManagedBusTest(bus, "cxf_managed_bus_test", bus.getId(), 9917);
+    }
+    
+    private void doManagedBusTest(Bus bus, String expect, String reject, int port) throws
Exception {
         InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
         assertNotNull(im);
         InstrumentationManagerImpl imi = (InstrumentationManagerImpl)im;
-        assertEquals("service:jmx:rmi:///jndi/rmi://localhost:9916/jmxrmi", imi.getJMXServiceURL());
+        assertEquals("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi",
+                     imi.getJMXServiceURL());
         assertTrue(imi.isEnabled());
         assertNotNull(imi.getMBeanServer());
 
@@ -75,6 +87,10 @@
         StringBuilder b = new StringBuilder();
         for (ObjectName o : CastUtils.cast(s, ObjectName.class)) {
             b.append(o.toString());
+            assertTrue("expected " + expect + " in object name: " + o,
+                       o.toString().indexOf("bus.id=" + expect + ",") != -1);
+            assertTrue("unexpected " + reject + " in object name: " + o,
+                       o.toString().indexOf("bus.id=" + reject + ",") == -1);
             b.append("\n");
         }
         assertEquals("Size is wrong: " + b.toString(), 1, s.size());
@@ -88,6 +104,10 @@
         b = new StringBuilder();
         for (ObjectName o : CastUtils.cast(s, ObjectName.class)) {
             b.append(o.toString());
+            assertTrue("expected " + expect + " in object name: " + o,
+                       o.toString().indexOf("bus.id=" + expect + ",") != -1);
+            assertTrue("unexpected " + reject + " in object name: " + o,
+                       o.toString().indexOf("bus.id=" + reject + ",") == -1);
             b.append("\n");
         }
         assertEquals("Size is wrong: " + b.toString(), 2, s.size());

Modified: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml?rev=816208&r1=816207&r2=816208&view=diff
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
(original)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
Thu Sep 17 14:24:54 2009
@@ -33,4 +33,4 @@
         <property name="name" value="testQueue"/>
         <property name="highWaterMark" value="50"/>
     </bean>
-</beans>
\ No newline at end of file
+</beans>

Added: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml?rev=816208&view=auto
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml
(added)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml
Thu Sep 17 14:24:54 2009
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+  
+    <bean id="org.apache.cxf.management.InstrumentationManager"
+        class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
+        <property name="bus" ref="cxf" />
+        <property name="enabled" value="true" />
+        <property name="JMXServiceURL" value="service:jmx:rmi:///jndi/rmi://localhost:9917/jmxrmi"
/>
+        <property name="persistentBusId" value="cxf:managed,bus=test" />
+    </bean> 
+ 
+    <bean id="wq" class="org.apache.cxf.workqueue.AutomaticWorkQueueImpl">
+        <property name="name" value="testQueue"/>
+        <property name="highWaterMark" value="50"/>
+    </bean>
+</beans>



Mime
View raw message