类javax.management.Attribute源码实例Demo

下面列出了怎么用javax.management.Attribute的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Tomcat8-Source-Read   文件: JMXAccessorSetTask.java
/**
 * Set property value.
 *
 * @param jmxServerConnection Connection to the JMX server
 * @param name The MBean name
 * @return null (no error message to report other than exception)
 * @throws Exception An error occurred
 */
protected String jmxSet(MBeanServerConnection jmxServerConnection,
        String name) throws Exception {
    Object realValue;
    if (type != null) {
        realValue = convertStringToType(value, type);
    } else {
        if (isConvert()) {
            String mType = getMBeanAttributeType(jmxServerConnection, name,
                    attribute);
            realValue = convertStringToType(value, mType);
        } else
            realValue = value;
    }
    jmxServerConnection.setAttribute(new ObjectName(name), new Attribute(
            attribute, realValue));
    return null;
}
 
源代码2 项目: openjdk-jdk8u   文件: RMIConnector.java
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
源代码3 项目: vjtools   文件: JmxClient.java
private synchronized NameValueMap getCachedAttributes(ObjectName objName, Set<String> attrNames)
		throws InstanceNotFoundException, ReflectionException, IOException {
	NameValueMap values = cachedValues.get(objName);
	if (values != null && values.keySet().containsAll(attrNames)) {
		return values;
	}
	attrNames = new TreeSet<String>(attrNames);
	Set<String> oldNames = cachedNames.get(objName);
	if (oldNames != null) {
		attrNames.addAll(oldNames);
	}
	values = new NameValueMap();
	final AttributeList attrs = conn.getAttributes(objName, attrNames.toArray(new String[attrNames.size()]));
	for (Attribute attr : attrs.asList()) {
		values.put(attr.getName(), attr.getValue());
	}
	cachedValues.put(objName, values);
	cachedNames.put(objName, attrNames);
	return values;
}
 
源代码4 项目: dragonwell8_jdk   文件: RMIConnector.java
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
源代码6 项目: TencentKona-8   文件: RMIConnector.java
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
源代码7 项目: Tomcat8-Source-Read   文件: JMXProxyServlet.java
/**
 * Sets an MBean attribute's value.
 */
private void setAttributeInternal(String onameStr, String attributeName, String value)
        throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    String type = registry.getType(oname, attributeName);
    Object valueObj = registry.convertValue(type, value);
    mBeanServer.setAttribute(oname, new Attribute(attributeName, valueObj));
}
 
源代码8 项目: openjdk-jdk8u   文件: MBeanExceptionTest.java
public void setAttribute(Attribute attr)
        throws MBeanException {
    String attrName = attr.getName();
    if (attrName.equals("UncheckedException"))
        throw theUncheckedException;
    else
        throw new AssertionError();
}
 
源代码9 项目: jdk8u60   文件: MXBeanProxy.java
@Override
Object invoke(MBeanServerConnection mbsc, ObjectName name, Object[] args)
        throws Exception {
    assert(args.length == 1);
    Attribute attr = new Attribute(getName(), args[0]);
    mbsc.setAttribute(name, attr);
    return null;
}
 
源代码10 项目: vjtools   文件: Client.java
protected static Object doAttributeOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command,
		MBeanAttributeInfo[] infos) throws Exception {
	// Usually we get attributes. If an argument, then we're being asked
	// to set attribute.
	CommandParse parse = new CommandParse(command);
	if (parse.getArgs() == null || parse.getArgs().length == 0) {
		// Special-casing. If the subCommand is 'Attributes', then return
		// list of all attributes.
		if (command.equals("Attributes")) {
			String[] names = new String[infos.length];
			for (int i = 0; i < infos.length; i++) {
				names[i] = infos[i].getName();
			}
			return mbsc.getAttributes(instance.getObjectName(), names);
		}
		return mbsc.getAttribute(instance.getObjectName(), parse.getCmd());
	}
	if (parse.getArgs().length != 1) {
		throw new IllegalArgumentException("One only argument setting " + "attribute values: " + parse.getArgs());
	}
	// Get first attribute of name 'cmd'. Assumption is no method
	// overrides. Then, look at the attribute and use its type.
	MBeanAttributeInfo info = (MBeanAttributeInfo) getFeatureInfo(infos, parse.getCmd());
	java.lang.reflect.Constructor c = Class.forName(info.getType()).getConstructor(new Class[] { String.class });
	Attribute a = new Attribute(parse.getCmd(), c.newInstance(new Object[] { parse.getArgs()[0] }));
	mbsc.setAttribute(instance.getObjectName(), a);
	return null;
}
 
