cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r816895 - in /cxf/branches/2.2.x-fixes: ./ 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 Sat, 19 Sep 2009 11:50:59 GMT
Author: dkulp
Date: Sat Sep 19 11:50:57 2009
New Revision: 816895

URL: http://svn.apache.org/viewvc?rev=816895&view=rev
Log:
Merged revisions 816208 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r816208 | eglynn | 2009-09-17 10:24:54 -0400 (Thu, 17 Sep 2009) | 2 lines
  
  Allow a peristent Bus ID to be configured for instrumentation purposes.
........

Added:
    cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml
      - copied unchanged from r816208, cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/persistent-id.xml
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
    cxf/branches/2.2.x-fixes/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
    cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
    cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml

Propchange: cxf/branches/2.2.x-fixes/
            ('svn:mergeinfo' removed)

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java?rev=816895&r1=816894&r2=816895&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
Sat Sep 19 11:50:57 2009
@@ -91,4 +91,7 @@
      */
     MBeanServer getMBeanServer();
 
+    String getPersistentBusId();
+    
+    void setPersistentBusId(String id);
 }

Modified: cxf/branches/2.2.x-fixes/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java?rev=816895&r1=816894&r2=816895&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
Sat Sep 19 11:50:57 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/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java?rev=816895&r1=816894&r2=816895&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
Sat Sep 19 11:50:57 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/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml?rev=816895&r1=816894&r2=816895&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
(original)
+++ cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
Sat Sep 19 11:50:57 2009
@@ -33,4 +33,4 @@
         <property name="name" value="testQueue"/>
         <property name="highWaterMark" value="50"/>
     </bean>
-</beans>
\ No newline at end of file
+</beans>



Mime
View raw message