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


Java MBeanServer.setAttribute方法代码示例

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


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

示例1: processAttribute

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void processAttribute(MBeanServer server,
                              Node descN, String objectName ) {
    String attName=DomUtil.getAttribute(descN, "name");
    String value=DomUtil.getAttribute(descN, "value");
    String type=null; // DomUtil.getAttribute(descN, "type");
    if( value==null ) {
        // The value may be specified as CDATA
        value=DomUtil.getContent(descN);
    }
    try {
        if( log.isDebugEnabled())
            log.debug("Set attribute " + objectName + " " + attName +
                    " " + value);
        ObjectName oname=new ObjectName(objectName);
        // find the type
        type=registry.getType(  oname, attName );

        if( type==null ) {
            log.info("Can't find attribute " + objectName + " " + attName );

        } else {
            Object valueO=registry.convertValue( type, value);
            server.setAttribute(oname, new Attribute(attName, valueO));
        }
    } catch( Exception ex) {
        log.error("Error processing attribute " + objectName + " " +
                attName + " " + value, ex);
    }

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

示例2: processAttribute

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void processAttribute(MBeanServer server,
                              Node descN, String objectName ) {
    String attName=DomUtil.getAttribute(descN, "name");
    String value=DomUtil.getAttribute(descN, "value");
    String type=null; // DomUtil.getAttribute(descN, "type");
    if( value==null ) {
        // The value may be specified as CDATA
        value=DomUtil.getContent(descN);
    }
    try {
        if( log.isDebugEnabled())
            log.debug("Set attribute " + objectName + " " + attName +
                    " " + value);
        ObjectName oname=new ObjectName(objectName);
        // find the type
        if( type==null )
            type=registry.getType(  oname, attName );

        if( type==null ) {
            log.info("Can't find attribute " + objectName + " " + attName );

        } else {
            Object valueO=registry.convertValue( type, value);
            server.setAttribute(oname, new Attribute(attName, valueO));
        }
    } catch( Exception ex) {
        log.error("Error processing attribute " + objectName + " " +
                attName + " " + value, ex);
    }

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

示例3: readBeanInfo

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void readBeanInfo() throws Exception {
    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    MBeanAttributeInfo printCompilation = (MBeanAttributeInfo) findAttributeInfo("PrintCompilation", info);
    assertNotNull("PrintCompilation found", printCompilation);
    assertEquals("true/false", Boolean.class.getName(), printCompilation.getType());

    Attribute printOn = new Attribute(printCompilation.getName(), Boolean.TRUE);

    Object before = server.getAttribute(name, printCompilation.getName());
    server.setAttribute(name, printOn);
    Object after = server.getAttribute(name, printCompilation.getName());

    assertNull("Default value was not set", before);
    assertEquals("Changed to on", Boolean.TRUE, after);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:HotSpotGraalMBeanTest.java

示例4: processAttribute

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void processAttribute(MBeanServer server, Node descN, String objectName) {
	String attName = DomUtil.getAttribute(descN, "name");
	String value = DomUtil.getAttribute(descN, "value");
	String type = null; // DomUtil.getAttribute(descN, "type");
	if (value == null) {
		// The value may be specified as CDATA
		value = DomUtil.getContent(descN);
	}
	try {
		if (log.isDebugEnabled())
			log.debug("Set attribute " + objectName + " " + attName + " " + value);
		ObjectName oname = new ObjectName(objectName);
		// find the type
		type = registry.getType(oname, attName);

		if (type == null) {
			log.info("Can't find attribute " + objectName + " " + attName);

		} else {
			Object valueO = registry.convertValue(type, value);
			server.setAttribute(oname, new Attribute(attName, valueO));
		}
	} catch (Exception ex) {
		log.error("Error processing attribute " + objectName + " " + attName + " " + value, ex);
	}

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

示例5: dumpOperation

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void dumpOperation() throws Exception {
    Field field = null;
    try {
        field = stopMBeanServer();
    } catch (Exception ex) {
        if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
            // skip on JDK9
            return;
        }
    }
    assertNull("The platformMBeanServer isn't initialized now", field.get(null));

    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);

    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);

    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    final MBeanOperationInfo[] arr = info.getOperations();
    assertEquals("Currently three overloads", 3, arr.length);
    MBeanOperationInfo dumpOp = null;
    for (int i = 0; i < arr.length; i++) {
        assertEquals("dumpMethod", arr[i].getName());
        if (arr[i].getSignature().length == 3) {
            dumpOp = arr[i];
        }
    }
    assertNotNull("three args variant found", dumpOp);

    server.invoke(name, "dumpMethod", new Object[]{
                    "java.util.Arrays", "asList", ":3"
    }, null);

    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
    Attribute dumpTo1 = new Attribute(dump.getName(), "");
    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals("", after);

    OptionValues empty = new OptionValues(EconomicMap.create());
    OptionValues unsetDump = realBean.optionsFor(empty, null);
    final MetaAccessProvider metaAccess = jdk.vm.ci.runtime.JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Arrays.class.getMethod("asList", Object[].class));
    final OptionValues forMethod = realBean.optionsFor(unsetDump, method);
    assertNotSame(unsetDump, forMethod);
    Object nothing = unsetDump.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", nothing);

    Object specialValue = forMethod.getMap().get(DebugOptions.Dump);
    assertEquals(":3", specialValue);

    OptionValues normalMethod = realBean.optionsFor(unsetDump, null);
    Object noSpecialValue = normalMethod.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", noSpecialValue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:HotSpotGraalMBeanTest.java

示例6: optionsAreCached

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void optionsAreCached() throws Exception {
    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);

    OptionValues original = new OptionValues(EconomicMap.create());

    assertSame(original, realBean.optionsFor(original, null));

    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);

    Attribute dumpTo1 = new Attribute(dump.getName(), 1);

    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals(1, after);

    final OptionValues modified1 = realBean.optionsFor(original, null);
    assertNotSame(original, modified1);
    final OptionValues modified2 = realBean.optionsFor(original, null);
    assertSame("Options are cached", modified1, modified2);

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


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