Java Code Examples for javax.management.AttributeList#get()

The following examples show how to use javax.management.AttributeList#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MBeanHelper.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void matchValues(AttributeList list, Map<String, Object> expectedMap) {
  for (Entry<String, Object> entry : expectedMap.entrySet()) {
    boolean found = false;
    for (int i = 0; i < list.size(); i++) {
      Attribute attr = (Attribute) list.get(i);
      if (attr.getName().equals(entry.getKey())) {
        found = true;
        Log.getLogWriter().info(
            entry.getKey() + "--> JMX : " + attr.getValue() + " BB : "
                + entry.getValue());
        if (!attr.getValue().equals(entry.getValue())) {
          printAndSaveError("Attribute", null, attr, entry.getValue());
        }
      }
    }
    if (!found)
      throw new TestException("Error attribute " + entry.getKey()
          + " not found");
  }
}
 
Example 2
Source File: DataSourceConfigurationManagerService.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public AttributeList setAttributes( AttributeList attributeList )
{
    AttributeList list = new AttributeList();
    for ( int i = 0; i < list.size(); i++ ) {
        Attribute attribute = ( Attribute ) list.get( i );

        try {
            setAttribute( attribute );
            list.add( attribute );
        } catch ( AttributeNotFoundException | InvalidAttributeValueException | ReflectionException | MBeanException e ) {
            e.printStackTrace();
        }
    }

    return list;
}
 
Example 3
Source File: ConfigurationManagerService.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public AttributeList setAttributes( AttributeList attributeList )
{
    AttributeList list = new AttributeList();
    for( int i = 0; i < list.size(); i++ )
    {
        Attribute attribute = (Attribute) list.get( i );

        try
        {
            setAttribute( attribute );
            list.add( attribute );
        }
        catch( AttributeNotFoundException | InvalidAttributeValueException | ReflectionException | MBeanException e )
        {
            e.printStackTrace();
        }
    }

    return list;
}
 
Example 4
Source File: MBeanInfoViewer.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
public String retrieveStats(String mbeanName, String range, String[] dataSources, String function) {
    lazyConnect();

    try {
        AttributeList attrs = connection.getAttributes(new ObjectName(mbeanName),
                                                       new String[] { "StatisticHistory" });
        Attribute attr = (Attribute) attrs.get(0);
        // content of the RRD4J database backing file
        byte[] rrd4j = (byte[]) attr.getValue();

        return MBeanInfoViewer.rrdContent(rrd4j,
                                          MBeanInfoViewer.possibleModifyRange(range, dataSources, 'd'),
                                          dataSources,
                                          function);
    } catch (Exception e) {
        LOGGER.error("Could not retrieve statistics history, " + e.getMessage());
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: MBeanHelper.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void compareValues(AttributeList list,
    Map<String, Number> expectedMap, boolean considerExpectedCanBeGreater) {
  for (Entry<String, Number> entry : expectedMap.entrySet()) {
    boolean found = false;
    for (int i = 0; i < list.size(); i++) {
      Attribute attr = (Attribute) list.get(i);
      if (attr.getName().equals(entry.getKey())) {
        found = true;
        Log.getLogWriter().info(
            entry.getKey() + "--> JMX : " + attr.getValue() + " BB : "
                + entry.getValue());
        if (considerExpectedCanBeGreater ? (((Number) attr.getValue())
            .longValue() > entry.getValue().longValue()) : (!attr.getValue()
            .toString().equals(entry.getValue().toString()))) {
          printAndSaveError("Attribute", null, attr, entry.getValue());
        }
      }
    }
    if (!found)
      throw new TestException("Error attribute " + entry.getKey()
          + " not found");
  }
}
 
Example 6
Source File: MBeanHelper.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void matchValues(AttributeList list, Map<String, Object> expectedMap) {
  for (Entry<String, Object> entry : expectedMap.entrySet()) {
    boolean found = false;
    for (int i = 0; i < list.size(); i++) {
      Attribute attr = (Attribute) list.get(i);
      if (attr.getName().equals(entry.getKey())) {
        found = true;
        Log.getLogWriter().info(
            entry.getKey() + "--> JMX : " + attr.getValue() + " BB : "
                + entry.getValue());
        if (!attr.getValue().equals(entry.getValue())) {
          printAndSaveError("Attribute", null, attr, entry.getValue());
        }
      }
    }
    if (!found)
      throw new TestException("Error attribute " + entry.getKey()
          + " not found");
  }
}
 
Example 7
Source File: MBeanHelper.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void compareValues(AttributeList list,
    Map<String, Number> expectedMap, boolean considerExpectedCanBeGreater) {
  for (Entry<String, Number> entry : expectedMap.entrySet()) {
    boolean found = false;
    for (int i = 0; i < list.size(); i++) {
      Attribute attr = (Attribute) list.get(i);
      if (attr.getName().equals(entry.getKey())) {
        found = true;
        Log.getLogWriter().info(
            entry.getKey() + "--> JMX : " + attr.getValue() + " BB : "
                + entry.getValue());
        if (considerExpectedCanBeGreater ? (((Number) attr.getValue())
            .longValue() > entry.getValue().longValue()) : (!attr.getValue()
            .toString().equals(entry.getValue().toString()))) {
          printAndSaveError("Attribute", null, attr, entry.getValue());
        }
      }
    }
    if (!found)
      throw new TestException("Error attribute " + entry.getKey()
          + " not found");
  }
}
 
Example 8
Source File: SimplePerformanceMeter.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public static double getProcessCpuLoadInternal() {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    try {
        final ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
        final AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });

        if (list.isEmpty()) {
            return Double.NaN;
        }

        final Attribute att = (Attribute) list.get(0);
        final Double value = (Double) att.getValue();

        // usually takes a couple of seconds before we get real values
        if (value == -1.0) {
            return Double.NaN;
        }
        // returns a percentage value with 1 decimal point precision
        return ((int) (value * 1000) / 10.0);
    } catch (MalformedObjectNameException | NullPointerException | InstanceNotFoundException | ReflectionException e) {
        return Double.NaN;
    }
}
 
