Example usage for javax.management MBeanAttributeInfo getName

List of usage examples for javax.management MBeanAttributeInfo getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the feature.

Usage

From source file:org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

private CompAttrib createCompAttrib(MBeanServerConnection jmxServerConnection, ObjectInstance jmxObjectInstance,
        MBeanAttributeInfo jmxMBeanAttributeInfo) {
    Boolean contentAdded = false;

    CompAttrib xmlCompAttrib = xmlObjectFactory.createCompAttrib();
    xmlCompAttrib.setName(jmxMBeanAttributeInfo.getName());
    xmlCompAttrib.setType("Composite");
    xmlCompAttrib.setAlias(jmxMBeanAttributeInfo.getName());

    CompositeData compositeData;/*from  w ww .j a va 2 s  . c  o m*/
    try {
        logger.debug("Try to get composite data");
        compositeData = (CompositeData) jmxServerConnection.getAttribute(jmxObjectInstance.getObjectName(),
                jmxMBeanAttributeInfo.getName());
        if (compositeData == null)
            logger.warn(
                    "compositeData is null. jmxObjectInstance.getObjectName: '{}', jmxMBeanAttributeInfo.getName: '{}'");
        if (compositeData != null) {
            logger.debug("compositeData.getCompositeType: '{}'", compositeData.getCompositeType());
            Set<String> keys = compositeData.getCompositeType().keySet();
            for (String key : keys) {
                Object compositeEntry = compositeData.get(key);
                if (numbers.contains(compositeEntry.getClass().getName())) {
                    contentAdded = true;
                    CompMember xmlCompMember = xmlObjectFactory.createCompMember();
                    xmlCompMember.setName(key);

                    logger.debug("composite member pure alias: '{}'",
                            jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key));
                    String alias = NameTools
                            .trimByDictionary(jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key));
                    alias = createAndRegisterUniceAlias(alias);
                    xmlCompMember.setAlias(alias);
                    logger.debug("composite member trimmed alias: '{}'", alias);

                    xmlCompMember.setType("gauge");
                    xmlCompAttrib.getCompMember().add(xmlCompMember);

                } else {
                    logger.debug("composite member key '{}' object's class '{}' was not a number.", key,
                            compositeEntry.getClass().getName());
                }
            }
        }
    } catch (Exception e) {
        logger.error("killed in action: '{}'", e.getMessage());
    }

    if (contentAdded) {
        logger.debug("xmlCompAttrib returned by createCompAttrib it's '{}'", xmlCompAttrib);
        return xmlCompAttrib;
    }
    return null;
}

From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

private CompAttrib createCompAttrib(MBeanServerConnection jmxServerConnection, ObjectInstance jmxObjectInstance,
        MBeanAttributeInfo jmxMBeanAttributeInfo) {
    Boolean contentAdded = false;

    CompAttrib xmlCompAttrib = xmlObjectFactory.createCompAttrib();
    xmlCompAttrib.setName(jmxMBeanAttributeInfo.getName());
    xmlCompAttrib.setType("Composite");
    xmlCompAttrib.setAlias(jmxMBeanAttributeInfo.getName());

    CompositeData compositeData;/*from  ww w  .  j  a  va 2  s .  com*/
    try {
        logger.debug("Try to get composite data");
        compositeData = (CompositeData) jmxServerConnection.getAttribute(jmxObjectInstance.getObjectName(),
                jmxMBeanAttributeInfo.getName());
        if (compositeData == null) {
            logger.warn(
                    "compositeData is null. jmxObjectInstance.getObjectName: '{}', jmxMBeanAttributeInfo.getName: '{}'");
        }
        if (compositeData != null) {
            logger.debug("compositeData.getCompositeType: '{}'", compositeData.getCompositeType());
            Set<String> keys = compositeData.getCompositeType().keySet();
            for (String key : keys) {
                Object compositeEntry = compositeData.get(key);
                if (numbers.contains(compositeEntry.getClass().getName())) {
                    contentAdded = true;
                    CompMember xmlCompMember = xmlObjectFactory.createCompMember();
                    xmlCompMember.setName(key);

                    logger.debug("composite member pure alias: '{}'",
                            jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key));
                    String alias = nameCutter
                            .trimByDictionary(jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key));
                    alias = createAndRegisterUniqueAlias(alias);
                    xmlCompMember.setAlias(alias);
                    logger.debug("composite member trimmed alias: '{}'", alias);

                    xmlCompMember.setType("gauge");
                    xmlCompAttrib.getCompMember().add(xmlCompMember);

                } else {
                    logger.debug("composite member key '{}' object's class '{}' was not a number.", key,
                            compositeEntry.getClass().getName());
                }
            }
        }
    } catch (Exception e) {
        logger.error("killed in action: '{}'", e.getMessage());
    }

    if (contentAdded) {
        logger.debug("xmlCompAttrib returned by createCompAttrib it's '{}'", xmlCompAttrib);
        return xmlCompAttrib;
    }
    return null;
}

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

