Author: dkulp
Date: Tue Apr 6 20:19:35 2010
New Revision: 931302
URL: http://svn.apache.org/viewvc?rev=931302&view=rev
Log:
Merged revisions 931192 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r931192 | dvaleri | 2010-04-06 11:51:36 -0400 (Tue, 06 Apr 2010) | 1 line
[CXF-2742] Changed InstrumentationManager to cleanup connectors on shutdown.
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
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/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=931302&r1=931301&r2=931302&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
Tue Apr 6 20:19:35 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/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java?rev=931302&r1=931301&r2=931302&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
Tue Apr 6 20:19:35 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/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java?rev=931302&r1=931301&r2=931302&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
Tue Apr 6 20:19:35 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;
+ }
}