cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1221813 - in /cxf/trunk/rt/management/src: main/java/org/apache/cxf/management/jmx/ test/java/org/apache/cxf/management/ test/java/org/apache/cxf/management/jmx/ test/resources/
Date Wed, 21 Dec 2011 17:16:29 GMT
Author: ay
Date: Wed Dec 21 17:16:28 2011
New Revision: 1221813

URL: http://svn.apache.org/viewvc?rev=1221813&view=rev
Log:
[CXF-3992] making jmx instrumentation manager configurable using some bus properties

Added:
    cxf/trunk/rt/management/src/test/resources/managed-spring-twobuses2.xml   (with props)
    cxf/trunk/rt/management/src/test/resources/managed-spring2.xml   (with props)
Modified:
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
    cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
    cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/BusRegistrationTest.java

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=1221813&r1=1221812&r2=1221813&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
Wed Dec 21 17:16:28 2011
@@ -30,7 +30,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.JMException;
 import javax.management.MBeanServer;
@@ -84,12 +83,35 @@ public class InstrumentationManagerImpl 
         super();
     }
     
+    public InstrumentationManagerImpl(Bus bus) {
+        this();
+        readJMXProperties(bus);
+        this.bus = bus;
+    }
+    
     public Bus getBus() {
         return bus;
     }
 
-    @Resource
-    public void setBus(Bus bus) {        
+    public void setBus(Bus bus) {
+        if (this.bus == null) {
+            readJMXProperties(bus);
+        } else {
+            // possibly this bus was reassigned from another im bean
+            InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
+            if (this != im) {
+                bus.setExtension(this, InstrumentationManager.class);
+                try {
+                    ManagedBus mbus = new ManagedBus(bus);
+                    im.unregister(mbus);
+                    if (LOG.isLoggable(Level.INFO)) {
+                        LOG.info("unregistered " + mbus.getObjectName());
+                    }
+                } catch (JMException e) {
+                    // ignore
+                }
+            }
+        }
         this.bus = bus;
     }
 
@@ -169,6 +191,9 @@ public class InstrumentationManagerImpl 
                     //infrastructure has been initialized.
                     ManagedBus mbus = new ManagedBus(bus);                    
                     register(mbus);
+                    if (LOG.isLoggable(Level.INFO)) {
+                        LOG.info("registered " + mbus.getObjectName());
+                    }
                 } catch (JMException jmex) {
                     LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new Object[]{bus, jmex});
                 }
@@ -361,5 +386,26 @@ public class InstrumentationManagerImpl 
         }
         return str.toString();
     }
+    
+    private void readJMXProperties(Bus b) {
+        if (b != null) {
+            persistentBusId = getBusProperty(b, "bus.jmx.persistentBusId", null);
+            mbeanServerName = 
+                getBusProperty(b, "bus.jmx.serverName", ManagementConstants.DEFAULT_DOMAIN_NAME);
+            usePlatformMBeanServer = 
+                Boolean.valueOf(getBusProperty(b, "bus.jmx.usePlatformMBeanServer", null));
+            createMBServerConnectorFactory = 
+                Boolean.valueOf(getBusProperty(b, "bus.jmx.createMBServerConnectorFactory",
null));
+            daemon = Boolean.valueOf(getBusProperty(b, "bus.jmx.daemon", null));
+            threaded = Boolean.valueOf(getBusProperty(b, "bus.jmx.threaded", null));
+            enabled = Boolean.valueOf(getBusProperty(b, "bus.jmx.enabled", null));
+            jmxServiceURL = getBusProperty(b, "bus.jmx.JMXServiceURL", null);
+        }
+    }
+
+    private static String getBusProperty(Bus b, String key, String dflt) {
+        String v = (String)b.getProperty(key);
+        return v != null ? v : dflt;
+    }
 }
 

Modified: cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java?rev=1221813&r1=1221812&r2=1221813&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
(original)
+++ cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
Wed Dec 21 17:16:28 2011
@@ -27,6 +27,7 @@ import javax.management.ObjectName;
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.management.counters.CounterRepository;
+import org.apache.cxf.management.jmx.InstrumentationManagerImpl;
 import org.apache.cxf.workqueue.WorkQueueManagerImpl;
 
 import org.junit.After;
