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.rifidi.edge.configuration.DefaultConfigurationImpl.java

@Override
public String[] getAttributeNames() {
    Set<String> names = new HashSet<String>();
    for (Attribute attr : attributes.asList()) {
        names.add(attr.getName());
    }//from  w w w . j a  v a2  s  . co m
    return names.toArray(new String[0]);
}

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  ww . j av a 2s  .  c  o m*/
    return ret;
}

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

/**
 * Private helper method so I don't have to duplicate JMS Notification calls
 * // www.  j  a v a2  s .co  m
 * @param attribute
 * @throws AttributeNotFoundException
 * @throws InvalidAttributeValueException
 * @throws MBeanException
 * @throws ReflectionException
 */
private void _setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    // for now we go through the individual setters
    if (nameToProperty.containsKey(attribute.getName())) {
        try {
            Property prop = nameToProperty.get(attribute.getName());
            Method method = this.getClass().getMethod("set" + attribute.getName(),
                    PropertyType.getClassFromType(prop.type()));

            // if attribute is a string, but is supposed to be another
            // type, convert it
            if ((attribute.getValue() instanceof String) && prop.type() != PropertyType.PT_STRING) {
                attribute = new Attribute(attribute.getName(),
                        PropertyType.convert((String) attribute.getValue(), prop.type()));
            }
            method.invoke(this, attribute.getValue());
            return;
        } catch (SecurityException e) {
            logger.error(e);
        } catch (NoSuchMethodException e) {
            logger.error(e);
        } catch (IllegalArgumentException e) {
            logger.error(e);
        } catch (IllegalAccessException e) {
            logger.error(e);
        } catch (InvocationTargetException e) {
            logger.error(e);
        }
    }
    logger.warn("Unknown attribute: " + attribute);
    // throw new AttributeNotFoundException();
}

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

@Override
public Object getAttribute(final String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    assert (attribute != null);
    for (Attribute attr : attributes.asList()) {
        if (attribute.equals(attr.getName())) {
            return attribute;
        }//from   ww w  .  j a v a  2s.c o  m
    }
    throw new AttributeNotFoundException();
}

From source file:com.ecyrd.management.SimpleMBean.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Method m;//from  w w  w  . ja  va2  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.rifidi.edge.configuration.DefaultConfigurationImpl.java

/**
 * Constructor.//from  www.j a  v  a  2s  .c o  m
 * 
 * @param context
 * @param serviceID
 * @param factoryID
 * @param attributes
 * @param sessionDTOs
 */
public DefaultConfigurationImpl(final String serviceID, final String factoryID, final AttributeList attributes,
        final NotifierService notifierService, final JMXService jmxService, Set<SessionDTO> sessionDTOs) {
    this.notifierService = notifierService;
    this.nameToProperty = new HashMap<String, Property>();
    this.nameToOperation = new HashMap<String, Operation>();
    this.factoryID = factoryID;
    this.serviceID = serviceID;
    this.attributes = (AttributeList) attributes.clone();
    disableAutoStart = false;
    for (Object o : this.attributes) {
        Attribute att = (Attribute) o;
        String name = att.getName();
        if (name.equals("DisableAutoStart")) {
            // This is the 'override' autostart, so we will default to true
            // unless it is explicitly set to false
            if (att.getValue() != null && ((String) att.getValue()).equalsIgnoreCase("true")) {
                disableAutoStart = true;
            }
            break;
        }
    }
    this.listeners = new CopyOnWriteArraySet<AttributesChangedListener>();
    this.target = new AtomicReference<RifidiService>(null);
    this.jmxService = jmxService;
    this.sessionDTOs = new ConcurrentHashMap<SessionDTO, String>();
    if (sessionDTOs != null) {
        for (SessionDTO dto : sessionDTOs) {
            this.sessionDTOs.put(dto, "-1");
        }
    }
}

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  ww  .  j  av  a2s  .  c om*/
    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  ww w. ja v a2  s.co 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.mc4j.ems.impl.jmx.connection.bean.DMBean.java

public List<EmsAttribute> refreshAttributes(List<String> attributeNames) {
    if (info == null)
        loadSynchronous();// www .  j a  v a 2 s. c om

    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();
    //            }
    //        }

}

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

@Override
public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException,
        AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    ResourcePermission ctx = getOperationContext(name, attribute.getName(), false);
    this.securityService.authorize(ctx);
    mbs.setAttribute(name, attribute);//w  w w  . jav  a 2s  . c  o m
}