Example 9
Source File: BrokerStatsRetriever.java    From doctorkafka with Apache License 2.0 6 votes vote down vote up
public static double getProcessCpuLoad(MBeanServerConnection mbs)
    throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException,
           ReflectionException, IOException {
  ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
  AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"});

  if (list.isEmpty()) {
    return 0.0;
  }

  Attribute att = (Attribute) list.get(0);
  Double value = (Double) att.getValue();

  // usually takes a couple of seconds before we get real values
  if (value == -1.0) {
    return 0.0;
  }
  // returns a percentage value with 1 decimal point precision
  return ((int) (value * 1000) / 10.0);
}
 
Example 10
Source File: DefaultLoginConfig.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public AttributeList setAttributes(AttributeList attributeList)
{
   AttributeList list = new AttributeList();
   for(int n = 0; n < attributeList.size(); n ++)
   {
      Attribute attr = (Attribute) attributeList.get(n);
      try
      {
         setAttribute(attr);
         list.add(attr);
      }
      catch(Exception e)
      {
      }
   }
   return list;
}
 
Example 11
Source File: SyncStats.java    From aion with MIT License 6 votes vote down vote up
private static double getProcessCpuLoad() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    AttributeList list = null;
    try {
        ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
        list = mbs.getAttributes(name, new String[] {"ProcessCpuLoad"});
    } catch (InstanceNotFoundException | ReflectionException | MalformedObjectNameException e) {
        e.printStackTrace();
    }

    if (Objects.requireNonNull(list).isEmpty()) {
        return Double.NaN;
    }

    Attribute att = (Attribute) list.get(0);
    Double value = (Double) att.getValue();

    // usually takes a couple of seconds before we get real values
    if (value == -1.0) {
        return Double.NaN;
    }
    // returns a percentage value with 1 decimal point precision
    return ((int) (value * 1000) / 10.0);
}
 
Example 12
Source File: ClusterStatistics.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void updateClusterStatement(ObjectName mbeanName) throws IOException {

    try {
      AttributeList attributeList = this.mbs.getAttributes(mbeanName, GfxdConstants.STATEMENT_MBEAN_ATTRIBUTES);
      String statementDefinition = mbeanName.getKeyProperty("name");
      if (isQuoted(statementDefinition)) {
        statementDefinition = ObjectName.unquote(statementDefinition);
      }
      
      Statement statement = statementMap.get(statementDefinition);

      if (null == statement) {
        statement = new Statement();
        statement.setQueryDefinition(statementDefinition);
      }

      for (int i = 0; i < attributeList.size(); i++) {
       Attribute attribute = (Attribute) attributeList.get(i);
        updateAttribute(statement,attribute);
      }

      addClusterStatement(statementDefinition, statement);
    } catch (InstanceNotFoundException infe) {
      logger.warning(infe);
    } catch (ReflectionException re) {
      logger.warning(re);
    }
  }
 
