提交 e20ec9ce 编写于 作者: E emcmanus

6772779: @NotificationInfo does not create MBeanNotificationInfo in the MBean's MBeanInfo

6773593: CompositeDataSupport constructor javadoc is not in sync with the implementation
Reviewed-by: sjiang
上级 5f02c9c3
...@@ -70,6 +70,7 @@ import javax.management.JMRuntimeException; ...@@ -70,6 +70,7 @@ import javax.management.JMRuntimeException;
import javax.management.ListenerNotFoundException; import javax.management.ListenerNotFoundException;
import javax.management.MBeanException; import javax.management.MBeanException;
import javax.management.MBeanInfo; import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanPermission; import javax.management.MBeanPermission;
import javax.management.MBeanRegistration; import javax.management.MBeanRegistration;
import javax.management.MBeanRegistrationException; import javax.management.MBeanRegistrationException;
...@@ -1045,8 +1046,10 @@ public class DefaultMBeanServerInterceptor ...@@ -1045,8 +1046,10 @@ public class DefaultMBeanServerInterceptor
Object resource = getResource(mbean); Object resource = getResource(mbean);
MBeanInjector.inject(resource, mbs, name); MBeanInjector.inject(resource, mbs, name);
if (MBeanInjector.injectsSendNotification(resource)) { if (MBeanInjector.injectsSendNotification(resource)) {
MBeanNotificationInfo[] mbnis =
mbean.getMBeanInfo().getNotifications();
NotificationBroadcasterSupport nbs = NotificationBroadcasterSupport nbs =
new NotificationBroadcasterSupport(); new NotificationBroadcasterSupport(mbnis);
MBeanInjector.injectSendNotification(resource, nbs); MBeanInjector.injectSendNotification(resource, nbs);
mbean = NotifySupport.wrap(mbean, nbs); mbean = NotifySupport.wrap(mbean, nbs);
} }
......
...@@ -44,6 +44,7 @@ import javax.management.Descriptor; ...@@ -44,6 +44,7 @@ import javax.management.Descriptor;
import javax.management.ImmutableDescriptor; import javax.management.ImmutableDescriptor;
import javax.management.IntrospectionException; import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException; import javax.management.InvalidAttributeValueException;
import javax.management.JMX;
import javax.management.MBean; import javax.management.MBean;
import javax.management.MBeanAttributeInfo; import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo; import javax.management.MBeanConstructorInfo;
...@@ -538,21 +539,22 @@ abstract class MBeanIntrospector<M> { ...@@ -538,21 +539,22 @@ abstract class MBeanIntrospector<M> {
} }
static MBeanNotificationInfo[] findNotifications(Object moi) { static MBeanNotificationInfo[] findNotifications(Object moi) {
if (!(moi instanceof NotificationBroadcaster)) if (moi instanceof NotificationBroadcaster) {
return null; MBeanNotificationInfo[] mbn =
MBeanNotificationInfo[] mbn = ((NotificationBroadcaster) moi).getNotificationInfo();
((NotificationBroadcaster) moi).getNotificationInfo(); if (mbn != null && mbn.length > 0) {
if (mbn == null || mbn.length == 0) MBeanNotificationInfo[] result =
return findNotificationsFromAnnotations(moi.getClass()); new MBeanNotificationInfo[mbn.length];
MBeanNotificationInfo[] result = for (int i = 0; i < mbn.length; i++) {
new MBeanNotificationInfo[mbn.length]; MBeanNotificationInfo ni = mbn[i];
for (int i = 0; i < mbn.length; i++) { if (ni.getClass() != MBeanNotificationInfo.class)
MBeanNotificationInfo ni = mbn[i]; ni = (MBeanNotificationInfo) ni.clone();
if (ni.getClass() != MBeanNotificationInfo.class) result[i] = ni;
ni = (MBeanNotificationInfo) ni.clone(); }
result[i] = ni; return result;
}
} }
return result; return findNotificationsFromAnnotations(moi.getClass());
} }
private static MBeanNotificationInfo[] findNotificationsFromAnnotations( private static MBeanNotificationInfo[] findNotificationsFromAnnotations(
......
...@@ -101,7 +101,7 @@ public class CompositeDataSupport ...@@ -101,7 +101,7 @@ public class CompositeDataSupport
* the same size as <tt>itemNames</tt>; must not be null. * the same size as <tt>itemNames</tt>; must not be null.
* *
* @throws IllegalArgumentException <tt>compositeType</tt> is null, or * @throws IllegalArgumentException <tt>compositeType</tt> is null, or
* <tt>itemNames[]</tt> or <tt>itemValues[]</tt> is null or empty, or one * <tt>itemNames[]</tt> or <tt>itemValues[]</tt> is null, or one
* of the elements in <tt>itemNames[]</tt> is a null or empty string, or * of the elements in <tt>itemNames[]</tt> is a null or empty string, or
* <tt>itemNames[]</tt> and <tt>itemValues[]</tt> are not of the same size. * <tt>itemNames[]</tt> and <tt>itemValues[]</tt> are not of the same size.
* *
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
*/ */
/* /*
* @test %M% %I% * @test
* @bug 6323980 * @bug 6323980 6772779
* @summary Test &#64;NotificationInfo annotation * @summary Test &#64;NotificationInfo annotation
* @author Eamonn McManus * @author Eamonn McManus
* @run main/othervm -ea AnnotatedNotificationInfoTest * @run main/othervm -ea AnnotatedNotificationInfoTest
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
import java.io.Serializable; import java.io.Serializable;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.management.AttributeChangeNotification; import javax.management.AttributeChangeNotification;
import javax.management.Description; import javax.management.Description;
...@@ -134,6 +135,23 @@ public class AnnotatedNotificationInfoTest { ...@@ -134,6 +135,23 @@ public class AnnotatedNotificationInfoTest {
private static Object mbeanIntf5 = new Intf5Impl(); private static Object mbeanIntf5 = new Intf5Impl();
@NotificationInfo(
types = {"foo", "bar"},
notificationClass = AttributeChangeNotification.class,
description = @Description(
value = "description",
bundleBaseName = "bundle",
key = "key"),
descriptorFields = {"foo=bar"})
public static interface Intf6MBean {}
public static class Intf6 implements Intf6MBean {
@Resource
private volatile SendNotification send;
}
private static Object mbeanIntf6 = new Intf6();
public static interface Impl1MBean {} public static interface Impl1MBean {}
@NotificationInfo( @NotificationInfo(
...@@ -202,22 +220,21 @@ public class AnnotatedNotificationInfoTest { ...@@ -202,22 +220,21 @@ public class AnnotatedNotificationInfoTest {
private static Object mbeanMBean2 = new MBean2(); private static Object mbeanMBean2 = new MBean2();
// Following disabled until we support it @MBean
// @MBean @NotificationInfo(
// @NotificationInfo( types = {"foo", "bar"},
// types = {"foo", "bar"}, notificationClass = AttributeChangeNotification.class,
// notificationClass = AttributeChangeNotification.class, description = @Description(
// description = @Description( value = "description",
// value = "description", bundleBaseName = "bundle",
// bundleBaseName = "bundle", key = "key"),
// key = "key"), descriptorFields = {"foo=bar"})
// descriptorFields = {"foo=bar"}) public static class MBean3 {
// public static class MBean3 { @Resource
// @Resource private volatile SendNotification send;
// private volatile SendNotification send; }
// }
// private static Object mbeanMBean3 = new MBean3();
// private static Object mbeanMBean3 = new MBean3();
@MXBean @MXBean
@NotificationInfo( @NotificationInfo(
...@@ -237,6 +254,23 @@ public class AnnotatedNotificationInfoTest { ...@@ -237,6 +254,23 @@ public class AnnotatedNotificationInfoTest {
private static Object mbeanMXBean2 = new MXBean2(); private static Object mbeanMXBean2 = new MXBean2();
// Classes for the second test. This tests the simplest case, which is
// the first example in the javadoc for @NotificationInfo. Notice that
// this MBean is not a NotificationBroadcaster and does not inject a
// SendNotification! That should possibly be an error, but it's currently
// allowed by the spec.
@NotificationInfo(types={"com.example.notifs.create",
"com.example.notifs.destroy"})
public static interface CacheMBean {
public int getCachedNum();
}
public static class Cache implements CacheMBean {
public int getCachedNum() {
return 0;
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if (!AnnotatedNotificationInfoTest.class.desiredAssertionStatus()) if (!AnnotatedNotificationInfoTest.class.desiredAssertionStatus())
throw new Exception("Test must be run with -ea"); throw new Exception("Test must be run with -ea");
...@@ -267,5 +301,14 @@ public class AnnotatedNotificationInfoTest { ...@@ -267,5 +301,14 @@ public class AnnotatedNotificationInfoTest {
assert mbnis[0].equals(expected) : mbnis[0]; assert mbnis[0].equals(expected) : mbnis[0];
mbs.unregisterMBean(on); mbs.unregisterMBean(on);
} }
mbs.registerMBean(new Cache(), on);
MBeanInfo mbi = mbs.getMBeanInfo(on);
MBeanNotificationInfo[] mbnis = mbi.getNotifications();
assert mbnis.length == 1 : mbnis.length;
String[] types = mbnis[0].getNotifTypes();
String[] expectedTypes =
CacheMBean.class.getAnnotation(NotificationInfo.class).types();
assert Arrays.equals(types, expectedTypes) : Arrays.toString(types);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册