提交 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;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanPermission;
import javax.management.MBeanRegistration;
import javax.management.MBeanRegistrationException;
......@@ -1045,8 +1046,10 @@ public class DefaultMBeanServerInterceptor
Object resource = getResource(mbean);
MBeanInjector.inject(resource, mbs, name);
if (MBeanInjector.injectsSendNotification(resource)) {
MBeanNotificationInfo[] mbnis =
mbean.getMBeanInfo().getNotifications();
NotificationBroadcasterSupport nbs =
new NotificationBroadcasterSupport();
new NotificationBroadcasterSupport(mbnis);
MBeanInjector.injectSendNotification(resource, nbs);
mbean = NotifySupport.wrap(mbean, nbs);
}
......
......@@ -44,6 +44,7 @@ import javax.management.Descriptor;
import javax.management.ImmutableDescriptor;
import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.JMX;
import javax.management.MBean;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
......@@ -538,21 +539,22 @@ abstract class MBeanIntrospector<M> {
}
static MBeanNotificationInfo[] findNotifications(Object moi) {
if (!(moi instanceof NotificationBroadcaster))
return null;
MBeanNotificationInfo[] mbn =
((NotificationBroadcaster) moi).getNotificationInfo();
if (mbn == null || mbn.length == 0)
return findNotificationsFromAnnotations(moi.getClass());
MBeanNotificationInfo[] result =
new MBeanNotificationInfo[mbn.length];
for (int i = 0; i < mbn.length; i++) {
MBeanNotificationInfo ni = mbn[i];
if (ni.getClass() != MBeanNotificationInfo.class)
ni = (MBeanNotificationInfo) ni.clone();
result[i] = ni;
if (moi instanceof NotificationBroadcaster) {
MBeanNotificationInfo[] mbn =
((NotificationBroadcaster) moi).getNotificationInfo();
if (mbn != null && mbn.length > 0) {
MBeanNotificationInfo[] result =
new MBeanNotificationInfo[mbn.length];
for (int i = 0; i < mbn.length; i++) {
MBeanNotificationInfo ni = mbn[i];
if (ni.getClass() != MBeanNotificationInfo.class)
ni = (MBeanNotificationInfo) ni.clone();
result[i] = ni;
}
return result;
}
}
return result;
return findNotificationsFromAnnotations(moi.getClass());
}
private static MBeanNotificationInfo[] findNotificationsFromAnnotations(
......
......@@ -101,7 +101,7 @@ public class CompositeDataSupport
* the same size as <tt>itemNames</tt>; must not be null.
*
* @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
* <tt>itemNames[]</tt> and <tt>itemValues[]</tt> are not of the same size.
*
......
......@@ -22,8 +22,8 @@
*/
/*
* @test %M% %I%
* @bug 6323980
* @test
* @bug 6323980 6772779
* @summary Test &#64;NotificationInfo annotation
* @author Eamonn McManus
* @run main/othervm -ea AnnotatedNotificationInfoTest
......@@ -32,6 +32,7 @@
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.util.Arrays;
import javax.annotation.Resource;
import javax.management.AttributeChangeNotification;
import javax.management.Description;
......@@ -134,6 +135,23 @@ public class AnnotatedNotificationInfoTest {
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 {}
@NotificationInfo(
......@@ -202,22 +220,21 @@ public class AnnotatedNotificationInfoTest {
private static Object mbeanMBean2 = new MBean2();
// Following disabled until we support it
// @MBean
// @NotificationInfo(
// types = {"foo", "bar"},
// notificationClass = AttributeChangeNotification.class,
// description = @Description(
// value = "description",
// bundleBaseName = "bundle",
// key = "key"),
// descriptorFields = {"foo=bar"})
// public static class MBean3 {
// @Resource
// private volatile SendNotification send;
// }
//
// private static Object mbeanMBean3 = new MBean3();
@MBean
@NotificationInfo(
types = {"foo", "bar"},
notificationClass = AttributeChangeNotification.class,
description = @Description(
value = "description",
bundleBaseName = "bundle",
key = "key"),
descriptorFields = {"foo=bar"})
public static class MBean3 {
@Resource
private volatile SendNotification send;
}
private static Object mbeanMBean3 = new MBean3();
@MXBean
@NotificationInfo(
......@@ -237,6 +254,23 @@ public class AnnotatedNotificationInfoTest {
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 {
if (!AnnotatedNotificationInfoTest.class.desiredAssertionStatus())
throw new Exception("Test must be run with -ea");
......@@ -267,5 +301,14 @@ public class AnnotatedNotificationInfoTest {
assert mbnis[0].equals(expected) : mbnis[0];
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.
先完成此消息的编辑!
想要评论请 注册