Package javax.management

Examples of javax.management.MBeanInfo


    void addMBean(ObjectName beanName)
    {
      try
      {
        MBeanInfo info = _server.getMBeanInfo(beanName);
        MBeanAttributeInfo[] infos = info.getAttributes();
        _beanValueMap.put(beanName.toString(), new HashMap<String, Object>());
        for(MBeanAttributeInfo infoItem : infos)
        {
          Object val = _server.getAttribute(beanName, infoItem.getName());
          // System.out.println("         " + infoItem.getName() + " : " + _server.getAttribute(beanName, infoItem.getName()) + " type : " + infoItem.getType());
View Full Code Here


    {
      List<ObjectName> errorMBeans = new ArrayList<ObjectName>();
      _logger.info("Sampling " + _mbeanNames.size() + " beans");
      for(ObjectName beanName : _mbeanNames.keySet())
      {
        MBeanInfo info;
        try
        {
          info = _mbeanServer.getMBeanInfo(beanName);
        }
        catch (Exception e)
        {
          _logger.error( e.getMessage()+" removing it");
          errorMBeans.add(beanName);
          continue;
        }
        if(!info.getClassName().equals(_beanClassName))
        {
          _logger.warn("Skip: className "+info.getClassName() + " expected : "+ _beanClassName);
          continue;
        }
        StringBuffer line = new StringBuffer();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss:SSS");
        String date = dateFormat.format(new Date());
        line.append(date + " ");
        line.append(beanName.toString() + " ");
       
        MBeanAttributeInfo[] infos = info.getAttributes();
        Map<String, MBeanAttributeInfo> infoMap = new HashMap<String, MBeanAttributeInfo>();
        for(MBeanAttributeInfo infoItem : infos)
        {
          infoMap.put(infoItem.getName(), infoItem);
        }
       
        for(String outputField : _outputFields)
        {
          try
          {
            if(infoMap.containsKey(outputField))
            {
              Object mbeanAttributeValue = _mbeanServer.getAttribute(beanName, outputField);
              line.append(mbeanAttributeValue.toString() + " ");
            }
            else
            {
              _logger.warn(outputField + " not found");
              line.append("null ");
            }
          }
          catch (Exception e)
          {
            _logger.error("Error:", e);
            line.append("null ");
            continue;
          }
        }
        MBeanOperationInfo[] operations = info.getOperations();
        Map<String, MBeanOperationInfo> opeMap = new HashMap<String, MBeanOperationInfo>();
        for(MBeanOperationInfo opeItem : operations)
        {
          opeMap.put(opeItem.getName(), opeItem);
        }
View Full Code Here

    return copy;
  }

  protected void init() {
    List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
    MBeanInfo parentInfo = super.getMBeanInfo();
    List<String> parentAttributes = new ArrayList<String>();
    for (MBeanAttributeInfo attr : parentInfo.getAttributes()) {
      attributes.add(attr);
      parentAttributes.add(attr.getName());
    }

    this.registryLength = this.registry.getMetricsList().size();

    for (MetricsBase metric : this.registry.getMetricsList()) {
      if (metric.getName() == null || parentAttributes.contains(metric.getName()))
        continue;

      // add on custom HBase metric types
      if (metric instanceof MetricsRate) {
        attributes.add( new MBeanAttributeInfo(metric.getName(),
            "java.lang.Float", metric.getDescription(), true, false, false) );
        extendedAttributes.put(metric.getName(), metric);
      } else if (metric instanceof MetricsString) {
        attributes.add( new MBeanAttributeInfo(metric.getName(),
            "java.lang.String", metric.getDescription(), true, false, false) );
        extendedAttributes.put(metric.getName(), metric);
        LOG.info("MetricsString added: " + metric.getName());
      } else if (metric instanceof MetricsHistogram) {

        String metricName = metric.getName() + MetricsHistogram.NUM_OPS_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Long", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.MIN_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Long", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.MAX_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Long", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.MEAN_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Float", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.STD_DEV_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Float", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.MEDIAN_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Float", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Float", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Float", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);

        metricName = metric.getName() + MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME;
        attributes.add(new MBeanAttributeInfo(metricName,
            "java.lang.Float", metric.getDescription(), true, false, false));
        extendedAttributes.put(metricName, metric);
      }
      // else, its probably a hadoop metric already registered. Skip it.
    }

    LOG.info("new MBeanInfo");
    this.extendedInfo = new MBeanInfo( this.getClass().getName(),
        this.description, attributes.toArray( new MBeanAttributeInfo[0] ),
        parentInfo.getConstructors(), parentInfo.getOperations(),
        parentInfo.getNotifications() );
  }
View Full Code Here

    public void onMBeanRegistered(MBeanServerConnection server,
        MBeanServerNotification mbsNotification)
    {
      try
      {
        MBeanInfo info = _server.getMBeanInfo(mbsNotification.getMBeanName());
        MBeanAttributeInfo[] infos = info.getAttributes();
        _beanValueMap.put(mbsNotification.getMBeanName().toString(), new ConcurrentHashMap<String, Object>());
        for (MBeanAttributeInfo infoItem : infos)
        {
          Object val = _server.getAttribute(mbsNotification.getMBeanName(), infoItem.getName());
          System.out.println("         " + infoItem.getName() + " : "
View Full Code Here

    public void refresh() throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, AttributeNotFoundException, MBeanException
    {
      for(String beanName: _beanValueMap.keySet())
      {
        ObjectName objName = new ObjectName(beanName);
        MBeanInfo info = _server.getMBeanInfo(objName);
        MBeanAttributeInfo[] infos = info.getAttributes();
        _beanValueMap.put(objName.toString(), new HashMap<String, Object>());
        for(MBeanAttributeInfo infoItem : infos)
        {
          Object val = _server.getAttribute(objName, infoItem.getName());
          System.out.println("         " + infoItem.getName() + " : " + _server.getAttribute(objName, infoItem.getName()) + " type : " + infoItem.getType());
View Full Code Here

            MBeanGBeanBridge mbeanGBeanBridge;
            synchronized (this) {
                if (registry.containsKey(abstractName)) {
                    return;
                }
                MBeanInfo mbeanInfo = JMXUtil.toMBeanInfo(kernel.getGBeanInfo(abstractName));
                mbeanGBeanBridge = new MBeanGBeanBridge(kernel, abstractName, abstractName.getObjectName(), mbeanInfo);
                registry.put(abstractName, mbeanGBeanBridge);
            }
            mbeanServer.registerMBean(mbeanGBeanBridge, mbeanGBeanBridge.getObjectName());
        } catch (GBeanNotFoundException e) {
View Full Code Here

        } else {
            args = rawArgs.split(",");
        }

        try {
            final MBeanInfo minfo = server.getMBeanInfo(on);
            final MBeanOperationInfo[] methods = minfo.getOperations();

            MBeanOperationInfo operation = null;
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().equals(name)) {
                    operation = methods[i];
View Full Code Here

        final MBeanServer mBeanServer = LocalMBeanServer.get();
        final String newValue = cmd.substring(split[0].length() + split[1].length() + 1).trim();
        try {
            final ObjectName oname = new ObjectName(split[1]);
            final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname);
            final MBeanAttributeInfo attrs[] = minfo.getAttributes();

            String type = String.class.getName();
            for (int i = 0; i < attrs.length; i++) {
                if (attrs[i].getName().equals(split[0])) {
                    type = attrs[i].getType();
View Full Code Here

        while (it.hasNext()) {
            ObjectName oname = it.next();
            streamManager.writeOut("Name: " + oname.toString());

            try {
                final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname);
                String code = minfo.getClassName();
                if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
                    code = (String) mBeanServer.getAttribute(oname, "modelerType");
                }
                streamManager.writeOut("  + modelerType: " + code);

                MBeanAttributeInfo attrs[] = minfo.getAttributes();
                Object value = null;

                for (int i = 0; i < attrs.length; i++) {
                    if (!attrs[i].isReadable()) {
                        continue;
View Full Code Here

            expectedValues.put(s + ".Variance", 0.0);
        }

        List<MBeanAttributeInfo> actualAttributes = new ArrayList<MBeanAttributeInfo>();
        Map<String, Object> actualValues = new HashMap<String, Object>();
        MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);
        for (MBeanAttributeInfo info : beanInfo.getAttributes()) {
            actualAttributes.add(info);
            actualValues.put(info.getName(), server.getAttribute(invocationsName, info.getName()));
        }

        //Verify invocation attributes and values
        assertEquals(expectedAttributes, actualAttributes);
        for (Map.Entry<String, Object> entry : actualValues.entrySet()) {
            if (!expectedValues.get(entry.getKey()).equals(actualValues.get(entry.getKey()))) {
                System.out.println("2. " + entry.getKey() + " => " + entry.getValue() + "/" + expectedValues.get(entry.getKey()));
            }
        }
        assertEquals(expectedValues, actualValues);

        // Grab invocation mbean operations
        MBeanParameterInfo[] invocationParameters1 = {
                new MBeanParameterInfo("excludeRegex", "java.lang.String", "\"\""),
                new MBeanParameterInfo("includeRegex", "java.lang.String", "\"\"")};
        MBeanParameterInfo[] invocationParameters2 = {
                new MBeanParameterInfo("p1", "int", "")};

        List<MBeanOperationInfo> expectedOperations = new ArrayList<MBeanOperationInfo>();
        expectedOperations.add(new MBeanOperationInfo(
                "FilterAttributes",
                "Filters the attributes that show up in the MBeanInfo.  The exclude is applied first, then any attributes that match the include are re-added.  It may be required to disconnect and reconnect the JMX console to force a refresh of the MBeanInfo",
                invocationParameters1, "void", MBeanOperationInfo.UNKNOWN));

        for (String s : methods) {
            expectedOperations.add(new MBeanOperationInfo(s + ".setSampleSize", "", invocationParameters2, "void", MBeanOperationInfo.UNKNOWN));
            expectedOperations.add(new MBeanOperationInfo(s + ".sortedValues", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
            expectedOperations.add(new MBeanOperationInfo(s + ".values", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
        }

        List<MBeanOperationInfo> actualOperations1 = new ArrayList<MBeanOperationInfo>();
        actualOperations1.addAll(Arrays.asList(beanInfo.getOperations()));

        //Verify invocation operation information and remove bean.
        assertEquals(expectedOperations, actualOperations1);
    }
View Full Code Here

TOP

Related Classes of javax.management.MBeanInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.