当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.getValue方法代码示例

本文整理汇总了Java中javax.management.Attribute.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.getValue方法的具体用法?Java Attribute.getValue怎么用?Java Attribute.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.Attribute的用法示例。


在下文中一共展示了Attribute.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: if

import javax.management.Attribute; //导入方法依赖的package包/类
/**
 * Send an <code>AttributeChangeNotification</code> to all registered
 * listeners.
 *
 * @param oldValue The original value of the <code>Attribute</code>
 * @param newValue The new value of the <code>Attribute</code>
 *
 * @exception MBeanException if an object initializer throws an
 *  exception
 * @exception RuntimeOperationsException wraps IllegalArgumentException
 *  when the specified notification is <code>null</code> or invalid
 */
@Override
public void sendAttributeChangeNotification
    (Attribute oldValue, Attribute newValue)
    throws MBeanException, RuntimeOperationsException {

    // Calculate the class name for the change notification
    String type = null;
    if (newValue.getValue() != null)
        type = newValue.getValue().getClass().getName();
    else if (oldValue.getValue() != null)
        type = oldValue.getValue().getClass().getName();
    else
        return;  // Old and new are both null == no change

    AttributeChangeNotification notification =
        new AttributeChangeNotification
        (this, 1, System.currentTimeMillis(),
         "Attribute value has changed",
         oldValue.getName(), type,
         oldValue.getValue(), newValue.getValue());
    sendAttributeChangeNotification(notification);

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:BaseModelMBean.java

示例2: getCpuLoad

import javax.management.Attribute; //导入方法依赖的package包/类
/**
 * Get CPU Load of Host System
 *
 * @author http://stackoverflow.com/questions/18489273/how-to-get-percentage-of-cpu-usage-of-os-from-java
 */
private double getCpuLoad() {
	try {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
		AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"});

		if (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);
	} catch (Exception e) {
		return Double.NaN;
	}
}
 
开发者ID:twitch4j,项目名称:twitch4j-chatbot,代码行数:27,代码来源:Diagnostics.java

示例3: getProcessCpuLoad

import javax.management.Attribute; //导入方法依赖的package包/类
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);
}
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:21,代码来源:BrokerStatsRetriever.java

示例4: sendAttributeChangeNotification

import javax.management.Attribute; //导入方法依赖的package包/类
public void sendAttributeChangeNotification(Attribute oldAttribute, Attribute newAttribute)
    throws MBeanException, RuntimeOperationsException {
  if (oldAttribute == null || newAttribute == null)
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_ATTRIBUTE_CANNOT_BE_NULL.toLocalizedString()));
  if (!oldAttribute.getName().equals(newAttribute.getName()))
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_ATTRIBUTE_NAMES_CANNOT_BE_DIFFERENT.toLocalizedString()));

  // TODO: the source must be the object name of the MBean if the listener was registered through
  // MBeanServer
  Object oldValue = oldAttribute.getValue();
  AttributeChangeNotification n = new AttributeChangeNotification(this, 1,
      System.currentTimeMillis(), "Attribute value changed", oldAttribute.getName(),
      oldValue == null ? null : oldValue.getClass().getName(), oldValue, newAttribute.getValue());
  sendAttributeChangeNotification(n);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:MX4JModelMBean.java

示例5: getProcessCpuLoad

import javax.management.Attribute; //导入方法依赖的package包/类
public static double getProcessCpuLoad() {
	double cpuLoad;
	try {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
		AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });

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

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

		if(value == -1.0) {
			return Double.NaN;
		}

		cpuLoad = value * 100d;
	} catch (InstanceNotFoundException | ReflectionException | MalformedObjectNameException err) {
		cpuLoad = Double.NaN;
	}

	return cpuLoad;
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:26,代码来源:Utils.java

示例6: getCpuLoad