public List<EmsAttribute> refreshAttributes() {
    if (info == null)
        loadSynchronous();// ww  w  .j a  v a  2 s . com

    MBeanAttributeInfo[] infos = new MBeanAttributeInfo[0];
    try {
        infos = this.info.getAttributes();
    } catch (RuntimeException e) {
        // If this throws an exception, there's a good chance our cached
    }

    // MUST be careful to only ask for types that we know we have
    // otherwise the RMI call will fail and we will get no data.
    List<String> nameList = new ArrayList<String>();
    for (MBeanAttributeInfo info : infos) {
        try {
            findType(info.getType());
            // If we know the type, add it to the list
            nameList.add(info.getName());
        } catch (ClassNotFoundException cnfe) {
            log.info("Can't load attribute type of [" + info.getName()
                    + "] because class not locally available");
        }
    }

    return refreshAttributes(nameList);
}

From source file:org.wso2.carbon.analytics.common.jmx.agent.JmxAgentWebInterface.java

/**
 * @param mBean    : The name of the MBean
 * @param url      : The URL for the JMX server
 * @param userName : The User name for the JMX server
 * @param password : The password for the JMX server
 * @return : The set of attributes in a MBean
 * @throws MalformedObjectNameException/*from   w ww . j ava  2  s  . com*/
 * @throws IntrospectionException
 * @throws InstanceNotFoundException
 * @throws IOException
 * @throws ReflectionException
 */
public String[][] getMBeanAttributeInfo(String mBean, String url, String userName, String password)
        throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, IOException,
        ReflectionException {

    JMXConnector jmxc = getJmxConnector(url, userName, password);

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName mBeanName = new ObjectName(mBean);

    MBeanAttributeInfo[] attrs = mbsc.getMBeanInfo(mBeanName).getAttributes();

    ArrayList<String[]> strAttrs = new ArrayList<String[]>();

    for (MBeanAttributeInfo info : attrs) {

        //check the suitability of the attribute
        try {
            Object result = mbsc.getAttribute(mBeanName, info.getName());

            //if this is an instance of a primary data type supported by cassandra
            if (result instanceof String || result instanceof Integer || result instanceof Double
                    || result instanceof Long || result instanceof Boolean || result instanceof Float) {
                strAttrs.add(new String[] { info.getName() });
            }

            //if this is a composite data type
            if (result instanceof CompositeData) {
                CompositeData cd = (CompositeData) result;
                ArrayList<String> keys = new ArrayList<String>();
                //add the attribute name
                keys.add(info.getName());
                for (String key : cd.getCompositeType().keySet()) {
                    //check whether the key returns a primary data type
                    Object attrValue = cd.get(key);
                    if (attrValue instanceof String || attrValue instanceof Integer
                            || attrValue instanceof Double || attrValue instanceof Long
                            || attrValue instanceof Boolean || attrValue instanceof Float) {
                        keys.add(key);
                    }
                }
                //if this composite data object has keys which returns attributes with
                // primary data types
                if (keys.size() > 1) {
                    strAttrs.add(keys.toArray(new String[keys.size()]));
                }
            }
        } catch (MBeanException e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());
        } catch (AttributeNotFoundException e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());
        } catch (UnmarshalException e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());
        } catch (RuntimeOperationsException e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());

        } catch (RuntimeMBeanException e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());
        } catch (ReflectionException e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());
        } catch (Exception e) {
            log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: "
                    + e.getMessage());
        }
    }

    //close the connection
    jmxc.close();

    return strAttrs.toArray(new String[strAttrs.size()][]);
}

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

