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

The following examples show how to use javax.management.AttributeList#add() . 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: BaseModelMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Obtain and return the values of several attributes of this MBean.
 *
 * @param names Names of the requested attributes
 */
@Override
public AttributeList getAttributes(String names[]) {

    // Validate the input parameters
    if (names == null)
        throw new RuntimeOperationsException
            (new IllegalArgumentException("Attribute names list is null"),
             "Attribute names list is null");

    // Prepare our response, eating all exceptions
    AttributeList response = new AttributeList();
    for (int i = 0; i < names.length; i++) {
        try {
            response.add(new Attribute(names[i],getAttribute(names[i])));
        } catch (Exception e) {
            // Not having a particular attribute in the response
            // is the indication of a getter problem
        }
    }
    return (response);

}
 
Example 2
Source File: DynamicMBeanWrapper.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public AttributeList getAttributes(final String[] attributes)
{
    final AttributeList list = new AttributeList();
    for (String n : attributes)
    {
        try
        {
            list.add(new Attribute(n, getAttribute(n)));
        }
        catch (Exception ignore)
        {
            // no-op
        }
    }
    return list;
}
 
Example 3
Source File: ModelControllerMBeanHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException {
    final ManagementModelIntegration.ResourceAndRegistration reg = getRootResourceAndRegistration();
    final PathAddress address = resolvePathAddress(name, reg);
    if (address == null) {
        throw JmxLogger.ROOT_LOGGER.mbeanNotFound(name);
    }
    final ResourceAccessControl accessControl = accessControlUtil.getResourceAccessWithInstanceNotFoundExceptionIfNotAccessible(name, address, false);
    AttributeList list = new AttributeList();
    for (String attribute : attributes) {
        try {
            list.add(new Attribute(attribute, getAttribute(reg, address, attribute, accessControl)));
        } catch (AttributeNotFoundException e) {
            throw new ReflectionException(e);
        }
    }
    return list;
}
 
Example 4
Source File: MBeanSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList getAttributes(String[] attributes) {
    final AttributeList result = new AttributeList(attributes.length);
    for (String attrName : attributes) {
        try {
            final Object attrValue = getAttribute(attrName);
            result.add(new Attribute(attrName, attrValue));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 5
Source File: RequiredModelMBean.java    From openjdk-jdk9 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.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "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 6
Source File: MBeanServerDelegateImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes it possible to get the values of several attributes of
 * the MBeanServerDelegate.
 *
 * @param attributes A list of the attributes to be retrieved.
 *
 * @return  The list of attributes retrieved.
 *
 */
public AttributeList getAttributes(String[] attributes) {
    // If attributes is null, the get all attributes.
    //
    final String[] attn = (attributes==null?attributeNames:attributes);

    // Prepare the result list.
    //
    final int len = attn.length;
    final AttributeList list = new AttributeList(len);

    // Get each requested attribute.
    //
    for (int i=0;i<len;i++) {
        try {
            final Attribute a =
                new Attribute(attn[i],getAttribute(attn[i]));
            list.add(a);
        } catch (Exception x) {
            // Skip the attribute that couldn't be obtained.
            //
            if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
                MBEANSERVER_LOGGER.logp(Level.FINEST,
                        MBeanServerDelegateImpl.class.getName(),
                        "getAttributes",
                        "Attribute " + attn[i] + " not found");
            }
        }
    }

    // Finally return the result.
    //
    return list;
}
 
Example 7
Source File: ManagedMBean.java    From tomee with Apache License 2.0 5 votes vote down vote up
public AttributeList getAttributes(final String[] strings) {
    final AttributeList list = new AttributeList(strings.length);
    for (final String attribute : strings) {
        try {
            list.add(new Attribute(attribute, getAttribute(attribute)));
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
    return list;
}
 
Example 8
Source File: OldMBeanServerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public AttributeList getAttributes(String[] attributes) {
    AttributeList list = new AttributeList();
    for (String attr : attributes) {
        try {
            list.add(new Attribute(attr, getAttribute(attr)));
        } catch (Exception e) {
            // OK: ignore per spec
        }
    }
    return list;
}
 
Example 9
Source File: CachedMBeanServerConnectionFactory.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private AttributeList getAttributes(
        ObjectName objName, String[] attrNames) throws
        InstanceNotFoundException, ReflectionException, IOException {
    final NameValueMap values = getCachedAttributes(
            objName,
            new TreeSet<String>(Arrays.asList(attrNames)));
    final AttributeList list = new AttributeList();
    for (String attrName : attrNames) {
        final Object value = values.get(attrName);
        if (value != null || values.containsKey(attrName)) {
            list.add(new Attribute(attrName, value));
        }
    }
    return list;
}
 
Example 10
Source File: DynamicMBeanProvider.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
public AttributeList getAttributes(String[] attributes) {
  AttributeList attributeList = new AttributeList();
  for (String attributeName : attributes) {
    try {
      Object value = getAttribute(attributeName);
      attributeList.add(new Attribute(attributeName, value));
    } catch (AttributeNotFoundException ex) {
      _logger.error("Failed to get attribute: " + attributeName, ex);
    }
  }
  return attributeList;
}
 
Example 11
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 12
Source File: OldMBeanServerTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public AttributeList getAttributes(String[] attributes) {
    AttributeList list = new AttributeList();
    for (String attr : attributes) {
        try {
            list.add(new Attribute(attr, getAttribute(attr)));
        } catch (Exception e) {
            // OK: ignore per spec
        }
    }
    return list;
}
 
Example 13
Source File: RequiredModelMBean.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: ResourceUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static AttributeList getResourceAttributes(JdbcResource jdbcResource){
    AttributeList attrs = new AttributeList();
    attrs.add(new Attribute(__JndiName, jdbcResource.getJndiName()));
    attrs.add(new Attribute(__PoolName, jdbcResource.getPoolName()));
    attrs.add(new Attribute(__JdbcObjectType, jdbcResource.getObjectType()));
    attrs.add(new Attribute(__Enabled, jdbcResource.getEnabled()));
    attrs.add(new Attribute(__Description, jdbcResource.getDescription()));
    return attrs;
}
 
Example 15
Source File: MBeanSupport.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList getAttributes(String[] attributes) {
    final AttributeList result = new AttributeList(attributes.length);
    for (String attrName : attributes) {
        try {
            final Object attrValue = getAttribute(attrName);
            result.add(new Attribute(attrName, attrValue));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 16
Source File: MBeanSupport.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList getAttributes(String[] attributes) {
    final AttributeList result = new AttributeList(attributes.length);
    for (String attrName : attributes) {
        try {
            final Object attrValue = getAttribute(attrName);
            result.add(new Attribute(attrName, attrValue));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 17
Source File: AttributeListTypeSafeTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void doOp(AttributeList alist, Op op) {
    Object x = "oops";
    switch (op) {
        case ADD: alist.add(x); break;
        case ADD_AT: alist.add(0, x); break;
        case ADD_ALL: alist.add(Collections.singleton(x)); break;
        case ADD_ALL_AT: alist.add(0, Collections.singleton(x)); break;
        case SET: alist.set(0, x); break;
        default: throw new AssertionError("Case not covered");
    }
}
 
Example 18
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 19
Source File: MBeanSupport.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 20
Source File: ServerInfo.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private AttributeList createAddAttributes(){
    AttributeList atList = new AttributeList();
    atList.add(new Attribute(this.PORT, this.getPort()));
    atList.add(new Attribute(this.DOMAIN, this.getDomain()));
    return atList;
}