servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r827585 - in /servicemix/smx4/nmr/trunk/nmr/management/src: main/java/org/apache/servicemix/nmr/management/ManagementAgent.java test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java
Date Tue, 20 Oct 2009 14:45:18 GMT
Author: eglynn
Date: Tue Oct 20 14:45:18 2009
New Revision: 827585

URL: http://svn.apache.org/viewvc?rev=827585&view=rev
Log:
Fix for [SMX4NMR-65]   ServiceMix NMR NotCompliantMBeanException when ManagedEndpoint registered
via ManagementStrategy

Modified:
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java?rev=827585&r1=827584&r2=827585&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java
(original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java
Tue Oct 20 14:45:18 2009
@@ -20,6 +20,7 @@
 import java.util.EventObject;
 import java.util.Set;
 import java.util.HashSet;
+import java.lang.reflect.UndeclaredThrowableException;
 
 import javax.jbi.component.ComponentContext;
 import javax.management.InstanceNotFoundException;
@@ -229,28 +230,32 @@
     public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException
{
         try {
             registerMBeanWithServer(obj, name, forceRegistration);
-        } catch (UndeclaredThrowableException e) {
-        	if (e.getCause() instanceof NotCompliantMBeanException) {
-        		setModelMBeanInfo(obj, name, forceRegistration);
-        	}
-        } catch (NotCompliantMBeanException e1) {
-        	setModelMBeanInfo(obj, name, forceRegistration);
+        } catch (NotCompliantMBeanException e) {
+            registerViaAnnotations(obj, name, forceRegistration);
+        } catch (UndeclaredThrowableException ute) {
+            if (ute.getCause() instanceof NotCompliantMBeanException) {
+                registerViaAnnotations(obj, name, forceRegistration);
+            } else if (ute.getCause() instanceof RuntimeException) {
+                throw (RuntimeException)ute.getCause();
+            } else {
+                throw new JMException(ute.getCause().getMessage());
+            }
         }
     }
 
-	private void setModelMBeanInfo(Object obj, ObjectName name,
-			boolean forceRegistration) throws JMException, ReflectionException,
-			MBeanException, InstanceNotFoundException {
-		ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString());
-		RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer.instantiate(RequiredModelMBean.class.getName());
-		mbean.setModelMBeanInfo(mbi);
-		try {
-			mbean.setManagedResource(obj, "ObjectReference");
-		} catch (InvalidTargetObjectTypeException itotex) {
-			throw new JMException(itotex.getMessage());
-		}
-		registerMBeanWithServer(mbean, name, forceRegistration);
-	}
+    protected void registerViaAnnotations(Object obj, ObjectName name, boolean forceRegistration)
throws JMException {
+        // If this is not a "normal" MBean, then try to deploy it using JMX
+        // annotations
+        ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString());
+        RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer.instantiate(RequiredModelMBean.class.getName());
+        mbean.setModelMBeanInfo(mbi);
+        try {
+            mbean.setManagedResource(obj, "ObjectReference");
+        } catch (InvalidTargetObjectTypeException itotex) {
+            throw new JMException(itotex.getMessage());
+        }
+        registerMBeanWithServer(mbean, name, forceRegistration);
+    }
 
     public void unregister(ObjectName name) throws JMException {
         mbeanServer.unregisterMBean(name);

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java?rev=827585&r1=827584&r2=827585&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java
(original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java
Tue Oct 20 14:45:18 2009
@@ -18,6 +18,8 @@
 
 import java.util.EventObject;
 import java.util.HashMap;
+import java.lang.reflect.UndeclaredThrowableException;
+
 
 import javax.management.MBeanServer;
 import javax.management.NotCompliantMBeanException;
@@ -273,6 +275,16 @@
 
     @Test
     public void testRepeatManageManagedEndpoint() throws Exception {
+        doTestManageManagedEndpoint(new NotCompliantMBeanException());
+    }
+
+    @Test
+    public void testManageManagedEndpointWithUndeclaredThrowable() throws Exception {
+        Exception ex = new NotCompliantMBeanException();
+        doTestManageManagedEndpoint(new UndeclaredThrowableException(ex));
+    }
+
+    private void doTestManageManagedEndpoint(Exception ex) throws Exception {
         ObjectName name = new ObjectName(ENDPOINT_NAME);
         ObjectInstance instance = new ObjectInstance(name, Nameable.class.getName());
         InternalEndpoint internal = control.createMock(InternalEndpoint.class);
@@ -280,7 +292,6 @@
         ManagedEndpoint endpoint = 
             new ManagedEndpoint(internal, props, strategy);
         expect(internal.getId()).andReturn("endpoint_foo");
-        Exception ex = new NotCompliantMBeanException();
         expect(mbeanServer.registerMBean(isA(ManagedEndpoint.class), eq(name))).andThrow(ex);
         RequiredModelMBean mbean = control.createMock(RequiredModelMBean.class);
         expect(mbeanServer.instantiate(RequiredModelMBean.class.getName())).andReturn(mbean);



Mime
View raw message