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


Java MBeanServerConnection.setAttribute方法代码示例

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


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

示例1: jmxSet

import javax.management.MBeanServerConnection; //导入方法依赖的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

示例2: invoke

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
@Override
Object invoke(MBeanServerConnection mbsc, ObjectName name, Object[] args)
        throws Exception {
    assert(args.length == 1);
    Attribute attr = new Attribute(getName(), args[0]);
    mbsc.setAttribute(name, attr);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:MXBeanProxy.java

示例3: doSetRequest

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
protected int doSetRequest(MBeanServerConnection mbsc,
                           ObjectName on,
                           boolean expectedException) {
    int errorCount = 0;

    try {
        Utils.debug(Utils.DEBUG_STANDARD,
            "ClientSide::doSetRequest: Set attributes of the MBean") ;

        Attribute attribute = new Attribute("Attribute", "My value") ;
        mbsc.setAttribute(on, attribute) ;

        if (expectedException) {
            System.out.println("ClientSide::doSetRequest: " +
                "(ERROR) Set did not fail with expected SecurityException");
            errorCount++;
        } else {
            System.out.println("ClientSide::doSetRequest: (OK) Set succeed") ;
        }
    } catch(Exception e) {
        Utils.printThrowable(e, true) ;
        if (expectedException) {
            if (e instanceof java.lang.SecurityException) {
                System.out.println("ClientSide::doSetRequest: " +
                    "(OK) Set failed with expected SecurityException") ;
            } else {
                System.out.println("ClientSide::doSetRequest: " +
                    "(ERROR) Set failed with " +
                    e.getClass() + " instead of expected SecurityException");
                errorCount++;
            }
        } else {
            System.out.println("ClientSide::doSetRequest: (ERROR) Set failed");
            errorCount++;
        }
    }
    return errorCount;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:AuthorizationTest.java

示例4: testWithException

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void testWithException(boolean send)
throws Exception {
    ClassLoader zoobyCL = new ZoobyClassLoader();
    Class<?> zoobyClass = Class.forName("Zooby", false, zoobyCL);
    Object zooby = zoobyClass.newInstance();

    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, null, pmbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();

    Object rzooby;
    if (send) {
        System.out.println("Sending object...");
        mbsc.setAttribute(getSetName, new Attribute("It", zooby));
        rzooby = getSetInstance.getIt();
    } else {
        System.out.println("Receiving object...");
        getSetInstance.setIt(zooby);
        rzooby = mbsc.getAttribute(getSetName, "It");
    }

    if (!rzooby.getClass().getName().equals("Zooby")) {
        throw new Exception("FAILED: remote object is not a Zooby");
    }
    if (rzooby.getClass().getClassLoader() ==
            zooby.getClass().getClassLoader()) {
        throw new Exception("FAILED: same class loader: " +
                zooby.getClass().getClassLoader());
    }

    cc.close();
    cs.stop();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:RMIDownloadTest.java

示例5: jmxSet

import javax.management.MBeanServerConnection; //导入方法依赖的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:how2j,项目名称:lazycat,代码行数:20,代码来源:JMXAccessorSetTask.java

示例6: doBasicMXBeanTest

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private final int doBasicMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- doBasicMXBeanTest") ;

    try {
        ObjectName objName =
                new ObjectName("sqe:type=BasicMXBean") ;
        mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
        MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
        printMBeanInfo(mbInfo);
        System.out.println("---- OK\n") ;
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        System.out.println("---- OK\n") ;

        System.out.println("Check mxbean field in the MBeanInfo");
        String mxbeanField =
                (String)mbInfo.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);

        if ( mxbeanField == null || ! mxbeanField.equals("true")) {
            System.out.println("---- ERROR : Improper mxbean field value "
                    + mxbeanField);
            errorCount++;
        }
        System.out.println("---- OK\n") ;

        System.out.println("Set attribute ObjectNameAtt");
        Attribute att = new Attribute("ObjectNameAtt", objName);
        mbsc.setAttribute(objName, att);
        ObjectName value =
                (ObjectName)mbsc.getAttribute(objName, "ObjectNameAtt");

        if ( ! value.equals(objName) ) {
            errorCount++;
            System.out.println("---- ERROR : setAttribute failed, got "
                    + value
                    + " while expecting "
                    + objName);
        }
        System.out.println("---- OK\n") ;

        System.out.println("Call operation doNothing");
        mbsc.invoke(objName,  "doNothing", null, null);
        System.out.println("---- OK\n") ;

        System.out.println("Call operation getWeather");
        Object weather = mbsc.invoke(objName,
                "getWeather",
                new Object[]{Boolean.TRUE},
                new String[]{"boolean"});
        System.out.println("Weather is " + weather);
        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:61,代码来源:MXBeanInteropTest2.java

示例7: main

import javax.management.MBeanServerConnection; //导入方法依赖的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.MBeanServerConnection.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。