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.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.java

/**
 * Registers the Platform MBeanServer as OSGi service. This would enable
 * Aries JMX Whitboard support to then register the JMX MBean which are registered as OSGi service
 * to be registered against the MBean server
 */// w  ww . ja v  a 2  s . c om
private static void registerMBeanServer(PojoServiceRegistry registry) {
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
    try {
        ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        AttributeList attrs = platformMBeanServer.getAttributes(beanName,
                new String[] { "MBeanServerId", "SpecificationName", "SpecificationVersion",
                        "SpecificationVendor", "ImplementationName", "ImplementationVersion",
                        "ImplementationVendor" });
        for (Object object : attrs) {
            Attribute attr = (Attribute) object;
            if (attr.getValue() != null) {
                mbeanProps.put(attr.getName(), attr.getValue().toString());
            }
        }
    } catch (Exception je) {
        log.info("Cannot set service properties of Platform MBeanServer service, registering without", je);
    }
    registry.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
}

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

public Object getAttribute(MBeanServer server, String attrName)
        throws InstanceNotFoundException, ReflectionException, AttributeNotFoundException {

    long timeNow = System.currentTimeMillis();

    if ((timeNow - this.timestamp) > this.expire) {
        AttributeList attrList;//from   ww w.j a  va  2s  .com

        if (log.isDebugEnabled()) {
            log.debug("server.getAttributes(" + this.name + ", " + Arrays.asList(this.attrs) + ")");
        }

        attrList = server.getAttributes(this.name, this.attrs);

        if (attrList == null) {
            throw new AttributeNotFoundException(this.name.toString());
        }

        for (Iterator it = attrList.iterator(); it.hasNext();) {

            Attribute attr = (Attribute) it.next();

            this.values.put(attr.getName(), attr.getValue());
        }

        this.timestamp = timeNow;
    }

    Object value = this.values.get(attrName);

    if (value == null) {
        throw new AttributeNotFoundException(attrName);
    }

    return value;
}

From source file:org.wso2.carbon.metrics.impl.ReporterTest.java

private SortedMap<String, Object> values(AttributeList attributes) {
    final TreeMap<String, Object> values = new TreeMap<String, Object>();
    if (attributes != null) {
        for (Object o : attributes) {
            final Attribute attribute = (Attribute) o;
            values.put(attribute.getName(), attribute.getValue());
        }/*from   w w  w .j ava  2 s. co  m*/
    }
    return values;
}

From source file:org.wso2.carbon.as.monitoring.collector.jmx.CollectorUtil.java

/**
 * Set the value of the attribute to the matching property of the event Object.
 *
 * @param event     The event object that should be filled with the attribute value
 * @param attribute The Attribute that should be set to the event field
 *//*from  ww  w  . j av a  2  s .c  o m*/
public void setFieldValue(Object event, Attribute attribute) throws AttributeMapperException {
    Class<?> clazz = event.getClass();
    Field field;
    try {
        field = clazz.getDeclaredField(attribute.getName());
    } catch (NoSuchFieldException e) {
        throw new AttributeMapperException(attribute.getName() + " not found as a field", e);
    }

    try {
        field.setAccessible(true);
        if (field.getType().equals(attribute.getValue().getClass())) {
            field.set(event, attribute.getValue());
        } else {
            throw new AttributeMapperException("Type mismatch occurred. field = " + field.getName()
                    + " expected = " + field.getType() + ", found = " + attribute.getValue().getClass());
        }
    } catch (IllegalAccessException e) {
        throw new AttributeMapperException(
                "Error occurred while accessing field: " + field.getName() + " accessing failed.", e);
    }
}

From source file:com.tomcat.monitor.jmx.obj.bean.MServer.java

/**
 * Zugriff auf ausgewhlte Menge von MBean Attribute
 * /*  w  w w  . j  av  a2s.  c om*/
 * @param accessorMbean
 *           ObjectName of mbean
 * @param attributes
 *           Map von Attribute und evtl. Path Zugriffs ausdrcken (Separator
 *           ";") see accessValue
 */
