Example usage for javax.management Attribute getName

List of usage examples for javax.management Attribute getName

Introduction

In this page you can find the example usage for javax.management Attribute getName.

Prototype

public String getName() 

Source Link

Document

Returns a String containing the name of the attribute.

Usage

From source file:org.eclipse.smila.management.jmx.AgentMBean.java

/**
 * {@inheritDoc}/*from  w  w w.  j a v a 2  s.c o m*/
 * 
 * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 */
public void setAttribute(final Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    final ModelMBeanAttributeInfo info = _beanInfo.getAttribute(attribute.getName());
    if (info == null) {
        final String msg = "MBean " + _beanInfo.getClassName()
                + " doesnt contain attribute Information for method " + attribute.getName()
                + ", please check if you have defined a gettter and setter for this Attriubute!";
        _log.error(msg);
        throw new AttributeNotFoundException(msg);
    }
    final Descriptor descriptor = info.getDescriptor();
    final String setterMethod = (String) (descriptor.getFieldValue("setMethod"));
    final String setterSignatureClass = (String) (descriptor.getFieldValue("setterSignatureClass"));
    invoke(setterMethod, new Object[] { attribute.getValue() }, new String[] { setterSignatureClass });
}

From source file:org.cleverbus.core.throttling.JmxThrottlingConfiguration.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Assert.notNull(attribute, "attribute must not be null");

    // attr name: systemName . serviceName
    String attrName = attribute.getName();

    String[] nameParts = StringUtils.split(attrName, ThrottleScope.THROTTLE_SEPARATOR);

    if (nameParts.length != 2) {
        throw new AttributeNotFoundException(
                "attribute name is not in expected format: 'systemName . serviceName'");
    }/*from   w w w  . j  ava  2 s.  co  m*/

    // attr value: limit / interval
    String attrValue = (String) attribute.getValue();

    String[] valueParts = StringUtils.split(attrValue, ThrottleProps.PROP_VALUE_SEPARATOR);

    if (valueParts.length != 2) {
        throw new InvalidAttributeValueException(
                "attribute value is not in expected format: 'limit / interval'");
    }

    configuration.addProperty(nameParts[0], nameParts[1], Integer.valueOf(valueParts[1]),
            Integer.valueOf(valueParts[0]));
}

From source file:org.hyperic.hq.plugin.websphere.jmx.WebSphereQuery.java

public boolean getAttributes(AdminClient mServer, ObjectName name, String[] attrNames) {

    AttributeList list;//w  w  w .  j ava 2 s.  c om

    if (attrNames.length == 0) {
        return true;
    }

    try {
        list = mServer.getAttributes(name, attrNames);
    } catch (InstanceNotFoundException e) {
        logAttrFailure(name, e);
        return false;
    } catch (ReflectionException e) {
        logAttrFailure(name, e);
        return false;
    } catch (ConnectorException e) {
        logAttrFailure(name, e);
        return false;
    }

    if (list == null) {
        return false;
    }

    for (int i = 0; i < list.size(); i++) {
        Attribute attr = (Attribute) list.get(i);
        Object obj = attr.getValue();
        if (obj != null) {
            this.attrs.put(attr.getName(), obj.toString());
        }
    }

    return true;
}

From source file:com.proofpoint.jmx.MBeanRepresentation.java

public MBeanRepresentation(MBeanServer mbeanServer, ObjectName objectName, ObjectMapper objectMapper)
        throws JMException {
    this.objectName = objectName;

    MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);

    className = mbeanInfo.getClassName();
    description = mbeanInfo.getDescription();
    descriptor = toMap(mbeanInfo.getDescriptor());

    ///*w  w  w.  j a va2 s .  co  m*/
    // Attributes
    //
    LinkedHashMap<String, MBeanAttributeInfo> attributeInfos = Maps.newLinkedHashMap();
    for (MBeanAttributeInfo attributeInfo : mbeanInfo.getAttributes()) {
        attributeInfos.put(attributeInfo.getName(), attributeInfo);
    }

    String[] attributeNames = attributeInfos.keySet().toArray(new String[attributeInfos.size()]);
    ImmutableList.Builder<AttributeRepresentation> attributes = ImmutableList.builder();
    for (Attribute attribute : mbeanServer.getAttributes(objectName, attributeNames).asList()) {
        String attributeName = attribute.getName();

        // use remove so we only include one value for each attribute
        MBeanAttributeInfo attributeInfo = attributeInfos.remove(attributeName);
        if (attributeInfo == null) {
            // unknown extra attribute, could have been added after MBeanInfo was fetched
            continue;
        }

        Object attributeValue = attribute.getValue();
        AttributeRepresentation attributeRepresentation = new AttributeRepresentation(attributeInfo,
                attributeValue, objectMapper);
        attributes.add(attributeRepresentation);
    }
    this.attributes = attributes.build();

    //
    // Operations
    //
    ImmutableList.Builder<OperationRepresentation> operations = ImmutableList.builder();
    for (MBeanOperationInfo operationInfo : mbeanInfo.getOperations()) {
        operations.add(new OperationRepresentation(operationInfo));
    }
    this.operations = operations.build();
}

From source file:org.rifidi.edge.configuration.RifidiService.java

/**
 * Set an attribute./* w  ww . j  av  a2  s.c  om*/
 * 
 * @param attribute
 */
