當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。