import javax.management.Notification; //导入方法依赖的package包/类
public static void processNotification(MBeanServerConnection connection, Notification notification) {
echo("\n");
echo("\t" + DATE_FORMAT.format(Calendar.getInstance().getTime()) + "");
echo("\t" + DATE_FORMAT.format(new Date(notification.getTimeStamp())) + "");
echo("\t" + notification.getClass().getName() + "");
echo("\t" + notification.getSource() + "");
echo("\t" + notification.getType() + "");
echo("\t" + notification.getMessage() + "");
if (notification instanceof AttributeChangeNotification) {
echo("\t");
AttributeChangeNotification acn = (AttributeChangeNotification) notification;
echo("\t\t" + acn.getAttributeName() + "");
echo("\t\t" + acn.getAttributeType() + "");
echo("\t\t" + acn.getNewValue() + "");
echo("\t\t" + acn.getOldValue() + "");
echo("\t");
}
if (notification.getSource() instanceof ObjectName) {
GarbageCollectorMXBean gcBean = JMX.newMXBeanProxy(connection, (ObjectName) notification.getSource(), GarbageCollectorMXBean.class);
echo("\t");
echo("\t\t" + gcBean.getCollectionTime() + "");
echo("\t\t" + gcBean.getCollectionCount() + "");
GcInfo gcInfo = gcBean.getLastGcInfo();
echo("\t\t" + gcInfo.getStartTime() + "");
echo("\t\t" + gcInfo.getEndTime() + "");
echo("\t\t" + gcInfo.getDuration() + "");
outputMemoryUsages(gcInfo.getMemoryUsageBeforeGc(), "memoryUsageBeforeGC");
outputMemoryUsages(gcInfo.getMemoryUsageAfterGc(), "memoryUsageAfterGC");
echo("\t");
}
echo("\n");
}