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

The following examples show how to use javax.management.AttributeList#size() . 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: BaseModelMBean.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Set the values of several attributes of this MBean.
 *
 * @param attributes THe names and values to be set
 *
 * @return The list of attributes that were set and their new values
 */
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList response = new AttributeList();

    // Validate the input parameters
    if (attributes == null)
        return response;
    
    // Prepare and return our response, eating all exceptions
    String names[] = new String[attributes.size()];
    int n = 0;
    Iterator<?> items = attributes.iterator();
    while (items.hasNext()) {
        Attribute item = (Attribute) items.next();
        names[n++] = item.getName();
        try {
            setAttribute(item);
        } catch (Exception e) {
            // Ignore all exceptions
        }
    }

    return (getAttributes(names));

}
 
Example 3
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 4
Source File: ResourceUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void addNewExtraProperties(ObjectName objName, Properties props, AttributeList attrList, ServerInterface mejb) throws Exception {
    try{
        String[] signature = new String[]{"javax.management.Attribute"};  //NOI18N
        Object[] params = null;
        if(props.size() > attrList.size()){
            java.util.Enumeration listProps = props.propertyNames();
            while(listProps.hasMoreElements()){
                String propName = listProps.nextElement().toString();
                if(! attrList.contains(propName)){
                    Attribute attr = new Attribute(propName, props.getProperty(propName));
                    params = new Object[]{attr};
                    mejb.invoke(objName, __SetProperty, params, signature);
                }
            }//while
        }
    }catch(Exception ex){
        throw new Exception(ex.getLocalizedMessage(), ex);
    }
}
 
Example 5
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 6
Source File: BaseModelMBean.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Set the values of several attributes of this MBean.
 *
 * @param attributes THe names and values to be set
 *
 * @return The list of attributes that were set and their new values
 */
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList response = new AttributeList();

    // Validate the input parameters
    if (attributes == null)
        return response;

    // Prepare and return our response, eating all exceptions
    String names[] = new String[attributes.size()];
    int n = 0;
    Iterator<?> items = attributes.iterator();
    while (items.hasNext()) {
        Attribute item = (Attribute) items.next();
        names[n++] = item.getName();
        try {
            setAttribute(item);
        } catch (Exception e) {
            // Ignore all exceptions
        }
    }

    return getAttributes(names);

}
 
Example 7
Source File: BaseModelMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Set the values of several attributes of this MBean.
 *
 * @param attributes THe names and values to be set
 *
 * @return The list of attributes that were set and their new values
 */
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList response = new AttributeList();

    // Validate the input parameters
    if (attributes == null)
        return response;
    
    // Prepare and return our response, eating all exceptions
    String names[] = new String[attributes.size()];
    int n = 0;
    Iterator<?> items = attributes.iterator();
    while (items.hasNext()) {
        Attribute item = (Attribute) items.next();
        names[n++] = item.getName();
        try {
            setAttribute(item);
        } catch (Exception e) {
            // Ignore all exceptions
        }
    }

    return (getAttributes(names));

}
 
Example 8
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 9
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 10
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 11
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 12
Source File: MBeanSupport.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 13
Source File: MBeanSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 14
Source File: MBeanSupport.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 15
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 16
Source File: MBeanSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 17
Source File: SoaBundle.java    From soabase with Apache License 2.0 5 votes vote down vote up
private void addMetrics(Environment environment)
{
    Metric metric = new Gauge<Double>()
    {
        private double lastValue = 0.0;

        @Override
        public Double getValue()
        {
            try
            {
                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
                ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
                AttributeList list = mbs.getAttributes(name, new String[]{"SystemCpuLoad"});
                if ( (list != null) && (list.size() > 0) )
                {
                    // unfortunately, this bean reports bad values occasionally. Filter them out.
                    Object value = list.asList().get(0).getValue();
                    double d = (value instanceof Number) ? ((Number)value).doubleValue() : 0.0;
                    d = ((d > 0.0) && (d < 1.0)) ? d : lastValue;
                    lastValue = d;
                    return d;
                }
            }
            catch ( Exception ignore )
            {
                // ignore
            }
            return lastValue;
        }
    };
    environment.metrics().register("system.cpu.load", metric);
}
 
Example 18
Source File: MBeanSupport.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
Example 19
Source File: MBeanSupport.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
 
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);
    }
}