源代码11 项目: presto   文件: JmxRecordSetProvider.java
private ImmutableMap<String, Optional<Object>> getAttributes(Set<String> uniqueColumnNames, String name)
        throws JMException
{
    ObjectName objectName = new ObjectName(name);

    String[] columnNamesArray = uniqueColumnNames.toArray(new String[uniqueColumnNames.size()]);

    ImmutableMap.Builder<String, Optional<Object>> attributes = ImmutableMap.builder();
    for (Attribute attribute : mbeanServer.getAttributes(objectName, columnNamesArray).asList()) {
        attributes.put(attribute.getName(), Optional.ofNullable(attribute.getValue()));
    }
    return attributes.build();
}
 
@Nullable
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
		throws JMException, IOException {

	Assert.state(this.serverToUse != null, "No MBeanServerConnection available");

	String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
	MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
	// If no attribute is returned, we know that it is not defined in the
	// management interface.
	if (inf == null) {
		throw new InvalidInvocationException(
				"Attribute '" + pd.getName() + "' is not exposed on the management interface");
	}

	if (invocation.getMethod().equals(pd.getReadMethod())) {
		if (inf.isReadable()) {
			return this.serverToUse.getAttribute(this.objectName, attributeName);
		}
		else {
			throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
		}
	}
	else if (invocation.getMethod().equals(pd.getWriteMethod())) {
		if (inf.isWritable()) {
			this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
			return null;
		}
		else {
			throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
		}
	}
	else {
		throw new IllegalStateException(
				"Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
	}
}
 
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameBeforeObjectNameMappedToSameBeanInstance() throws Exception {
	String beanName = "testBean";
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");

	SelfNamingTestBean testBean = new SelfNamingTestBean();
	testBean.setObjectName(objectName);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerSingleton(beanName, testBean);

	Map<String, Object> beans = new HashMap<>();
	beans.put(beanName, testBean);

	Map listenerMappings = new HashMap();
	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
	listenerMappings.put(beanName, listener);
	listenerMappings.put(objectName, listener);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setNotificationListenerMappings(listenerMappings);
	exporter.setBeanFactory(factory);
	start(exporter);
	assertIsRegistered("Should have registered MBean", objectName);

	server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
	assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
}
 
源代码14 项目: TencentKona-8   文件: MBeanSupport.java
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
源代码15 项目: openjdk-jdk8u   文件: OldMBeanServerTest.java
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList list = new AttributeList();
    // We carefully avoid using any new stuff from AttributeList here!
    for (Iterator<?> it = attributes.iterator(); it.hasNext(); ) {
        Attribute attr = (Attribute) it.next();
        try {
            setAttribute(attr);
            list.add(attr);
        } catch (Exception e) {
            // OK: ignore per spec
        }
    }
    return list;
}
 
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameAndBeanNameInBeansMap() throws Exception {
	String beanName = "testBean";
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");

	SelfNamingTestBean testBean = new SelfNamingTestBean();
	testBean.setObjectName(objectName);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerSingleton(beanName, testBean);

	Map<String, Object> beans = new HashMap<>();
	beans.put(beanName, beanName);

	Map listenerMappings = new HashMap();
	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
	listenerMappings.put(beanName, listener);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setNotificationListenerMappings(listenerMappings);
	exporter.setBeanFactory(factory);
	start(exporter);
	assertIsRegistered("Should have registered MBean", objectName);

	server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
	assertEquals("Listener not notified", 1, listener.getCount("Age"));
}
 
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameAndBeanNameInBeansMap() throws Exception {
	String beanName = "testBean";
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");

	SelfNamingTestBean testBean = new SelfNamingTestBean();
	testBean.setObjectName(objectName);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerSingleton(beanName, testBean);

	Map<String, Object> beans = new HashMap<>();
	beans.put(beanName, beanName);

	Map listenerMappings = new HashMap();
	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
	listenerMappings.put(beanName, listener);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setNotificationListenerMappings(listenerMappings);
	exporter.setBeanFactory(factory);
	start(exporter);
	assertIsRegistered("Should have registered MBean", objectName);

	server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
	assertEquals("Listener not notified", 1, listener.getCount("Age"));
}
 
源代码18 项目: jdk8u60   文件: RequiredModelMBean.java
/**
 * Returns the values of several attributes in the ModelMBean.
 * Executes a getAttribute for each attribute name in the
 * attrNames array passed in.
 *
 * @param attrNames A String array of names of the attributes
 * to be retrieved.
 *
 * @return The array of the retrieved attributes.
 *
 * @exception RuntimeOperationsException Wraps an
 * {@link IllegalArgumentException}: The object name in parameter is
 * null or attributes in parameter is null.
 *
 * @see #setAttributes(javax.management.AttributeList)
 */