public synchronized void loadSynchronous() {
    if (!loaded) {
        try {//w  ww.  jav a  2  s.  c o m
            info = connectionProvider.getMBeanServer().getMBeanInfo(this.objectName);

            if (info.getAttributes().length > 0) {

                this.attributes = new TreeMap<String, EmsAttribute>(String.CASE_INSENSITIVE_ORDER);
                for (MBeanAttributeInfo attributeInfo : info.getAttributes()) {
                    DAttribute attribute = new DAttribute(attributeInfo, this);
                    this.attributes.put(attributeInfo.getName(), attribute);
                }
            }

            if (info.getOperations().length > 0) {
                this.operations = new TreeMap<String, EmsOperation>(String.CASE_INSENSITIVE_ORDER);
                for (MBeanOperationInfo operationInfo : info.getOperations()) {
                    DOperation operation = new DOperation(operationInfo, this);
                    this.operations.put(operationInfo.getName(), operation);
                }
            }

            if (info.getNotifications().length > 0) {
                this.notifications = new TreeMap<String, EmsNotification>(String.CASE_INSENSITIVE_ORDER);
                for (MBeanNotificationInfo notificationInfo : info.getNotifications()) {
                    DNotification notification = new DNotification(notificationInfo, this);
                    this.notifications.put(notificationInfo.getName(), notification);
                }
            }

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

        } catch (Exception e) {
            unsupportedType = true;
            RuntimeException f = new EmsUnsupportedTypeException(
                    "Could not load MBean info, unsupported type on bean " + objectName, e);
            // TODO: Memory Leak below... don't do that
            //registerFailure(f);
            // TODO should we throw this here?
            //throw f;
        } finally {
            loaded = true;
        }
    }
}

From source file:org.echocat.jemoni.carbon.jmx.Jmx2CarbonBridge.java

@Nullable
protected AttributeDefinition findDefinitionFor(@Nonnull ObjectName objectName,
        @Nonnull MBeanAttributeInfo info) {
    final Descriptor descriptor = info.getDescriptor();
    final OpenType<?> openType = (OpenType<?>) descriptor.getFieldValue("openType");
    return findDefinitionFor(objectName, info, info.getName(), openType);
}

From source file:net.sbbi.upnp.jmx.UPNPMBeanService.java