public void setAttribute(Attribute attribute) {
    try {
        _setAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        logger.error("Error when setting attribute " + attribute.getName() + " " + e);
    } catch (InvalidAttributeValueException e) {
        logger.error("Error when setting attribute " + attribute.getName() + " " + e);
    } catch (MBeanException e) {
        logger.error("Error when setting attribute " + attribute.getName() + " " + e);
    } catch (ReflectionException e) {
        logger.error("Error when setting attribute " + attribute.getName() + " " + e);
    }
}

From source file:org.echocat.jemoni.jmx.support.CacheDynamicMBean.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    final String attributeName = attribute.getName();
    final Object value = attribute.getValue();
    if ("maximumLifetime".equals(attributeName)) {
        if (value != null && !(value instanceof String)) {
            throw new InvalidAttributeValueException();
        }//from w  w  w .  ja va  2 s.co m
        cast(LimitedCache.class).setMaximumLifetime(
                value != null && !value.toString().trim().isEmpty() ? new Duration(value.toString()) : null);
    } else if ("capacity".equals(attributeName)) {
        if (value != null && !(value instanceof Number)) {
            throw new InvalidAttributeValueException();
        }
        cast(LimitedCache.class).setCapacity(value != null ? ((Number) value).longValue() : null);
    } else if ("producingType".equals(attributeName)) {
        if (value != null && !(value instanceof String)) {
            throw new InvalidAttributeValueException();
        }
        final ProducingType producingType;
        if (value == null || value.toString().trim().isEmpty()) {
            producingType = ProducingType.DEFAULT;
        } else {
            try {
                producingType = ProducingType.valueOf(value.toString().trim());
            } catch (IllegalArgumentException ignored) {
                throw new InvalidAttributeValueException("Illegal value: " + value + ". Possible values: "
                        + StringUtils.join(ProducingType.values(), ", "));
            }
        }
        cast(ProducingTypeEnabledCache.class).setProducingType(producingType);
    } else {
        throw new AttributeNotFoundException();
    }
}

From source file:org.elasticsearch.river.jolokia.strategy.simple.SimpleRiverSource.java

private Map<String, String> getAttributeTransforms() {
    try {/*  w ww.  j  a va  2 s.  c o m*/
        Map<String, String> mappings = new HashMap<String, String>();
        for (Attribute attr : setting.getAttributes()) {
            if (null != attr.getTransform()) {
                mappings.put(attr.getName(), attr.getTransform());
            }
        }
        return mappings;
    } catch (Exception e) {
        return new HashMap<String, String>();
    }
}

From source file:org.apache.hadoop.hdfs.server.common.MetricsLoggerTask.java

/**
 * Write metrics to the metrics appender when invoked.
 *//* w  ww .  j a  v  a 2s. co m*/
@Override
public void run() {
    // Skip querying metrics if there are no known appenders.
    if (!metricsLog.isInfoEnabled() || !hasAppenders(metricsLog) || objectName == null) {
        return;
    }

    metricsLog.info(" >> Begin " + nodeName + " metrics dump");
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    // Iterate over each MBean.
    for (final ObjectName mbeanName : server.queryNames(objectName, null)) {
        try {
            MBeanInfo mBeanInfo = server.getMBeanInfo(mbeanName);
            final String mBeanNameName = MBeans.getMbeanNameName(mbeanName);
            final Set<String> attributeNames = getFilteredAttributes(mBeanInfo);

            final AttributeList attributes = server.getAttributes(mbeanName,
                    attributeNames.toArray(new String[attributeNames.size()]));

            for (Object o : attributes) {
                final Attribute attribute = (Attribute) o;
                final Object value = attribute.getValue();
                final String valueStr = (value != null) ? value.toString() : "null";
                // Truncate the value if it is too long
                metricsLog.info(mBeanNameName + ":" + attribute.getName() + "=" + trimLine(valueStr));
            }
        } catch (Exception e) {
            metricsLog.error("Failed to get " + nodeName + " metrics for mbean " + mbeanName.toString(), e);
        }
    }
    metricsLog.info(" << End " + nodeName + " metrics dump");
}

From source file:org.hyperic.hq.plugin.weblogic.jmx.WeblogicQuery.java

public boolean getAttributes(MBeanServer mServer, ObjectName name, String[] attrNames) {

    if (name == null) {
        return false;
    }//from  w ww  . j  av  a  2s.c  o  m
    if (attrNames.length == 0) {
        setName(name.getKeyProperty("Name"));
        return true;
    }

    AttributeList list;

    try {
        list = mServer.getAttributes(name, attrNames);
    } catch (InstanceNotFoundException e) {
        //given that the ObjectName is from queryNames
        //returned by the server this should not happen.
        //however, it is possible when nodes are not properly
        //configured.
        logAttrFailure(name, attrNames, e);
        return false;
    } catch (ReflectionException e) {
        //this should not happen either
        logAttrFailure(name, attrNames, e);
        return false;
    }

    if (list == null) {
        //only 6.1 seems to behave this way,
        //modern weblogics throw exceptions.
        return false;
    }

    for (int i = 0; i < list.size(); i++) {
        Attribute attr = (Attribute) list.get(i);
        Object obj = attr.getValue();
        if (obj != null) {
            this.attrs.put(attr.getName(), obj.toString());
        }
    }

    return true;
}

From source file:com.zavakid.mushroom.impl.MetricsSourceAdapter.java

@Override
public Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    updateJmxCache();//from w  ww  .  j av  a2  s.co  m
    synchronized (this) {
        Attribute a = attrCache.get(attribute);
        if (a == null) {
            throw new AttributeNotFoundException(attribute + " not found");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(attribute + ": " + a.getName() + "=" + a.getValue());
        }
        return a.getValue();
    }
}