public AttributeList getAttributes(String[] attrNames)      {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
        "getAttributes(String[])","Entry");
    }

    if (attrNames == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException("attributeNames must not be null"),
            "Exception occurred trying to get attributes of a "+
            "RequiredModelMBean");

    AttributeList responseList = new AttributeList();
    for (int i = 0; i < attrNames.length; i++) {
        try {
            responseList.add(new Attribute(attrNames[i],
                                 getAttribute(attrNames[i])));
        } catch (Exception e) {
            // eat exceptions because interface doesn't have an
            // exception on it
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
                MODELMBEAN_LOGGER.logp(Level.FINER,
                        RequiredModelMBean.class.getName(),
                    "getAttributes(String[])",
                        "Failed to get \"" + attrNames[i] + "\": ", e);
            }
        }
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
            RequiredModelMBean.class.getName(),
                "getAttributes(String[])","Exit");
    }

    return responseList;
}
 
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameBeforeObjectNameMappedToSameBeanInstance() throws Exception {
	String beanName = "testBean";
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");

	SelfNamingTestBean testBean = new SelfNamingTestBean();
	testBean.setObjectName(objectName);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerSingleton(beanName, testBean);

	Map<String, Object> beans = new HashMap<>();
	beans.put(beanName, testBean);

	Map listenerMappings = new HashMap();
	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
	listenerMappings.put(beanName, listener);
	listenerMappings.put(objectName, listener);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setNotificationListenerMappings(listenerMappings);
	exporter.setBeanFactory(factory);
	start(exporter);
	assertIsRegistered("Should have registered MBean", objectName);

	server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
	assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
}
 
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance() throws Exception {
	String beanName = "testBean";
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");

	SelfNamingTestBean testBean = new SelfNamingTestBean();
	testBean.setObjectName(objectName);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerSingleton(beanName, testBean);

	Map<String, Object> beans = new HashMap<>();
	beans.put(beanName, testBean);

	Map listenerMappings = new HashMap();
	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
	listenerMappings.put(objectName, listener);
	listenerMappings.put(beanName, listener);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setNotificationListenerMappings(listenerMappings);
	exporter.setBeanFactory(factory);
	start(exporter);
	assertIsRegistered("Should have registered MBean", objectName);

	server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
	assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
}
 
源代码21 项目: jdk8u60   文件: MBeanExceptionTest.java
public void setAttribute(Attribute attr)
        throws MBeanException {
    String attrName = attr.getName();
    if (attrName.equals("UncheckedException"))
        throw theUncheckedException;
    else
        throw new AssertionError();
}
 
源代码22 项目: jdk8u60   文件: MBeanSupport.java
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
/**
 * This method always fail since all MBeanServerDelegateMBean attributes
 * are read-only.
 *
 * @param attribute The identification of the attribute to
 * be set and  the value it is to be set to.
 *
 * @exception AttributeNotFoundException
 */
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {

    // Now we will always fail:
    // Either because the attribute is null or because it is not
    // accessible (or does not exist).
    //
    final String attname = (attribute==null?null:attribute.getName());
    if (attname == null) {
        final RuntimeException r =
            new IllegalArgumentException("Attribute name cannot be null");
        throw new RuntimeOperationsException(r,
            "Exception occurred trying to invoke the setter on the MBean");
    }

    // This is a hack: we call getAttribute in order to generate an
    // AttributeNotFoundException if the attribute does not exist.
    //
    Object val = getAttribute(attname);

    // If we reach this point, we know that the requested attribute
    // exists. However, since all attributes are read-only, we throw
    // an AttributeNotFoundException.
    //
    throw new AttributeNotFoundException(attname + " not accessible");
}
 
源代码24 项目: jdk1.8-source-analysis   文件: MXBeanProxy.java
@Override
Object invoke(MBeanServerConnection mbsc, ObjectName name, Object[] args)
        throws Exception {
    assert(args.length == 1);
    Attribute attr = new Attribute(getName(), args[0]);
    mbsc.setAttribute(name, attr);
    return null;
}
 
