cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dval...@apache.org
Subject svn commit: r931192 - in /cxf/trunk/rt/management/src: main/java/org/apache/cxf/management/jmx/ test/java/org/apache/cxf/management/jmx/
Date Tue, 06 Apr 2010 15:51:37 GMT
Author: dvaleri
Date: Tue Apr  6 15:51:36 2010
New Revision: 931192

URL: http://svn.apache.org/viewvc?rev=931192&view=rev
Log:
[CXF-2742] Changed InstrumentationManager to cleanup connectors on shutdown.

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/jmx/HelloWorld.java
    cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.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=931192&r1=931191&r2=931192&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
Tue Apr  6 15:51:36 2010
@@ -223,18 +223,7 @@ public class InstrumentationManagerImpl 
                 LOG.log(Level.SEVERE, "STOP_CONNECTOR_FAILURE_MSG", new Object[] {ex});
             }
         }
-    }
-
-    public void initComplete() {
         
-    }
-    
-    public void preShutdown() {
-                
-    }
-    
-   
-    public void postShutdown() {
         //Using the array to hold the busMBeans to avoid the CurrentModificationException
         Object[] mBeans = busMBeans.toArray();
         for (Object name : mBeans) {
@@ -246,6 +235,18 @@ public class InstrumentationManagerImpl 
             }
         }
     }
+
+    public void initComplete() {
+        
+    }
+    
+    public void preShutdown() {
+                
+    }
+   
+    public void postShutdown() {
+        this.shutdown();
+    }
     
     private void register(Object obj, ObjectName name, ModelMBeanInfo mbi, boolean forceRegistration)

         throws JMException {                  

Modified: cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java?rev=931192&r1=931191&r2=931192&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java (original)
+++ cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java Tue
Apr  6 15:51:36 2010
@@ -20,7 +20,13 @@
 package org.apache.cxf.management.jmx;
 
 public class HelloWorld implements HelloWorldMBean {
+    private String name;
+    
+    public HelloWorld(String name) {
+        this.name = name;
+    }
+    
     public String sayHi() {
-        return "Wazzzuuup!";
+        return "Wazzzuuup " + this.name;
     }
 }

Modified: cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java?rev=931192&r1=931191&r2=931192&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
(original)
+++ cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
Tue Apr  6 15:51:36 2010
@@ -19,7 +19,12 @@
 
 package org.apache.cxf.management.jmx;
 
+import java.lang.management.ManagementFactory;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
 import javax.management.JMException;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation;
@@ -101,12 +106,79 @@ public class JMXManagedComponentManagerT
 
     @Test
     public void testRegisterStandardMBean() throws Exception {
-        HelloWorld hw = new HelloWorld();
-        ObjectName name = new ObjectName("org.apache.cxf:type=foo,name=bar");
-        manager.register(hw, name);
+        ObjectName name = this.registerStandardMBean("yo!");
         String result = 
             (String)manager.getMBeanServer().invoke(name, "sayHi", new Object[0], new String[0]);
   
-        assertEquals("Wazzzuuup!", result);
+        assertEquals("Wazzzuuup yo!", result);
+    }
+    
+    /**
+     * Simulate repeated startup and shutdown of the CXF Bus in an environment
+     * where the container and MBeanServer are not shutdown between CXF restarts.
+     */
+    @Test
+    public void testBusLifecycleListener() throws Exception {
+        // We need to destroy the manager that is automatically setup by the test.
+        this.tearDown();
+        
+        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        
+        this.manager = new InstrumentationManagerImpl(); 
+        this.manager.setDaemon(false);
+        // Turn threading off so that we get the exception in this thread
+        // and the manager is set into a failed state if the connector
+        // cannot be created.
+        this.manager.setThreaded(false);
+        this.manager.setEnabled(true);
+        this.manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+        this.manager.setServer(server);
+        this.manager.register();
+        this.manager.init();
+        
+        ObjectName name = this.registerStandardMBean("yo!");
+        String result = 
+            (String)manager.getMBeanServer().invoke(name, "sayHi", new Object[0], new String[0]);
   
+        assertEquals("Wazzzuuup yo!", result);
+        
+        try {
+            name = this.registerStandardMBean("yo!");
+            fail("registered duplicate MBean");
+        } catch (InstanceAlreadyExistsException e) {
+            // expected
+        }
+        
+        this.manager.preShutdown();
+        this.manager.postShutdown();
+        
+        try {
+            this.manager.getMBeanServer().invoke(name, "sayHi", new Object[0], new String[0]);
+            fail("MBean not unregistered on shutdown.");
+        } catch (InstanceNotFoundException e) {
+            // expected
+        }
+        
+        this.manager = new InstrumentationManagerImpl(); 
+        this.manager.setDaemon(false);
+        // Turn threading off so that we get the exception in this thread
+        // and the manager is set into a failed state if the connector
+        // cannot be created.
+        this.manager.setThreaded(false);
+        this.manager.setEnabled(true);
+        this.manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+        this.manager.setServer(server);
+        this.manager.register();
+        this.manager.init();
+        
+        name = this.registerStandardMBean("yoyo!");
+        result = 
+            (String)manager.getMBeanServer().invoke(name, "sayHi", new Object[0], new String[0]);
   
+        assertEquals("Wazzzuuup yoyo!", result);
     }
     
+    private ObjectName registerStandardMBean(String name) throws Exception {
+        final HelloWorld hw = new HelloWorld(name);
+        final ObjectName oName = new ObjectName("org.apache.cxf:type=foo,name=bar");
+        this.manager.register(hw, oName);
+        return oName;
+    }
 }



Mime
View raw message