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


Java Attribute类代码示例

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


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

示例1: getProcessCpuLoad

import javax.management.Attribute; //导入依赖的package包/类
public static double getProcessCpuLoad() throws Exception {

		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
		AttributeList list = mbs.getAttributes(name, new String[] { "SystemCpuLoad" });

		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 value;
	}
 
开发者ID:enoy19,项目名称:keyboard-light-composer,代码行数:19,代码来源:CpuUsage.java

示例2: getAttributes

import javax.management.Attribute; //导入依赖的package包/类
@Override
public AttributeList getAttributes(String[] attributeNames) {
  if (attributeNames == null || attributeNames.length == 0) 
    throw new IllegalArgumentException();
  
  updateMbeanInfoIfMetricsListChanged();
  
  AttributeList result = new AttributeList(attributeNames.length);
  for (String iAttributeName : attributeNames) {
    try {
      Object value = getAttribute(iAttributeName);
      result.add(new Attribute(iAttributeName, value));
    } catch (Exception e) {
      continue;
    } 
  }
  return result;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:MetricsDynamicMBeanBase.java

示例3: setAttribute

import javax.management.Attribute; //导入依赖的package包/类
@Override
public synchronized void setAttribute(final Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Attribute newAttribute = attribute;
    if (configBeanModificationDisabled.get()) {
        throw new IllegalStateException("Operation is not allowed now");
    }

    if ("Attribute".equals(newAttribute.getName())) {
        setAttribute((Attribute) newAttribute.getValue());
        return;
    }

    try {
        if (newAttribute.getValue() instanceof ObjectName) {
            newAttribute = fixDependencyAttribute(newAttribute);
        } else if (newAttribute.getValue() instanceof ObjectName[]) {
            newAttribute = fixDependencyListAttribute(newAttribute);
        }

        internalServer.setAttribute(objectNameInternal, newAttribute);
    } catch (final InstanceNotFoundException e) {
        throw new MBeanException(e);
    }

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:27,代码来源:DynamicWritableWrapper.java

示例4: jmxSet

import javax.management.Attribute; //导入依赖的package包/类
/**
 * @param jmxServerConnection
 * @param name
 * @throws Exception
 */
protected String jmxSet(MBeanServerConnection jmxServerConnection,
        String name) throws Exception {
    Object realValue;
    if (type != null) {
        realValue = convertStringToType(value, type);
    } else {
        if (isConvert()) {
            String mType = getMBeanAttributeType(jmxServerConnection, name,
                    attribute);
            realValue = convertStringToType(value, mType);
        } else
            realValue = value;
    }
    jmxServerConnection.setAttribute(new ObjectName(name), new Attribute(
            attribute, realValue));
    return null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:JMXAccessorSetTask.java

示例5: getAttributes

import javax.management.Attribute; //导入依赖的package包/类
/**
 * Obtain and return the values of several attributes of this MBean.
 *
 * @param names Names of the requested attributes
 */
@Override
public AttributeList getAttributes(String names[]) {

    // Validate the input parameters
    if (names == null)
        throw new RuntimeOperationsException
            (new IllegalArgumentException("Attribute names list is null"),
             "Attribute names list is null");

    // Prepare our response, eating all exceptions
    AttributeList response = new AttributeList();
    for (int i = 0; i < names.length; i++) {
        try {
            response.add(new Attribute(names[i],getAttribute(names[i])));
        } catch (Exception e) {
            // Not having a particular attribute in the response
            // is the indication of a getter problem
        }
    }
    return (response);

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

示例6: setAttributes

import javax.management.Attribute; //导入依赖的package包/类
/**
 * 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));

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

示例7: 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

示例8: 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

示例9: getAttributes

import javax.management.Attribute; //导入依赖的package包/类
/**
 * Obtain and return the values of several attributes of this MBean.
 *
 * @param names Names of the requested attributes
 */
public AttributeList getAttributes(String names[]) {

    // Validate the input parameters
    if (names == null)
        throw new RuntimeOperationsException
            (new IllegalArgumentException("Attribute names list is null"),
             "Attribute names list is null");

    // Prepare our response, eating all exceptions
    AttributeList response = new AttributeList();
    for (int i = 0; i < names.length; i++) {
        try {
            response.add(new Attribute(names[i],getAttribute(names[i])));
        } catch (Exception e) {
            ; // Not having a particular attribute in the response
            ; // is the indication of a getter problem
        }
    }
    return (response);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:BaseModelMBean.java

示例10: getFileDecriptorInfo

import javax.management.Attribute; //导入依赖的package包/类
@Override
public long[] getFileDecriptorInfo() {
    MBeanServer mbsc = MBeans.getMBeanServer();
    AttributeList attributes;
    try {
        attributes = mbsc.getAttributes(
            new ObjectName("java.lang:type=OperatingSystem"), 
            new String[]{"OpenFileDescriptorCount", "MaxFileDescriptorCount"});
        List<Attribute> attrList = attributes.asList();
        long openFdCount = (Long)attrList.get(0).getValue();
        long maxFdCount = (Long)attrList.get(1).getValue();
        long[] fdCounts = { openFdCount, maxFdCount};
        return fdCounts;
    } catch (Exception e) {
        LogFactory.getLog(SdkMBeanRegistrySupport.class).debug(
                "Failed to retrieve file descriptor info", e);
    }
    return null;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:20,代码来源:JmxInfoProviderSupport.java

示例11: doTest

import javax.management.Attribute; //导入依赖的package包/类
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:RMIConnectorLogAttributesTest.java

示例12: testReadAttributes

import javax.management.Attribute; //导入依赖的package包/类
@Test
public void testReadAttributes() throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);

    assertEquals(threadCount, proxy.getAttribute(THREAD_COUNT));

    assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(),
            proxy.getAttribute(TRIGGER_NEW_INSTANCE_CREATION));

    AttributeList attributes = proxy.getAttributes(new String[] { THREAD_COUNT, TRIGGER_NEW_INSTANCE_CREATION });
    assertEquals(2, attributes.size());
    Attribute threadCountAttr = (Attribute) attributes.get(0);
    assertEquals(THREAD_COUNT, threadCountAttr.getName());
    assertEquals(threadCount, threadCountAttr.getValue());
    Attribute boolTestAttr = (Attribute) attributes.get(1);
    assertEquals(TRIGGER_NEW_INSTANCE_CREATION, boolTestAttr.getName());
    assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), boolTestAttr.getValue());

    MBeanInfo beanInfo = proxy.getMBeanInfo();
    assertEquals(2, beanInfo.getAttributes().length);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:AbstractDynamicWrapperTest.java

示例13: setAttribute

import javax.management.Attribute; //导入依赖的package包/类
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute="
            + attribute);

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:RMIConnector.java

示例14: 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

示例15: setAttributes

import javax.management.Attribute; //导入依赖的package包/类
public AttributeList setAttributes(AttributeList attributes) {
  if (attributes == null)
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_ATTRIBUTE_LIST_CANNOT_BE_NULL.toLocalizedString()));

  Logger logger = getLogger();

  AttributeList list = new AttributeList();
  for (Iterator i = attributes.iterator(); i.hasNext();) {
    Attribute attribute = (Attribute) i.next();
    String name = attribute.getName();
    try {
      setAttribute(attribute);
      list.add(attribute);
    } catch (Exception x) {
      if (logger.isEnabledFor(Logger.TRACE))
        logger.trace("setAttribute for attribute " + name + " failed", x);
      // And go on with the next one
    }
  }
  return list;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:MX4JModelMBean.java


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