private String getDeviceSSDP(MBeanInfo info) throws IllegalArgumentException {

    MBeanOperationInfo[] ops = info.getOperations();
    MBeanAttributeInfo[] atts = info.getAttributes();

    if ((ops == null || ops.length == 0) && (atts == null || atts.length == 0)) {
        throw new IllegalArgumentException(
                "MBean has no operation and no attribute and cannot be exposed as an UPNP device, provide at least one attribute");
    }/*  www  . j a  v  a 2 s.co  m*/
    Set deployedActionNames = new HashSet();
    operationsStateVariables = new HashMap();
    StringBuffer rtrVal = new StringBuffer();
    rtrVal.append("<?xml version=\"1.0\" ?>\r\n");
    rtrVal.append("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">\r\n");
    rtrVal.append("<specVersion><major>1</major><minor>0</minor></specVersion>\r\n");

    if (ops != null && ops.length > 0) {
        rtrVal.append("<actionList>\r\n");
        for (int i = 0; i < ops.length; i++) {
            MBeanOperationInfo op = ops[i];
            StringBuffer action = new StringBuffer();
            if (deployedActionNames.contains(op.getName())) {
                log.debug("The " + op.getName()
                        + " is allready deplyoed and cannot be reused, skipping operation deployment");
                continue;
            }
            action.append("<action>\r\n");
            action.append("<name>");
            action.append(op.getName());
            action.append("</name>\r\n");
            action.append("<argumentList>\r\n");
            // output argument
            action.append("<argument>\r\n");
            action.append("<name>");
            // TODO handle specific output vars
            String outVarName = op.getName() + "_out";
            String actionOutDataType = ServiceStateVariable.getUPNPDataTypeMapping(op.getReturnType());
            if (actionOutDataType == null)
                actionOutDataType = ServiceStateVariableTypes.STRING;
            action.append(outVarName);
            action.append("</name>\r\n");
            action.append("<direction>out</direction>\r\n");
            action.append("<relatedStateVariable>");
            action.append(outVarName);
            action.append("</relatedStateVariable>\r\n");
            action.append("</argument>\r\n");

            // handle now for all input argument
            boolean nonPrimitiveInputType = false;
            boolean duplicatedInputVarname = false;
            Map operationsInputStateVariables = new HashMap();
            if (op.getSignature() != null) {
                for (int z = 0; z < op.getSignature().length; z++) {
                    MBeanParameterInfo param = op.getSignature()[z];
                    // do some sanity checks
                    String actionInDataType = ServiceStateVariable.getUPNPDataTypeMapping(param.getType());
                    if (actionInDataType == null) {
                        nonPrimitiveInputType = true;
                        log.debug("The " + param.getType()
                                + " type is not an UPNP compatible data type, use only primitives");
                        break;
                    }
                    String inVarName = param.getName();
                    // check that if the name does allready exists it
                    // has the same type
                    String existing = (String) operationsStateVariables.get(inVarName);
                    if (existing != null && !existing.equals(actionInDataType)) {
                        String msg = "The operation " + op.getName() + " " + inVarName
                                + " parameter already exists for another method with another data type ("
                                + existing + ") either match the data type or change the parameter name"
                                + " in you MBeanParameterInfo object for this operation";
                        duplicatedInputVarname = true;
                        log.debug(msg);
                        break;
                    }
                    action.append("<argument>\r\n");
                    action.append("<name>");
                    operationsInputStateVariables.put(inVarName, actionInDataType);
                    action.append(inVarName);
                    action.append("</name>\r\n");
                    action.append("<direction>in</direction>\r\n");
                    action.append("<relatedStateVariable>");
                    action.append(inVarName);
                    action.append("</relatedStateVariable>\r\n");
                    action.append("</argument>\r\n");
                }
            }

            action.append("</argumentList>\r\n");
            action.append("</action>\r\n");
            // finally the action is only added to the UPNP SSDP if no problems have been detected
            // with the input parameters type and names.
            if (!nonPrimitiveInputType && !duplicatedInputVarname) {
                operationsStateVariables.putAll(operationsInputStateVariables);
                operationsStateVariables.put(outVarName, actionOutDataType);
                rtrVal.append(action.toString());
                deployedActionNames.add(op.getName());
            }
        }
        rtrVal.append("</actionList>\r\n");
    } else {
        rtrVal.append("<actionList/>\r\n");
    }

    // now append the operation created state vars
    rtrVal.append("<serviceStateTable>\r\n");

    for (Iterator i = operationsStateVariables.keySet().iterator(); i.hasNext();) {
        String name = (String) i.next();
        String type = (String) operationsStateVariables.get(name);
        // TODO handle sendevents with mbean notifications ???
        // TODO handle defaultValue and allowedValueList values
        rtrVal.append("<stateVariable sendEvents=\"no\">\r\n");
        rtrVal.append("<name>");
        rtrVal.append(name);
        rtrVal.append("</name>\r\n");
        rtrVal.append("<dataType>");
        rtrVal.append(type);
        rtrVal.append("</dataType>\r\n");
        rtrVal.append("</stateVariable>\r\n");
    }

    if (atts != null && atts.length > 0) {
        for (int i = 0; i < atts.length; i++) {
            MBeanAttributeInfo att = atts[i];
            if (att.isReadable()) {
                rtrVal.append("<stateVariable sendEvents=\"no\">\r\n");
                rtrVal.append("<name>");
                rtrVal.append(att.getName());
                rtrVal.append("</name>\r\n");
                rtrVal.append("<dataType>");
                // TODO check if this works
                String stateVarType = ServiceStateVariable.getUPNPDataTypeMapping(att.getType());
                if (stateVarType == null)
                    stateVarType = ServiceStateVariableTypes.STRING;
                rtrVal.append(stateVarType);
                rtrVal.append("</dataType>\r\n");
                rtrVal.append("</stateVariable>\r\n");
            }
        }
    }
    rtrVal.append("</serviceStateTable>\r\n");
    rtrVal.append("</scpd>");
    return rtrVal.toString();
}

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

@Override
public synchronized void storeConfiguration() {
    HashSet<DefaultConfigurationImpl> copy = new HashSet<DefaultConfigurationImpl>(IDToConfigurations.values());
    ConfigurationStore store = new ConfigurationStore();
    store.setServices(new ArrayList<ServiceStore>());
    for (DefaultConfigurationImpl config : copy) {
        ServiceStore serviceStore = new ServiceStore();
        serviceStore.setServiceID(config.getServiceID());
        serviceStore.setFactoryID(config.getFactoryID());

        Map<String, Object> configAttrs = config.getAttributes();
        Map<String, String> attributes = new HashMap<String, String>();
        try {//from ww  w  .  j a  va 2  s .co m
            for (MBeanAttributeInfo attrInfo : config.getMBeanInfo().getAttributes()) {
                if (attrInfo.isWritable()) {
                    try {
                        attributes.put(attrInfo.getName(), configAttrs.get(attrInfo.getName()).toString());
                    } catch (NullPointerException ex) {
                        logger.error("No property: " + attrInfo.getName());
                    }
                }
            }
        } catch (NullPointerException ex) {
            logger.error("Problem with config: " + config);
        }
        serviceStore.setAttributes(attributes);
        try {
            RifidiService target = config.getTarget();
            if (target != null && target instanceof AbstractSensor<?>) {
                serviceStore.setSessionDTOs(new HashSet<SessionDTO>());
                for (SensorSession session : ((AbstractSensor<?>) target).getSensorSessions().values()) {
                    serviceStore.getSessionDTOs().add(session.getDTO());
                }
            }
        } catch (RuntimeException e) {
            logger.warn("Target went away while trying to store it: " + e);
        }
        store.getServices().add(serviceStore);
    }

    try {
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        File file = persistanceResource.getFile();
        marshaller.marshal(store, file);
        logger.info("configuration saved at " + file);
    } catch (IOException e) {
        logger.error(e);
    } catch (JAXBException e) {
        logger.error(e);
    }
}

From source file:org.fishwife.jrugged.spring.jmx.TestWebMBeanAdapter.java

@Test
public void testGetAttributeMetadata() throws Exception {

    String attributeName1 = "attribute_name_1";
    MBeanAttributeInfo mockAttribute1 = createMock(MBeanAttributeInfo.class);

    String attributeName2 = "attribute_name_2";
    MBeanAttributeInfo mockAttribute2 = createMock(MBeanAttributeInfo.class);

    MBeanAttributeInfo[] attributeList = new MBeanAttributeInfo[2];
    attributeList[0] = mockAttribute1;//w  w w.  j av  a2 s.co  m
    attributeList[1] = mockAttribute2;
    expect(mockMBeanInfo.getAttributes()).andReturn(attributeList);
    expect(mockAttribute1.getName()).andReturn(attributeName1);
    expect(mockAttribute2.getName()).andReturn(attributeName2);

    replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockAttribute1, mockAttribute2);

    Map<String, MBeanAttributeInfo> attributeMap = webMBeanAdapter.getAttributeMetadata();

    assertEquals(2, attributeMap.size());
    assertEquals(mockAttribute1, attributeMap.get(attributeName1));
    assertEquals(mockAttribute2, attributeMap.get(attributeName2));

    verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockAttribute1, mockAttribute2);
}