Example 13
Source File: RemoteMBeanScheduler.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
public SchedulerMetaData getMetaData() throws SchedulerException {
    AttributeList attributeList = 
        getAttributes(
            new String[] {
                "schedulerName",
                "schedulerInstanceId",
                "inStandbyMode",
                "shutdown",
                "jobStoreClass",
                "threadPoolClass",
                "threadPoolSize",
                "version"
            });
    
    return new SchedulerMetaData(
            (String)attributeList.get(0),
            (String)attributeList.get(1),
            getClass(), true, isStarted(), 
            ((Boolean)attributeList.get(2)).booleanValue(), 
            ((Boolean)attributeList.get(3)).booleanValue(), 
            (Date)invoke("runningSince", new Object[] {}, new String[] {}), 
            ((Integer)invoke("numJobsExecuted", new Object[] {}, new String[] {})).intValue(),
            (Class)attributeList.get(4),
            ((Boolean)invoke("supportsPersistence", new Object[] {}, new String[] {})).booleanValue(),
            ((Boolean)invoke("isClustered", new Object[] {}, new String[] {})).booleanValue(),
            (Class)attributeList.get(5),
            ((Integer)attributeList.get(6)).intValue(),
            (String)attributeList.get(7));
}
 
Example 14
Source File: ClusterStatistics.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void updateClusterStatement(ObjectName mbeanName) throws IOException {

    try {
      AttributeList attributeList = this.mbs.getAttributes(mbeanName, GfxdConstants.STATEMENT_MBEAN_ATTRIBUTES);
      String statementDefinition = mbeanName.getKeyProperty("name");
      if (isQuoted(statementDefinition)) {
        statementDefinition = ObjectName.unquote(statementDefinition);
      }
      
      Statement statement = statementMap.get(statementDefinition);

      if (null == statement) {
        statement = new Statement();
        statement.setQueryDefinition(statementDefinition);
      }

      for (int i = 0; i < attributeList.size(); i++) {
       Attribute attribute = (Attribute) attributeList.get(i);
        updateAttribute(statement,attribute);
      }

      addClusterStatement(statementDefinition, statement);
    } catch (InstanceNotFoundException infe) {
      logger.warning(infe);
    } catch (ReflectionException re) {
      logger.warning(re);
    }
  }
 
Example 15
Source File: RegistrationUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void copyServerPool(HashMap serverPools, String newPoolName, String operationName, ServerInterface mejb){
    try{
        String updatedPoolName = newPoolName + POOL_EXTENSION;
        if(! serverPools.containsKey(updatedPoolName)){
            ObjectName serverPoolObj = (ObjectName)serverPools.get(newPoolName);
            Map attributeInfos = ResourceUtils.getResourceAttributeNames(serverPoolObj, mejb);
            attributeInfos.remove("name");
            String[] attrNames = (String[]) attributeInfos.keySet().toArray(new String[attributeInfos.size()]);
            AttributeList attrList = mejb.getAttributes(serverPoolObj, attrNames);
            Attribute nameAttr = new Attribute("name", updatedPoolName);
            attrList.add(nameAttr);
                      
            Properties props = new Properties();
            AttributeList propsList = (AttributeList)mejb.invoke(serverPoolObj, WizardConstants.__GetProperties, null, null);             
            for(int i=0; i<propsList.size(); i++){
                Attribute propAttr = (Attribute)propsList.get(i);
                String propName = propAttr.getName();
                Object propValue = propAttr.getValue();
                if(propValue != null){
                    props.put(propName, propValue);
                }    
            }
            
            Object[] params = new Object[]{attrList, props, null};
            ResourceUtils.createResource(operationName, params, mejb);
        }
    }catch(Exception ex){  
        //Unable to copy pool
        System.out.println(ex.getLocalizedMessage());
    }
}
 
Example 16
Source File: ResourceUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static HashMap getObjMap(AttributeList attrList){
    HashMap attrs = new HashMap();
    for(int k=0; k<attrList.size(); k++){
        Attribute currAttr = (Attribute)attrList.get(k);
        String pname = currAttr.getName();
        Object pObjvalue = currAttr.getValue();
        attrs.put(pname, pObjvalue);
    }
    return attrs;
}
 
Example 17
Source File: MBeanInfoViewer.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Return the informations about the Scheduler MBean as a Map.
 * The first time this method is called it connects to the JMX connector server.
 * The default behavior will try to establish a connection using RMI protocol, if it fails
 * the RO (Remote Object) protocol is used.
 *
 * @param mbeanNameAsString the object name of the MBean
 * @return the informations about the MBean as a formatted string
 */
