Java Code Examples for javax.management.AttributeList#asList()

The following examples show how to use javax.management.AttributeList#asList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluggableMBeanServerImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException,
        ReflectionException {
    Throwable error = null;
    MBeanServerPlugin delegate = null;
    final boolean readOnly = false;
    try {
        delegate = findDelegate(name);
        for( Attribute attribute : attributes.asList()) {
            authorizeMBeanOperation(delegate, name, SET_ATTRIBUTES, attribute.getName(), JmxAction.Impact.WRITE);
        }
        return delegate.setAttributes(name, attributes);
    } catch (Exception e) {
        error = e;
        if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e;
        if (e instanceof ReflectionException) throw (ReflectionException)e;
        throw makeRuntimeException(e);
    } finally {
        if (shouldAuditLog(delegate, readOnly)) {
            new MBeanServerAuditLogRecordFormatter(this, error, readOnly).setAttributes(name, attributes);
        }
    }
}
 
Example 2
Source File: MBean.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AttributeList setAttributes(@Nullable final AttributeList attributes) {
  AttributeList result = new AttributeList();
  if (attributes != null) {
    for (Attribute attribute : attributes.asList()) {
      try {
        setAttribute(attribute);
        result.add(attribute);
      }
      catch (Exception e) {
        log.warn("Failed to set attribute: {}", attribute.getName(), e);
      }
    }
  }
  return result;
}
 
Example 3
Source File: CachedMBeanServerConnectionFactory.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: ProxyClient.java    From jvmtop with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: JmxClient.java    From vjtools with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: RequiredModelMBean.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 7
Source File: RequiredModelMBean.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 8
Source File: RequiredModelMBean.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 9
Source File: RequiredModelMBean.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 10
Source File: RequiredModelMBean.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 11
Source File: ConfigurationMBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList successful = new AttributeList();
    for (Attribute attribute: attributes.asList()) {
        try {
            setAttribute(attribute);
            successful.add(attribute);
        } catch (AttributeNotFoundException | InvalidAttributeValueException | MBeanException | ReflectionException e) {
            // Ignore as we just won't return it in the result.
        }
    }
    return successful;
}
 
Example 12
Source File: KafkaMetrics.java    From kmanager with Apache License 2.0 5 votes vote down vote up
private Double getDoubleValue(AttributeList attributes, String name) {
  List<Attribute> _attributes = attributes.asList();
  for (Attribute attr : _attributes) {
    if (attr.getName().equalsIgnoreCase(name)) {
      return (Double) attr.getValue();
    }
  }
  return 0D;
}
 
Example 13
Source File: KafkaMetrics.java    From kmanager with Apache License 2.0 5 votes vote down vote up
private Long getLongValue(AttributeList attributes, String name) {
  List<Attribute> _attributes = attributes.asList();
  for (Attribute attr : _attributes) {
    if (attr.getName().equalsIgnoreCase(name)) {
      return (Long) attr.getValue();
    }
  }
  return 0L;
}
 
Example 14
Source File: ReflectionMbean.java    From simplejmx with ISC License 5 votes vote down vote up
@Override
public AttributeList setAttributes(AttributeList attributes) {
	AttributeList returnList = new AttributeList(attributes.size());
	for (Attribute attribute : attributes.asList()) {
		String name = attribute.getName();
		try {
			setAttribute(attribute);
			returnList.add(new Attribute(name, getAttribute(name)));
		} catch (Exception e) {
			returnList.add(new Attribute(name, e.getMessage()));
		}
	}
	return returnList;
}
 
Example 15
Source File: RequiredModelMBean.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 16
Source File: JavaMailJMSStatisticsTest.java    From javamail with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAttributes() throws Exception {
    List<String> attrNames = Arrays.asList("countSuccessful", "countFailure");
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    AttributeList attributeList = platformMBeanServer.getAttributes(JavaMailJMSStatistics.JMX_OBJECT_NAME, attrNames.toArray(new String[attrNames.size()]));
    List<Attribute> list = attributeList.asList();
    for(Attribute attribute : list) {
        if (attrNames.contains(attribute.getName())) {
            Object val = attribute.getValue();
            assertTrue(val instanceof Number);
            continue;
        }
        fail("There is more attributes then expected - " + attribute);
    }
}
 
Example 17
Source File: RequiredModelMBean.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 18
Source File: RequiredModelMBean.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 19
Source File: RequiredModelMBean.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

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

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
 
Example 20
Source File: ArtemisMBeanServerGuard.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void handleSetAttributes(MBeanServer proxy, ObjectName objectName, AttributeList attributes) throws JMException, IOException {
   for (Attribute attr : attributes.asList()) {
      handleSetAttribute(proxy, objectName, attr);
   }
}