public Map<String, Object> values(ObjectName accessorMbean, Map<String, String> attributes) {

    String[] attrNames = new String[attributes.size()];
    attributes.keySet().toArray(attrNames);
    AttributeList list = null;
    try {
        list = mserver.getAttributes(accessorMbean, attrNames);
    } catch (Exception e) {
        logger.error(e);
    }
    Map<String, Object> values = new HashMap<String, Object>();
    if (list != null) {
        if (logger.isDebugEnabled())
            logger.debug("access: " + accessorMbean + " attr=" + list.toString());
        for (Iterator<Object> iter = list.iterator(); iter.hasNext();) {
            Attribute attr = (Attribute) iter.next();
            Object value = attr.getValue();
            String attributePath = attributes.get(attr.getName());
            if (attributePath != null) {
                StringTokenizer st = new StringTokenizer(attributePath, ";");
                while (st.hasMoreTokens()) {
                    String path = st.nextToken();
                    Object pathvalue = accessValue(path, value);
                    values.put(attr.getName() + "." + path, pathvalue);
                }
            } else
                values.put(attr.getName(), value);
        }
    }
    return values;
}

From source file:com.wakacommerce.common.cache.StatisticsServiceImpl.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (attribute.getName().equals("LOG_RESOLUTION")) {
        setLogResolution((Long) attribute.getValue());
    }// w w w.  j  a v a 2  s .c o  m
    //do nothing - not allowed
}

From source file:org.cleverbus.core.alerts.AlertsJmxConfiguration.java

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

    String attrName = attribute.getName();
    String value = (String) attribute.getValue();

    AlertInfo alert = getAlert(attrName);

    if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) {
        alert.setEnabled(BooleanUtils.toBoolean(value));
    } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) {
        alert.setLimit(Long.valueOf(value));
    } else {//from w  ww  . j a va  2  s . c  o  m
        throw new IllegalStateException("unsupported attribute name '" + attrName + "'");
    }
}

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

@Override
public AttributeList getAttributes(String[] attributes) {
    updateJmxCache();// ww w  .  j  av  a  2s.c  o  m
    synchronized (this) {
        AttributeList ret = new AttributeList();
        for (String key : attributes) {
            Attribute attr = attrCache.get(key);
            if (LOG.isDebugEnabled()) {
                LOG.debug(key + ": " + attr.getName() + "=" + attr.getValue());
            }
            ret.add(attr);
        }
        return ret;
    }
}

From source file:org.hyperic.hq.product.jmx.MxQuery.java

public void getAttributes(MBeanServerConnection mServer, ObjectName name, String[] attrs)
        throws PluginException {

    if (attrs.length == 0) {
        return;/*from  w  w  w  .  ja v  a 2 s  .com*/
    }

    AttributeList mBeanAttrs;

    try {
        mBeanAttrs = mServer.getAttributes(name, attrs);
    } catch (RemoteException e) {
        throw new PluginException("Cannot connect to server", e);
    } catch (InstanceNotFoundException e) {
        throw new PluginException("Cannot find MBean [" + name + "]", e);
    } catch (ReflectionException e) {
        throw new PluginException("MBean reflection exception", e);
    } catch (IOException e) {
        throw new PluginException("Cannot connect to server", e);
    }

    for (Iterator it = mBeanAttrs.iterator(); it.hasNext();) {
        Attribute attr = (Attribute) it.next();
        Object value = attr.getValue();
        if (value != null) {
            setAttribute(attr.getName(), value.toString());
        }
    }
}

From source file:com.cyberway.issue.crawler.datamodel.credential.HtmlFormCredential.java

/**
 * @param context CrawlURI context to use.
 * @return Form inputs as convenient map.  Returns null if no form items.
 * @throws AttributeNotFoundException//ww  w  .  ja  v  a2s .co m
 */
public Map<String, Object> getFormItems(final CrawlURI context) throws AttributeNotFoundException {
    Map<String, Object> result = null;
    MapType items = (MapType) getAttribute(ATTR_FORM_ITEMS, context);
    if (items != null) {
        for (Iterator i = items.iterator(context); i.hasNext();) {
            Attribute a = (Attribute) i.next();
            if (result == null) {
                result = new HashMap<String, Object>();
            }
            result.put(a.getName(), a.getValue());
        }
    }
    return result;
}