@@ -133,5 +134,41 @@ public class InstrumentationManagerTest 
         }
     }
     
+    @Test
+    public void testInstrumentBusWithBusProperties() {
+        ClassPathXmlApplicationContext context = null;
+        Bus cxf1 = null;
+        Bus cxf2 = null;
+        try {
+            context = new ClassPathXmlApplicationContext("managed-spring-twobuses2.xml");
+
+            cxf1 = (Bus)context.getBean("cxf1");
+            InstrumentationManagerImpl im1 = 
+                (InstrumentationManagerImpl)cxf1.getExtension(InstrumentationManager.class);
+            assertNotNull("Instrumentation Manager of cxf1 should not be null", im1);
+            
+            assertTrue(im1.isEnabled());
+            assertEquals("service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi", im1.getJMXServiceURL());
+            
+            cxf2 = (Bus)context.getBean("cxf2");
+            InstrumentationManagerImpl im2 = 
+                (InstrumentationManagerImpl)cxf2.getExtension(InstrumentationManager.class);
+            assertNotNull("Instrumentation Manager of cxf2 should not be null", im2);
+
+            assertFalse(im2.isEnabled());
+            assertEquals("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi", im2.getJMXServiceURL());
+            
+        } finally {
+            if (cxf1 != null) {
+                cxf1.shutdown(true);
+            }
+            if (cxf2 != null) {
+                cxf2.shutdown(true);
+            }
+            if (context != null) {
+                context.close();
+            }
+        }
+    }
 
 }

Modified: cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/BusRegistrationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/BusRegistrationTest.java?rev=1221813&r1=1221812&r2=1221813&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/BusRegistrationTest.java
(original)
+++ cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/BusRegistrationTest.java
Wed Dec 21 17:16:28 2011
@@ -35,6 +35,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+
 /**
  * 
  */
@@ -62,9 +63,19 @@ public class BusRegistrationTest extends
 
     @Test
     public void testRegisterMultipleBuses() throws Exception {
-        final SpringBusFactory factory = new SpringBusFactory();
+        // classic external IM-bean
+        testRegisterMultipleBuses("managed-spring.xml");
+    }
 
-        serverBus =  factory.createBus("managed-spring.xml");
+    @Test
+    public void testRegisterMultipleBuses2() throws Exception {
+        // integrated IM configuration in bus
+        testRegisterMultipleBuses("managed-spring2.xml");
+    }
+    
+    private void testRegisterMultipleBuses(String conf) throws Exception {
+        final SpringBusFactory factory = new SpringBusFactory();
+        serverBus =  factory.createBus(conf);
         assertEquals("CXF-Test-Bus", serverBus.getId());
         serverIM = serverBus.getExtension(InstrumentationManager.class);
         assertTrue("Instrumentation Manager should not be null", serverIM != null);
@@ -114,13 +125,17 @@ public class BusRegistrationTest extends
         }
     }
     
+        
     private static ObjectName getObjectName(Bus bus) throws JMException {
         String busId = bus.getId();
+        return getObjectName(busId);
+    }
+
+    private static ObjectName getObjectName(String id) throws JMException {
         StringBuilder buffer = new StringBuilder(ManagementConstants.DEFAULT_DOMAIN_NAME
+ ":");
-        buffer.append(ManagementConstants.BUS_ID_PROP + "=" +  busId + ",");
+        buffer.append(ManagementConstants.BUS_ID_PROP + "=" +  id + ",");
         buffer.append(ManagementConstants.TYPE_PROP + "=Bus");
         
         return new ObjectName(buffer.toString());
     }
-
 }

Added: cxf/trunk/rt/management/src/test/resources/managed-spring-twobuses2.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/resources/managed-spring-twobuses2.xml?rev=1221813&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/rt/management/src/test/resources/managed-spring-twobuses2.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/rt/management/src/test/resources/managed-spring-twobuses2.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: cxf/trunk/rt/management/src/test/resources/managed-spring2.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/resources/managed-spring2.xml?rev=1221813&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/rt/management/src/test/resources/managed-spring2.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/rt/management/src/test/resources/managed-spring2.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml



Mime
View raw message