import javax.management.Attribute; //导入方法依赖的package包/类
private static double getCpuLoad() {
	// http://stackoverflow.com/questions/18489273/how-to-get-percentage-of-cpu-usage-of-os-from-java
	try {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
		AttributeList list = mbs.getAttributes(name, new String[]{ "ProcessCpuLoad" });

		if (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);
	} catch(Exception e) {
		return Double.NaN;
	}
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:23,代码来源:Diagnostics.java

示例7: sendAttributeChangeNotification

import javax.management.Attribute; //导入方法依赖的package包/类
/**
 * Send an <code>AttributeChangeNotification</code> to all registered
 * listeners.
 *
 * @param oldValue
 *            The original value of the <code>Attribute</code>
 * @param newValue
 *            The new value of the <code>Attribute</code>
 *
 * @exception MBeanException
 *                if an object initializer throws an exception
 * @exception RuntimeOperationsException
 *                wraps IllegalArgumentException when the specified
 *                notification is <code>null</code> or invalid
 */
@Override
public void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue)
		throws MBeanException, RuntimeOperationsException {

	// Calculate the class name for the change notification
	String type = null;
	if (newValue.getValue() != null)
		type = newValue.getValue().getClass().getName();
	else if (oldValue.getValue() != null)
		type = oldValue.getValue().getClass().getName();
	else
		return; // Old and new are both null == no change

	AttributeChangeNotification notification = new AttributeChangeNotification(this, 1, System.currentTimeMillis(),
			"Attribute value has changed", oldValue.getName(), type, oldValue.getValue(), newValue.getValue());
	sendAttributeChangeNotification(notification);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:34,代码来源:BaseModelMBean.java

示例8: getAllMBeans

import javax.management.Attribute; //导入方法依赖的package包/类
public static Map<String, Map<String, String>> getAllMBeans() {
  Map<String, Map<String, String>> mbeanMap = Maps.newHashMap();
  Set<ObjectInstance> queryMBeans = null;
  try {
    queryMBeans = mbeanServer.queryMBeans(null, null);
  } catch (Exception ex) {
    LOG.error("Could not get Mbeans for monitoring", ex);
    Throwables.propagate(ex);
  }
  for (ObjectInstance obj : queryMBeans) {
    try {
      if (!obj.getObjectName().toString().startsWith("org.apache.flume")) {
        continue;
      }
      MBeanAttributeInfo[] attrs = mbeanServer.getMBeanInfo(obj.getObjectName()).getAttributes();
      String[] strAtts = new String[attrs.length];
      for (int i = 0; i < strAtts.length; i++) {
        strAtts[i] = attrs[i].getName();
      }
      AttributeList attrList = mbeanServer.getAttributes(obj.getObjectName(), strAtts);
      String component = obj.getObjectName().toString().substring(
          obj.getObjectName().toString().indexOf('=') + 1);
      Map<String, String> attrMap = Maps.newHashMap();

      for (Object attr : attrList) {
        Attribute localAttr = (Attribute) attr;
        if (localAttr.getName().equalsIgnoreCase("type")) {
          component = localAttr.getValue() + "." + component;
        }
        attrMap.put(localAttr.getName(), localAttr.getValue().toString());
      }
      mbeanMap.put(component, attrMap);
    } catch (Exception e) {
      LOG.error("Unable to poll JMX for metrics.", e);
    }
  }
  return mbeanMap;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:39,代码来源:JMXPollUtil.java

示例9: getDoubleValue

import javax.management.Attribute; //导入方法依赖的package包/类
private Double getDoubleValue(AttributeList attributes, String name) {
  List<Attribute> _attributes = attributes.asList();
  for (Attribute attr : _attributes) {
    if (attr.getName().equalsIgnoreCase(name)) {
      return (Double) attr.getValue();
    }
  }
  return 0D;
}
 
开发者ID:chickling,项目名称:kmanager,代码行数:10,代码来源:KafkaMetrics.java

示例10: cloneAttribute

import javax.management.Attribute; //导入方法依赖的package包/类
/**
 * Clone attribute.
 */
private Attribute cloneAttribute(Attribute attribute) {
    if (attribute != null) {
        if (!attribute.getClass().equals(Attribute.class)) {
            return new Attribute(attribute.getName(), attribute.getValue());
        }
    }
    return attribute;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:JmxMBeanServer.java

示例11: setAttribute

import javax.management.Attribute; //导入方法依赖的package包/类
public final void setAttribute(Attribute attribute)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {
    final String name = attribute.getName();
    final Object value = attribute.getValue();
    perInterface.setAttribute(resource, name, value, getCookie());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:MBeanSupport.java

示例12: getLongValue

import javax.management.Attribute; //导入方法依赖的package包/类
private Long getLongValue(AttributeList attributes, String name) {
  List<Attribute> _attributes = attributes.asList();
  for (Attribute attr : _attributes) {
    if (attr.getName().equalsIgnoreCase(name)) {
      return (Long) attr.getValue();
    }
  }
  return 0L;
}
 
开发者ID:chickling,项目名称:kmanager,代码行数:10,代码来源:KafkaMetrics.java

示例13: getAttribute

import javax.management.Attribute; //导入方法依赖的package包/类
@Override
public Object getAttribute(String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
  updateJmxCache();
  synchronized(this) {
    Attribute a = attrCache.get(attribute);
    if (a == null) {
      throw new AttributeNotFoundException(attribute +" not found");
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(attribute +": "+ a);
    }
    return a.getValue();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:MetricsSourceAdapter.java

示例14: executeStrategy

import javax.management.Attribute; //导入方法依赖的package包/类
@Override
@SuppressWarnings("IllegalCatch")
void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on,
        ServiceRegistryWrapper services) throws ConfigHandlingException {

    for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
        try {
            AttributeConfigElement ace = configAttributeEntry.getValue();

            if (!ace.getResolvedValue().isPresent()) {
                LOG.debug("Skipping attribute {} for {}", configAttributeEntry.getKey(), on);
                continue;
            }

            Object toBeMergedIn = ace.getResolvedValue().get();
            // Get the existing values so we can merge the new values with them.
            Attribute currentAttribute = ta.getAttribute(on, ace.getJmxName());
            Object oldValue = currentAttribute != null ? currentAttribute.getValue() : null;
            // Merge value with currentValue
            toBeMergedIn = merge(oldValue, toBeMergedIn);
            ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), toBeMergedIn));
            LOG.debug("Attribute {} set to {} for {}", configAttributeEntry.getKey(), toBeMergedIn, on);
        } catch (RuntimeException e) {
            LOG.error("Error while merging object names of {}", on, e);
            throw new ConfigHandlingException(String.format("Unable to set attributes for %s, "
                            + "Error with attribute %s : %s ",
                    on,
                    configAttributeEntry.getKey(),
                    configAttributeEntry.getValue()),
                    DocumentedException.ErrorType.APPLICATION,
                    DocumentedException.ErrorTag.OPERATION_FAILED,
                    DocumentedException.ErrorSeverity.ERROR);
        }
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:36,代码来源:MergeEditConfigStrategy.java

示例15: sendAttributeChangeNotification

import javax.management.Attribute; //导入方法依赖的package包/类
public void sendAttributeChangeNotification(Attribute inOldVal,
                                            Attribute inNewVal)
    throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }

    // do we really want to do this?
    if ((inOldVal == null) || (inNewVal == null))
        throw new RuntimeOperationsException(new
           IllegalArgumentException("Attribute object must not be null"),
           "Exception occurred trying to send " +
           "attribute change notification of a ModelMBean");


    if (!(inOldVal.getName().equals(inNewVal.getName())))
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Attribute names are not the same"),
            "Exception occurred trying to send " +
            "attribute change notification of a ModelMBean");


    Object newVal = inNewVal.getValue();
    Object oldVal = inOldVal.getValue();
    String className = "unknown";
    if (newVal != null)
        className = newVal.getClass().getName();
    if (oldVal != null)
        className = oldVal.getClass().getName();

    AttributeChangeNotification myNtfyObj = new
        AttributeChangeNotification(this,
                                    1,
                                    ((new Date()).getTime()),
                                    "AttributeChangeDetected",
                                    inOldVal.getName(),
                                    className,
                                    inOldVal.getValue(),
                                    inNewVal.getValue());

    sendAttributeChangeNotification(myNtfyObj);

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:RequiredModelMBean.java


注:本文中的javax.management.Attribute.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。