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


Java MBeanInfo.getAttributes方法代码示例

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


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

示例1: fetchKafkaMetrics

import javax.management.MBeanInfo; //导入方法依赖的package包/类
private static void fetchKafkaMetrics(String host, String jmxPort, String metric)
    throws Exception {

  Map<String, String[]> env = new HashMap<>();
  JMXServiceURL address = new JMXServiceURL(
      "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
  JMXConnector connector = JMXConnectorFactory.connect(address, env);
  MBeanServerConnection mbs = connector.getMBeanServerConnection();


  ObjectName name = ObjectName.getInstance(metric);
  MBeanInfo beanInfo = mbs.getMBeanInfo(name);
  for (MBeanAttributeInfo attributeInfo : beanInfo.getAttributes()) {
    Object obj = mbs.getAttribute(name, attributeInfo.getName());
    System.out.println(" attributeName = " + attributeInfo.getName() + " " + obj.toString());
  }
}
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:18,代码来源:MetricsFetcher.java

示例2: getType

import javax.management.MBeanInfo; //导入方法依赖的package包/类
/** Get the type of an attribute of the object, from the metadata.
 *
 * @param oname
 * @param attName
 * @return null if metadata about the attribute is not found
 * @since 1.1
 */
public String getType( ObjectName oname, String attName )
{
    String type=null;
    MBeanInfo info=null;
    try {
        info=server.getMBeanInfo(oname);
    } catch (Exception e) {
        log.info( "Can't find metadata for object" + oname );
        return null;
    }

    MBeanAttributeInfo attInfo[]=info.getAttributes();
    for( int i=0; i<attInfo.length; i++ ) {
        if( attName.equals(attInfo[i].getName())) {
            type=attInfo[i].getType();
            return type;
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:Registry.java

示例3: getMBeanInfo

import javax.management.MBeanInfo; //导入方法依赖的package包/类
/**
 * Return the MBeanInfo for the given resource, based on the given
 * per-interface data.
 */
final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) {
    MBeanInfo mbi =
            getClassMBeanInfo(resource.getClass(), perInterface);
    MBeanNotificationInfo[] notifs = findNotifications(resource);
    if (notifs == null || notifs.length == 0)
        return mbi;
    else {
        return new MBeanInfo(mbi.getClassName(),
                mbi.getDescription(),
                mbi.getAttributes(),
                mbi.getConstructors(),
                mbi.getOperations(),
                notifs,
                mbi.getDescriptor());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:MBeanIntrospector.java

示例4: printMBeanInfo

import javax.management.MBeanInfo; //导入方法依赖的package包/类
private void printMBeanInfo(MBeanInfo mbInfo) {
    System.out.println("Description " + mbInfo.getDescription());

    for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) {
        System.out.println("Constructor " + ctor.getName());
    }

    for (MBeanAttributeInfo att : mbInfo.getAttributes()) {
        System.out.println("Attribute " + att.getName()
        + " [" + att.getType() + "]");
    }

    for (MBeanOperationInfo oper : mbInfo.getOperations()) {
        System.out.println("Operation " + oper.getName());
    }

    for (MBeanNotificationInfo notif : mbInfo.getNotifications()) {
        System.out.println("Notification " + notif.getName());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:MXBeanInteropTest2.java

示例5: check

import javax.management.MBeanInfo; //导入方法依赖的package包/类
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);

    // check the MBean itself
    check(mbi);

    // check attributes
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    for (MBeanAttributeInfo attr : attrs) {
        check(attr);
        if (attr.getName().equals("ReadOnly"))
            check("@Full", attr.getDescriptor(), expectedFullDescriptor);
    }

    // check operations
    MBeanOperationInfo[] ops = mbi.getOperations();
    for (MBeanOperationInfo op : ops) {
        check(op);
        check(op.getSignature());
    }

    MBeanConstructorInfo[] constrs = mbi.getConstructors();
    for (MBeanConstructorInfo constr : constrs) {
        check(constr);
        check(constr.getSignature());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:AnnotationTest.java

示例6: run

import javax.management.MBeanInfo; //导入方法依赖的package包/类
@Override
public void run() {
  try {
    // This will trigger updateJmxCache().
    MBeanInfo info = sa.getMBeanInfo();
    final String key = src.getKey();
    for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
      // Found the new key, update the metric source and move on.
      if (mBeanAttributeInfo.getName().equals(key)) {
        LOG.info("found key/val=" + cnt + "/" + cnt);
        cnt++;
        src.setKV("key" + cnt, cnt);
        return;
      }
    }
    LOG.error("key=" + key + " not found. Stopping now.");
    hasError.set(true);
  } catch (Exception e) {
    // catch other errors
    hasError.set(true);
    LOG.error(e.getStackTrace());
  } finally {
    if (hasError.get()) {
      future.cancel(false);
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:TestMetricsSourceAdapter.java

示例7: getMBeanAttributeType

import javax.management.MBeanInfo; //导入方法依赖的package包/类
/**
 * Get MBean Attriute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    if (attrs != null) {
        for (int i = 0; mattrType == null && i < attrs.length; i++) {
            if (attribute.equals(attrs[i].getName()))
                mattrType = attrs[i].getType();
        }
    }
    return mattrType;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:JMXAccessorSetTask.java

示例8: printAttrs

import javax.management.MBeanInfo; //导入方法依赖的package包/类
private static void printAttrs(
        MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
    Set<ObjectName> names = mbsc1.queryNames(null, null);
    for (ObjectName name : names) {
        System.out.println(name + ":");
        MBeanInfo mbi = mbsc1.getMBeanInfo(name);
        MBeanAttributeInfo[] mbais = mbi.getAttributes();
        for (MBeanAttributeInfo mbai : mbais) {
            String attr = mbai.getName();
            Object value;
            try {
                value = mbsc1.getAttribute(name, attr);
            } catch (Exception e) {
                if (expectX != null && expectX.isInstance(e))
                    value = "<" + e + ">";
                else
                    throw e;
            }
            String s = "  " + attr + " = " + value;
            if (s.length() > 80)
                s = s.substring(0, 77) + "...";
            System.out.println(s);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:OldMBeanServerTest.java

示例9: getMBeanInfo

import javax.management.MBeanInfo; //导入方法依赖的package包/类
@Override
public MBeanInfo getMBeanInfo() {
    MBeanInfo mbi = super.getMBeanInfo();
    Class<?> resourceClass = getResource().getClass();
    if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass))
        return mbi;
    return new MBeanInfo(mbi.getClassName(), mbi.getDescription(),
            mbi.getAttributes(), mbi.getConstructors(),
            mbi.getOperations(),
            MBeanIntrospector.findNotifications(getResource()),
            mbi.getDescriptor());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:StandardMBeanSupport.java

示例10: getOperationContext

import javax.management.MBeanInfo; //导入方法依赖的package包/类
private ResourcePermission getOperationContext(ObjectName objectName, String featureName,
    boolean isOp) throws InstanceNotFoundException, ReflectionException {
  MBeanInfo beanInfo = null;
  try {
    beanInfo = mbs.getMBeanInfo(objectName);
  } catch (IntrospectionException e) {
    throw new GemFireSecurityException("error getting beanInfo of " + objectName, e);
  }
  // If there is no annotation defined either in the class level or method level, we should
  // consider this operation/attribute freely accessible
  ResourcePermission result = null;

  // find the context in the beanInfo if defined in the class level
  result = getOperationContext(beanInfo.getDescriptor(), result);

  MBeanFeatureInfo[] featureInfos = null;
  if (isOp) {
    featureInfos = beanInfo.getOperations();
  } else {
    featureInfos = beanInfo.getAttributes();
  }
  // still look into the attributes/operations to see if it's defined in the method level
  for (MBeanFeatureInfo info : featureInfos) {
    if (info.getName().equals(featureName)) {
      // found the featureInfo of this method on the bean
      result = getOperationContext(info.getDescriptor(), result);
      break;
    }
  }
  return result;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:32,代码来源:MBeanServerWrapper.java

示例11: getMBeanAttributeType

import javax.management.MBeanInfo; //导入方法依赖的package包/类
/**
 * Get MBean Attribute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    for (int i = 0; mattrType == null && i < attrs.length; i++) {
        if (attribute.equals(attrs[i].getName()))
            mattrType = attrs[i].getType();
    }
    return mattrType;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:23,代码来源:JMXAccessorSetTask.java

示例12: testMXBean

import javax.management.MBeanInfo; //导入方法依赖的package包/类
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:MXBeanTest.java

示例13: getMBeanAttributeType

import javax.management.MBeanInfo; //导入方法依赖的package包/类
/**
 * Get MBean Attribute from Mbean Server
 * 
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute)
		throws Exception {
	ObjectName oname = new ObjectName(name);
	String mattrType = null;
	MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
	MBeanAttributeInfo attrs[] = minfo.getAttributes();
	for (int i = 0; mattrType == null && i < attrs.length; i++) {
		if (attribute.equals(attrs[i].getName()))
			mattrType = attrs[i].getType();
	}
	return mattrType;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:JMXAccessorSetTask.java

示例14: getAttribute

import javax.management.MBeanInfo; //导入方法依赖的package包/类
Object getAttribute(MBeanServerConnection mbsc,
                    ObjectName object,
                    String attribute)
    throws AttributeNotFoundException,
           InstanceNotFoundException,
           MBeanException,
           ReflectionException,
           IOException {
    // Check for "ObservedAttribute" replacement.
    // This could happen if a thread A called setObservedAttribute()
    // while other thread B was in the middle of the monitor() method
    // and received the old observed attribute value.
    //
    final boolean lookupMBeanInfo;
    synchronized (this) {
        if (!isActive())
            throw new IllegalArgumentException(
                "The monitor has been stopped");
        if (!attribute.equals(getObservedAttribute()))
            throw new IllegalArgumentException(
                "The observed attribute has been changed");
        lookupMBeanInfo =
            (firstAttribute == null && attribute.indexOf('.') != -1);
    }

    // Look up MBeanInfo if needed
    //
    final MBeanInfo mbi;
    if (lookupMBeanInfo) {
        try {
            mbi = mbsc.getMBeanInfo(object);
        } catch (IntrospectionException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        mbi = null;
    }

    // Check for complex type attribute
    //
    final String fa;
    synchronized (this) {
        if (!isActive())
            throw new IllegalArgumentException(
                "The monitor has been stopped");
        if (!attribute.equals(getObservedAttribute()))
            throw new IllegalArgumentException(
                "The observed attribute has been changed");
        if (firstAttribute == null) {
            if (attribute.indexOf('.') != -1) {
                MBeanAttributeInfo mbaiArray[] = mbi.getAttributes();
                for (MBeanAttributeInfo mbai : mbaiArray) {
                    if (attribute.equals(mbai.getName())) {
                        firstAttribute = attribute;
                        break;
                    }
                }
                if (firstAttribute == null) {
                    String tokens[] = attribute.split("\\.", -1);
                    firstAttribute = tokens[0];
                    for (int i = 1; i < tokens.length; i++)
                        remainingAttributes.add(tokens[i]);
                    isComplexTypeAttribute = true;
                }
            } else {
                firstAttribute = attribute;
            }
        }
        fa = firstAttribute;
    }
    return mbsc.getAttribute(object, fa);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:73,代码来源:Monitor.java

示例15: main

import javax.management.MBeanInfo; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException,
        MalformedObjectNameException, InstanceNotFoundException,
        AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException, IntrospectionException {
    String domainName = "MyMBean";
    int rmiPort = 1099;
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/"+domainName);
    // 可以类比HelloAgent.java中的那句:
    // JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    JMXConnector jmxc = JMXConnectorFactory.connect(url);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    //print domains
    System.out.println("Domains:------------------");
    String domains[] = mbsc.getDomains();
    for(int i=0;i<domains.length;i++){
        System.out.println("\tDomain["+i+"] = "+domains[i]);
    }
    //MBean count
    System.out.println("MBean count = "+mbsc.getMBeanCount());
    //process attribute
    ObjectName mBeanName = new ObjectName(domainName+":name=HelloWorld");
    mbsc.setAttribute(mBeanName, new Attribute("Name","zzh"));//注意这里是Name而不是name
    System.out.println("Name = "+mbsc.getAttribute(mBeanName, "Name"));

    //接下去是执行Hello中的printHello方法,分别通过代理和rmi的方式执行
    //via proxy
    HelloMBean proxy = MBeanServerInvocationHandler.newProxyInstance(mbsc, mBeanName, HelloMBean.class, false);
    proxy.printHello();
    proxy.printHello("jizhi boy");
    //via rmi
    mbsc.invoke(mBeanName, "printHello", null, null);
    mbsc.invoke(mBeanName, "printHello", new String[]{"jizhi gril"}, new String[]{String.class.getName()});

    //get mbean information
    MBeanInfo info = mbsc.getMBeanInfo(mBeanName);
    System.out.println("Hello Class: "+info.getClassName());
    for(int i=0;i<info.getAttributes().length;i++){
        System.out.println("Hello Attribute:"+info.getAttributes()[i].getName());
    }
    for(int i=0;i<info.getOperations().length;i++){
        System.out.println("Hello Operation:"+info.getOperations()[i].getName());
    }

    //ObjectName of MBean
    System.out.println("all ObjectName:--------------");
    Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
    for(Iterator<ObjectInstance> it = set.iterator();it.hasNext();){
        ObjectInstance oi = it.next();
        System.out.println("\t"+oi.getObjectName());
    }
    jmxc.close();
}
 
开发者ID:breakEval13,项目名称:rocketmq-flink-plugin,代码行数:54,代码来源:Client.java


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