Example usage for javax.management AttributeList add

List of usage examples for javax.management AttributeList add

Introduction

In this page you can find the example usage for javax.management AttributeList add.

Prototype

@Override
public boolean add(Object element) 

Source Link

Usage

From source file:org.apache.geode.management.internal.security.MBeanServerWrapper.java

@Override
public AttributeList getAttributes(ObjectName name, String[] attributes)
        throws InstanceNotFoundException, ReflectionException {
    AttributeList results = new AttributeList();
    for (String attribute : attributes) {
        try {/* w  w w .  ja v a  2  s.c  om*/
            Object value = getAttribute(name, attribute);
            Attribute att = new Attribute(attribute, value);
            results.add(att);
        } catch (Exception e) {
            throw new GemFireSecurityException("error getting value of " + attribute + " from " + name, e);
        }
    }
    return results;
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public AttributeList getAttributes(String[] attributes) {
    AttributeList al = new AttributeList();
    if (attributes == null)
        return null;

    for (int i = 0; i < attributes.length; i++) {
        try {// ww  w . j a v  a  2  s.  c  om
            Attribute att = new Attribute(attributes[i], getAttribute(attributes[i]));
            al.add(att);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return al;
}

From source file:org.archive.crawler.admin.CrawlJob.java

public AttributeList setAttributes(AttributeList attributes) {
    if (attributes == null) {
        throw new RuntimeOperationsException(
                new IllegalArgumentException("attributeNames[] cannot be " + "null"),
                "Cannot call getAttributes with null attribute " + "names");
    }/*www .  j  a va  2  s .  c  o m*/

    AttributeList resultList = new AttributeList();
    if (attributes.size() == 0) {
        return resultList;
    }
    for (int i = 0; i < attributes.size(); i++) {
        try {
            Attribute attr = (Attribute) attributes.get(i);
            setAttributeInternal(attr);
            String an = attr.getName();
            Object newValue = getAttribute(an);
            resultList.add(new Attribute(an, newValue));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // prompt updating of settings-sensitive components
    kickUpdate();
    return resultList;
}

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

@Override
public AttributeList getAttributes(final String[] attributes) {
    final AttributeList attributeList = new AttributeList();
    for (final String attributeName : attributes) {
        try {//  w ww .  ja va  2 s  .  com
            attributeList.add(new Attribute(attributeName, getAttribute(attributeName)));
        } catch (final AttributeNotFoundException e) {
            // ignore
        } catch (final MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (final ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return attributeList;
}

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

/**
 * {@inheritDoc}//from w  ww  .  j a  v a2s.c o  m
 * 
 * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
 */
public AttributeList getAttributes(final String[] attributes) {
    if (attributes == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("attributeNames must not be null"),
                "Exception occured trying to get attributes of a " + "LocalMBean");
    }
    final AttributeList attributeList = new AttributeList();
    String attributeName;
    for (int i = 0; i < attributes.length; i++) {
        attributeName = attributes[i];
        try {
            attributeList.add(new Attribute(attributeName, getAttribute(attributeName)));
        } catch (final Throwable e) {
            _log.error("getAttributes(String[]), failed to get \"" + attributeName + "\"", e);
        }
    }
    return attributeList;
}

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

/**
 * {@inheritDoc}/*from  w  w w .  ja  v a  2 s  . c  o  m*/
 * 
 * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
 */
public AttributeList setAttributes(final AttributeList attributes) {
    if (attributes == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("attributes must not be null"),
                "Exception occured trying to set attributes of a " + "LocalMBean");
    }
    final AttributeList attributeList = new AttributeList();
    for (final Iterator i = attributes.iterator(); i.hasNext();) {
        final Attribute attribute = (Attribute) i.next();
        try {
            setAttribute(attribute);
            attributeList.add(attribute);
        } catch (final Exception e) {
            i.remove();
        }
    }
    return attributeList;
}

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

/**
 * Load the configuration. Not thread safe.
 * /*from ww w  .  j a v  a  2  s.  c o m*/
 * @return
 */
private ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> loadConfig() {
    ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> ret = new ConcurrentHashMap<String, Set<DefaultConfigurationImpl>>();

    ConfigurationStore store;
    try {
        store = (ConfigurationStore) jaxbContext.createUnmarshaller().unmarshal(persistanceResource.getFile());
    } catch (IOException e) {
        logger.error("Error loading config/rifidi.xml, no configuration loaded");
        return ret;
    } catch (JAXBException e) {
        logger.error("Exception loading config/rifidi.xml or file not found, no configuration loaded");
        return ret;
    }
    if (store.getServices() != null) {
        for (ServiceStore service : store.getServices()) {
            if (ret.get(service.getFactoryID()) == null) {
                ret.put(service.getFactoryID(), new CopyOnWriteArraySet<DefaultConfigurationImpl>());
            }
            AttributeList attributes = new AttributeList();
            // get all properties
            for (String key : service.getAttributes().keySet()) {
                // factoryid is already processed
                if (Constants.FACTORYID.equals(key)) {
                    continue;
                }
                // type is already processed
                if (Constants.FACTORY_TYPE.equals(key)) {
                    continue;
                }
                attributes.add(new Attribute(key, service.getAttributes().get(key)));
            }
            if (!checkName(service.getServiceID())) {
                continue;
            }
            ret.get(service.getFactoryID()).add(createAndRegisterConfiguration(service.getServiceID(),
                    service.getFactoryID(), attributes, service.getSessionDTOs()));
            serviceNames.add(service.getServiceID());
        }
    }
    return ret;
}

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

@Override
public AttributeList getAttributes(String[] attributes) {
    assert (attributes != null);
    AttributeList ret = new AttributeList();
    Set<String> attribNames = new HashSet<String>();
    for (int count = 0; count < attributes.length; count++) {
        attribNames.add(attributes[count]);
    }/* w w w  .jav a2s .co  m*/
    for (Attribute attr : this.attributes.asList()) {
        if (attribNames.contains(attr.getName())) {
            ret.add(attr);
        }
    }
    return ret;
}

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

@Override
public AttributeList setAttributes(final AttributeList attributes) {
    assert (attributes != null);
    RifidiService service = target.get();
    if (service != null) {
        service.setAttributes(attributes);
    }/*from w  ww.j a  va  2  s.  c  o  m*/

    // keep track of changed attributes since there might be an error
    AttributeList changedAttributes = new AttributeList();

    for (Attribute attribute : attributes.asList()) {

        String attrName = attribute.getName();
        Integer pos = nameToPos.get(attrName);
        if (pos == null) {
            logger.error("Error when trying to set " + attribute.getName());
        } else {
            this.attributes.set(pos, attribute);
            changedAttributes.add(this.attributes.get(pos));
        }

    }

    notifierService.attributesChanged(getServiceID(), (AttributeList) changedAttributes);
    return (AttributeList) changedAttributes.clone();
}

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

/**
 * Get all attributes and their values.//w w  w .jav  a2s  .c o m
 * 
 * @return
 */
public AttributeList getAttributes() {
    AttributeList ret = new AttributeList();
    for (String name : nameToMethod.keySet()) {
        try {

            Object value = nameToMethod.get(name).invoke(this);
            ret.add(new Attribute(name, value));
        } catch (IllegalArgumentException e) {
            logger.error("Error when invoking getter " + nameToMethod.get(name) + ": " + e);
        } catch (IllegalAccessException e) {
            logger.error("Error when invoking getter " + nameToMethod.get(name) + ": " + e);
        } catch (InvocationTargetException e) {
            logger.error("Error when invoking getter " + nameToMethod.get(name) + ": " + e);
        }
    }
    return ret;
}