From source file:org.springframework.jmx.access.MBeanClientInterceptor.java

/**
 * Loads the management interface info for the configured MBean into the caches.
 * This information is used by the proxy when determining whether an invocation matches
 * a valid operation or attribute on the management interface of the managed resource.
 *//*from  w w  w. j ava  2  s.  c om*/
private void retrieveMBeanInfo(MBeanServerConnection server) throws MBeanInfoRetrievalException {
    try {
        MBeanInfo info = server.getMBeanInfo(this.objectName);

        MBeanAttributeInfo[] attributeInfo = info.getAttributes();
        this.allowedAttributes = new HashMap<>(attributeInfo.length);
        for (MBeanAttributeInfo infoEle : attributeInfo) {
            this.allowedAttributes.put(infoEle.getName(), infoEle);
        }

        MBeanOperationInfo[] operationInfo = info.getOperations();
        this.allowedOperations = new HashMap<>(operationInfo.length);
        for (MBeanOperationInfo infoEle : operationInfo) {
            Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader);
            this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
        }
    } catch (ClassNotFoundException ex) {
        throw new MBeanInfoRetrievalException("Unable to locate class specified in method signature", ex);
    } catch (IntrospectionException ex) {
        throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]",
                ex);
    } catch (InstanceNotFoundException ex) {
        // if we are this far this shouldn't happen, but...
        throw new MBeanInfoRetrievalException(
                "Unable to obtain MBean info for bean [" + this.objectName
                        + "]: it is likely that this bean was unregistered during the proxy creation process",
                ex);
    } catch (ReflectionException ex) {
        throw new MBeanInfoRetrievalException("Unable to read MBean info for bean [ " + this.objectName + "]",
                ex);
    } catch (IOException ex) {
        throw new MBeanInfoRetrievalException("An IOException occurred when communicating with the "
                + "MBeanServer. It is likely that you are communicating with a remote MBeanServer. "
                + "Check the inner exception for exact details.", ex);
    }
}