Example usage for javax.management Attribute getValue

List of usage examples for javax.management Attribute getValue

Introduction

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

Prototype

public Object getValue() 

Source Link

Document

Returns an Object that is the value of this attribute.

Usage

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;
    }// w  w  w  . j av a  2s . co 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: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  w  w . j a  va 2 s .  co  m
        throw new IllegalStateException("unsupported attribute name '" + attrName + "'");
    }
}

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());
    }//from  www .  j a  va  2s  .  c  o  m
    //do nothing - not allowed
}

From source file:org.jolokia.jmx.JsonDymamicMBeanImplTest.java

@Test
public void setGetAttributes() throws Exception {
    AttributeList attrList = new AttributeList(
            Arrays.asList(new Attribute("Chili", "aji"), new Attribute("Numbers", "16,11,68")));
    platformServer.setAttributes(testName, attrList);

    AttributeList ret = platformServer.getAttributes(testName, new String[] { "Chili", "Numbers" });
    Attribute chili = (Attribute) ret.get(0);
    Attribute num = (Attribute) ret.get(1);
    assertEquals(chili.getValue(), "aji");

    JSONArray numsJ = (JSONArray) toJSON((String) num.getValue());
    assertEquals(numsJ.get(0), 16L);/*from w  w  w  .  j a v a2  s  .  c  o  m*/
    assertEquals(numsJ.get(1), 11L);
    assertEquals(numsJ.get(2), 68L);
    assertEquals(numsJ.size(), 3);

    Assert.assertTrue(platformServer.getAttributes(testName, new String[0]).size() == 0);

}

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 ww. j  a  va2s . com
        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:com.zavakid.mushroom.impl.MetricsSourceAdapter.java

@Override
public Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    updateJmxCache();//from   w w  w  .  jav a  2 s  .c  om
    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();
    }
}

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

@Override
public Map<String, Object> getAttributes() {
    Map<String, Object> ret = new HashMap<String, Object>();
    for (Attribute attr : this.attributes.asList()) {
        ret.put(attr.getName(), attr.getValue());
    }//from   w  w  w .  ja  va  2 s  . c om
    return ret;
}

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
 */// ww w.  ja  va 2  s .  co 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.ecyrd.management.SimpleMBean.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Method m;//from ww  w.ja  va  2  s  .c o  m

    String mname = "set" + StringUtils.capitalize(attr.getName());
    m = findGetterSetter(getClass(), mname, attr.getValue().getClass());

    if (m == null)
        throw new AttributeNotFoundException(attr.getName());

    Object[] args = { attr.getValue() };

    try {
        m.invoke(this, args);
    } catch (IllegalArgumentException e) {
        throw new InvalidAttributeValueException("Faulty argument: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Cannot access attribute " + e.getMessage());
    } catch (InvocationTargetException e) {
        throw new ReflectionException(e, "Cannot invoke attribute " + e.getMessage());
    }
}

From source file:org.mc4j.ems.impl.jmx.connection.bean.DMBean.java

public List<EmsAttribute> refreshAttributes(List<String> attributeNames) {
    if (info == null)
        loadSynchronous();//from ww w. j  ava 2s .  c o  m

    MBeanServer server = getConnectionProvider().getMBeanServer();

    try {
        String[] names = attributeNames.toArray(new String[attributeNames.size()]);

        AttributeList attributeList = server.getAttributes(getObjectName(), names);

        List<EmsAttribute> attributeResults = new ArrayList<EmsAttribute>();

        Iterator iter = attributeList.iterator();
        while (iter.hasNext()) {
            Attribute attr = (Attribute) iter.next();
            EmsAttribute attribute = getAttribute(attr.getName());

            attribute.alterValue(attr.getValue());

            //                if (!values.containsKey(attribute.getName())) {
            //                    attribute.setSupportedType(false);
            //                }

            attributeResults.add(attribute);

        }
        return attributeResults;
    } catch (InstanceNotFoundException infe) {
        this.deleted = true;
        this.attributes = null;
        this.operations = null;
        this.notifications = null;

        throw new RuntimeException("Unable to load attributes, bean not found", infe);
    } catch (Exception e) {
        // TODO: determine which exceptions to register, which to throw and what to log
        //                e.printStackTrace();

        // Don't load them as a set anymore...
        this.hasUnsupportedType = true;
        //System.out.println(ExceptionUtility.printStackTracesToString(e));

        // If we still we're unable to load all the attributes at once
        // lets load as many as we can, one at a time.
        //            for (EmsAttribute attribute : getAttributes()) {
        //                attribute.refresh();
        //            }

        throw new RuntimeException(
                "Unable to load attributes on bean [" + getBeanName().toString() + "] " + e.getMessage(), e);
    }
    //        } else {
    //            // If the object has unsupported attribute types
    //            // lets load as many as we can, one at a time.
    //            System.out.println("Loading individually: " + getObjectName().getCanonicalName());
    //            for (EmsAttribute attribute : getAttributes()) {
    //                attribute.refresh();
    //            }
    //        }

}