源代码25 项目: openjdk-jdk8u   文件: MBeanServerDelegateImpl.java
/**
 * This method always fail since all MBeanServerDelegateMBean attributes
 * are read-only.
 *
 * @param attribute The identification of the attribute to
 * be set and  the value it is to be set to.
 *
 * @exception AttributeNotFoundException
 */
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {

    // Now we will always fail:
    // Either because the attribute is null or because it is not
    // accessible (or does not exist).
    //
    final String attname = (attribute==null?null:attribute.getName());
    if (attname == null) {
        final RuntimeException r =
            new IllegalArgumentException("Attribute name cannot be null");
        throw new RuntimeOperationsException(r,
            "Exception occurred trying to invoke the setter on the MBean");
    }

    // This is a hack: we call getAttribute in order to generate an
    // AttributeNotFoundException if the attribute does not exist.
    //
    Object val = getAttribute(attname);

    // If we reach this point, we know that the requested attribute
    // exists. However, since all attributes are read-only, we throw
    // an AttributeNotFoundException.
    //
    throw new AttributeNotFoundException(attname + " not accessible");
}
 
源代码26 项目: jdk1.8-source-analysis   文件: JmxMBeanServer.java
/**
 * Clone attribute.
 */
private Attribute cloneAttribute(Attribute attribute) {
    if (attribute != null) {
        if (!attribute.getClass().equals(Attribute.class)) {
            return new Attribute(attribute.getName(), attribute.getValue());
        }
    }
    return attribute;
}
 
源代码27 项目: jdk8u60   文件: XMBeanAttributes.java
public void tableChanged(final TableModelEvent e) {
    // only post changes to the draggable column
    if (isColumnEditable(e.getColumn())) {
        final TableModel model = (TableModel)e.getSource();
        Object tableValue = model.getValueAt(e.getFirstRow(),
                                         e.getColumn());

        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("tableChanged: firstRow="+e.getFirstRow()+
                ", lastRow="+e.getLastRow()+", column="+e.getColumn()+
                ", value="+tableValue);
        }
        // if it's a String, try construct new value
        // using the defined type.
        if (tableValue instanceof String) {
            try {
                tableValue =
                    Utils.createObjectFromString(getClassName(e.getFirstRow()), // type
                    (String)tableValue);// value
            } catch (Throwable ex) {
                popupAndLog(ex,"tableChanged",
                            Messages.PROBLEM_SETTING_ATTRIBUTE);
            }
        }
        final String attributeName = getValueName(e.getFirstRow());
        final Attribute attribute =
              new Attribute(attributeName,tableValue);
        setAttribute(attribute, "tableChanged");
    }
}
 
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance() throws Exception {
	String beanName = "testBean";
	ObjectName objectName = ObjectName.getInstance("spring:name=Test");

	SelfNamingTestBean testBean = new SelfNamingTestBean();
	testBean.setObjectName(objectName);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerSingleton(beanName, testBean);

	Map<String, Object> beans = new HashMap<>();
	beans.put(beanName, testBean);

	Map listenerMappings = new HashMap();
	CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
	listenerMappings.put(objectName, listener);
	listenerMappings.put(beanName, listener);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setNotificationListenerMappings(listenerMappings);
	exporter.setBeanFactory(factory);
	start(exporter);
	assertIsRegistered("Should have registered MBean", objectName);

	server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
	assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
}
 
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
/**
 * Returns the values of several attributes in the ModelMBean.
 * Executes a getAttribute for each attribute name in the
 * attrNames array passed in.
 *
 * @param attrNames A String array of names of the attributes
 * to be retrieved.
 *
 * @return The array of the retrieved attributes.
 *
 * @exception RuntimeOperationsException Wraps an
 * {@link IllegalArgumentException}: The object name in parameter is
 * null or attributes in parameter is null.
 *
 * @see #setAttributes(javax.management.AttributeList)
 */
public AttributeList getAttributes(String[] attrNames)      {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
        "getAttributes(String[])","Entry");
    }

    if (attrNames == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException("attributeNames must not be null"),
            "Exception occurred trying to get attributes of a "+
            "RequiredModelMBean");

    AttributeList responseList = new AttributeList();
    for (int i = 0; i < attrNames.length; i++) {
        try {
            responseList.add(new Attribute(attrNames[i],
                                 getAttribute(attrNames[i])));
        } catch (Exception e) {
            // eat exceptions because interface doesn't have an
            // exception on it
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
                MODELMBEAN_LOGGER.logp(Level.FINER,
                        RequiredModelMBean.class.getName(),
                    "getAttributes(String[])",
                        "Failed to get \"" + attrNames[i] + "\": ", e);
            }
        }
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
            RequiredModelMBean.class.getName(),
                "getAttributes(String[])","Exit");
    }

    return responseList;
}
 
 类所在包
 同包方法