public synchronized Map<String, String> getMappedInfo(final String mbeanNameAsString) {
    HashMap<String, String> result = new HashMap<>();
    // Lazy initial connection
    this.lazyConnect();
    try {
        // If new name create a new ObjectName and refresh attribute names
        if (this.mbeanName == null || !this.mbeanName.getCanonicalName().equals(mbeanNameAsString)) {
            this.mbeanName = new ObjectName(mbeanNameAsString);
            final MBeanAttributeInfo[] attrs = this.connection.getMBeanInfo(this.mbeanName).getAttributes();
            List<String> attrNames = new ArrayList<>(attrs.length - 1);
            for (int i = 0; i < attrs.length; i++) {
                // reading only primitive or string-type attributes
                if (isPrimitive(attrs[i].getType()) || String.class.getName().equals(attrs[i].getType())) {
                    attrNames.add(attrs[i].getName());
                }
            }
            this.names = attrNames.toArray(new String[] {});
        }
        // Get the list of attributes in a single JMX call
        final AttributeList list = this.connection.getAttributes(this.mbeanName, this.names);
        for (int i = 0; i < this.names.length; i++) {
            final String attName = this.names[i];
            Object value = "Unavailable";
            for (int j = 0; j < list.size(); j++) {
                final Attribute a = (Attribute) list.get(j);
                if (a.getName().equals(attName)) {
                    value = a.getValue();
                    break;
                }
            }
            result.put(attName, value.toString());
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException("Cannot retrieve JMX informations from Selected Bean", e);
    }
}
 
Example 18
Source File: ResourceUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void updateResourceAttributes(ObjectName objName, AttributeList attrList, ServerInterface mejb) throws Exception {
    try{
        Map attributeInfos = getResourceAttributeNames(objName, mejb);
        String[] attrNames = (String[]) attributeInfos.keySet().toArray(new String[attributeInfos.size()]);

        //Attributes from server
        AttributeList existAttrList = mejb.getAttributes(objName, attrNames);
        if (existAttrList != null) {
            for (int i = 0; i < existAttrList.size(); i++) {
                Attribute existAttr = (Attribute) existAttrList.get(i);
                String existAttrName = existAttr.getName();
                for (int j = 0; j < attrList.size(); j++) {
                    Attribute resAttr = (Attribute) attrList.get(j);
                    String resAttrName = resAttr.getName();
                    if (existAttrName.equals(resAttrName)) {
                        if (resAttr.getValue() == null && existAttr.getValue() != null) {
                            mejb.setAttribute(objName, resAttr);
                        } else if (existAttr.getValue() == null) { //NOI18N
                            if ((resAttr.getValue() != null) && (!resAttr.getValue().toString().equals(""))) {
                                mejb.setAttribute(objName, resAttr);
                            }
                        } else {
                            if (!resAttr.getValue().toString().equals(existAttr.getValue().toString())) {
                                mejb.setAttribute(objName, resAttr);
                            }
                        }
                    }//if
                }//loop through project's resource Attributes
            }
        }
    }catch(Exception ex){
        throw new Exception(ex.getLocalizedMessage(), ex);
    }
}
 
Example 19
Source File: RemoteMBeanScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private Attribute getAttribute(AttributeList attributeList, int index) {
    return (Attribute)attributeList.get(index);
}
 
Example 20
Source File: MBeanInfoViewer.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Return the informations about the Scheduler MBean as a formatted string.
 * The first time this method is called it connects to the JMX connector server.
 * The default behavior will try to establish a connection using RMI protocol, if it fails
 * the RO (Remote Object) protocol is used.
 *
 * @param mbeanNameAsString the object name of the MBean
 * @return the informations about the MBean as a formatted string
 */
@Deprecated
public String getInfo(final String mbeanNameAsString) {
    // Lazy initial connection
    this.lazyConnect();
    try {
        int padding = 0;
        // If new name create a new ObjectName and refresh attribute names
        if (this.mbeanName == null || !this.mbeanName.getCanonicalName().equals(mbeanNameAsString)) {
            this.mbeanName = new ObjectName(mbeanNameAsString);
            final MBeanAttributeInfo[] attrs = this.connection.getMBeanInfo(this.mbeanName).getAttributes();

            this.names = new String[attrs.length];
            for (int i = 0; i < attrs.length; i++) {
                String name = attrs[i].getName();
                if (name.length() > padding) {
                    padding = name.length();
                }
                this.names[i] = name;
            }
            padding += 2;
        }
        // Get the list of attributes in a single JMX call  
        final AttributeList list = this.connection.getAttributes(this.mbeanName, this.names);
        final StringBuilder out = new StringBuilder();
        for (int i = 0; i < this.names.length; i++) {
            final String attName = this.names[i];
            Object value = "Unavailable";
            for (int j = 0; j < list.size(); j++) {
                final Attribute a = (Attribute) list.get(j);
                if (a.getName().equals(attName)) {
                    value = a.getValue();
                    break;
                }
            }
            out.append(String.format("  %1$-" + padding + "s" + value + "\n", attName));
        }
        return out.toString();
    } catch (Exception e) {
        throw new RuntimeException("Cannot retrieve JMX informations from Selected Bean", e);
    }
}