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


Java ModelMBeanInfoSupport类代码示例

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


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

示例1: getMBeanInfo

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
@Override
public MBeanInfo getMBeanInfo() {
    try {
        ModelMBeanAttributeInfo[] attributes = new ModelMBeanAttributeInfo[0];
        ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[] {
                new ModelMBeanConstructorInfo("-", this.getClass().getConstructor())
        };
        ModelMBeanOperationInfo[] operations = new ModelMBeanOperationInfo[] {
                new ModelMBeanOperationInfo("info", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.INFO),
                new ModelMBeanOperationInfo("action", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION),
                new ModelMBeanOperationInfo("actionInfo", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION_INFO),
                new ModelMBeanOperationInfo("unknown", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.UNKNOWN)
        };
        ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0];
        return new ModelMBeanInfoSupport(this.getClass().getName(), "-", attributes, constructors, operations, notifications);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:20,代码来源:TestModelMBean.java

示例2: testNotPresent

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify that returned value of invoked method never retrieves value from
 * cache if currencyTimeLimit is not defended in descriptor of
 * ModelMBeanOperationInfo.
 * <p>
 * Instructions are the same as in testNegative.
 */
public Result testNotPresent() throws Exception {
    Method method = class1.getDeclaredMethod("simpleMethod", null);
    ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
        "description", method);
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", null, null,
        new ModelMBeanOperationInfo[] { operationInfo1 }, null);
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    requiredModelMBean.setManagedResource(this, "ObjectReference");
    ObjectName objectName = new ObjectName("domain", "name", "simple name");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    Object value = server.invoke(objectName, method.getName(), null, null);
    assertEquals(value, returnedObject);
    assertTrue(isInvokedMethod());
    ModelMBeanOperationInfo operationInfo2 = (ModelMBeanOperationInfo)server
        .getMBeanInfo(objectName).getOperations()[0];
    assertTrue(operationInfo1 == operationInfo2);
    value = server.invoke(objectName, method.getName(), null, null);
    assertEquals(value, returnedObject);
    assertTrue(isInvokedMethod());
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:32,代码来源:InvocationTest.java

示例3: testRegisterExistingMBeanWithUserSuppliedObjectName

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
@Test
public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");
	ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null);
	RequiredModelMBean bean = new RequiredModelMBean(info);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName);
	assertEquals(info, infoFromServer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:MBeanExporterOperationsTests.java

示例4: test01

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
public Result test01() throws Exception {
    ModelMBeanInfoSupport beanInfoSupport = constractModelMBeanInfoSupport();
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    requiredModelMBean.setManagedResource(new UserDefinedDescriptorTest(),
        "ObjectReference");
    ObjectName objectName = new ObjectName("modelmbean:type=Operation");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    verifyModelMBeanInfo((ModelMBeanInfoSupport)server
        .getMBeanInfo(objectName));
    return passed();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:14,代码来源:UserDefinedDescriptorTest.java

示例5: verifyModelMBeanInfo

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Do 11-15 steps.
 */
private void verifyModelMBeanInfo(ModelMBeanInfoSupport modelMBeanInfo)
    throws Exception {
    Descriptor descriptor = modelMBeanInfo.getMBeanDescriptor();
    Descriptor descriptor2 = (Descriptor)map.get(modelMBeanInfo.getClass()
        .getName());
    assertTrue(DefaultDescriptorTest.compareDescriptors(descriptor,
        descriptor2));
    verifyDescriptor(modelMBeanInfo.getAttribute("name"));
    verifyDescriptor(modelMBeanInfo.getAttributes());
    verifyDescriptor(modelMBeanInfo.getConstructors());
    verifyDescriptor(modelMBeanInfo.getNotification("name"));
    verifyDescriptor(modelMBeanInfo.getNotifications());
    verifyDescriptor(modelMBeanInfo.getOperations());
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:18,代码来源:UserDefinedDescriptorTest.java

示例6: constractModelMBeanInfoSupport

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Do 1-6 steps.
 */
private ModelMBeanInfoSupport constractModelMBeanInfoSupport()
    throws Exception {
    ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo(
        "description", class1.getMethod("simpleOperartion", null));
    setDescriptor(operationInfo);
    ModelMBeanConstructorInfo constructorInfo = new ModelMBeanConstructorInfo(
        "description", class1.getConstructor(null));
    setDescriptor(constructorInfo);
    ModelMBeanAttributeInfo attributeInfo = new ModelMBeanAttributeInfo(
        "name", "description", class1.getMethod("getH", null), class1
            .getMethod("setH", new Class[] { int.class }));
    setDescriptor(attributeInfo);
    ModelMBeanNotificationInfo notificationInfo = new ModelMBeanNotificationInfo(
        new String[] { "specific notification tepes" }, "name",
        "description");
    setDescriptor(notificationInfo);
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description",
        new ModelMBeanAttributeInfo[] { attributeInfo },
        new ModelMBeanConstructorInfo[] { constructorInfo },
        new ModelMBeanOperationInfo[] { operationInfo },
        new ModelMBeanNotificationInfo[] { notificationInfo });
    Descriptor descriptor = beanInfoSupport.getMBeanDescriptor();
    String[] strings = getSpesific(beanInfoSupport.getClass());
    descriptor.setField(strings[0], strings[1]);
    map.put(beanInfoSupport.getClass().getName(), descriptor);
    beanInfoSupport.setMBeanDescriptor(descriptor);
    return beanInfoSupport;
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:33,代码来源:UserDefinedDescriptorTest.java

示例7: testLogging

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * <ul>
 * Verify that logs of new notifications, when sendNotification is invoked,
 * write to file. File name is value of descriptor of
 * ModelMBeanNotificationInfo.
 * <li>Create java class, which is not MBean. MBean has 1 getter and 1
 * setter methods.
 * <li>Create ModelMBeanNotificationInfo object for my type with descriptor
 * with logging.
 * <li>Create ModelMBeanInfoSupport object. All ModelMBeanXXXInfo except
 * ModelMBeanNotificationInfo are default.
 * <li>Create RequiredModelMBean object.
 * <li>Instance of java class in 1st step sets managed resource for
 * RequiredModelMBean using setManagedResource method.
 * <li>Send my notification using sendNotification method.
 * <li>Verify that logfile was created and size of file > 0.
 * </ul>
 */
public Result testLogging() throws Exception {
    ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
        "g", "descr", class1.getMethod("getG", null), class1.getMethod(
            "setG", new Class[] { String.class }));
    ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
    ModelMBeanNotificationInfo notificationInfo = new ModelMBeanNotificationInfo(
        new String[] { SimpleNotification.notificationType },
        SimpleNotification.notificationType, "description");
    File file = File.createTempFile("log", ".txt");
    file.deleteOnExit();
    Descriptor descriptor = notificationInfo.getDescriptor();
    descriptor.setField("log", "true");
    descriptor.setField("logfile", file.getAbsolutePath());
    log.info("file name: " + file.getAbsolutePath());
    notificationInfo.setDescriptor(descriptor);
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", attributeInfos, null, null,
        new ModelMBeanNotificationInfo[] { notificationInfo });
    beanInfoSupport.getNotification(new SimpleNotification("src", 1)
        .getType());
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    beanInfoSupport.getDescriptor(new SimpleNotification("src", 1)
        .getType(), "notification");
    requiredModelMBean.sendNotification(new SimpleNotification("src", 1));
    assertTrue(file.length() > 0);
    file.delete();
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:48,代码来源:NotificationLoggingTest.java

示例8: testException

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify that invoke method throws exception if target operation method
 * throws exception.
 * <ul>
 * Step by step:
 * <li>Create operation method with one string parameter which always
 * throws an exception with message=parameter of this method.
 * <li>Create ModelMBeanOperationInfo object for operation method.
 * <li>Set value currencyTimeLimit = 0 in descriptor for
 * ModelMBeanOperationInfo object.
 * <li>Create ModelMBeanInfoSupport object with default descriptor. All
 * ModelMBeanXXXInfo except ModelMBeanOperationInfo are default.
 * <li>Instance of class created in 1st step sets managed resource for
 * RequiredModelMBean using setManagedResource method.
 * <li>Create ObjectName object.
 * <li>Register RequiredModelMBean object in MBeanServer with above
 * ObjectName.
 * <li>Invoke operation methodThrowException method thru invoke method of
 * MBeanServer with specific msg.
 * <li>Verify that MBeanException was thrown with nested exception which
 * has message which specified in previous step.
 * </ul>
 */
public Result testException() throws Exception {
    Method method = class1.getMethod("methodThrowException",
        new Class[] { String.class });
    ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
        "description", method);
    Descriptor descriptor = operationInfo1.getDescriptor();
    descriptor.setField("currencyTimeLimit", "0");
    operationInfo1.setDescriptor(descriptor);
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", null, null,
        new ModelMBeanOperationInfo[] { operationInfo1 }, null);
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    requiredModelMBean.setManagedResource(this, "ObjectReference");
    ObjectName objectName = new ObjectName("domain", "name", "simple name");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    try {
        server.invoke(objectName, method.getName(),
            new Object[] { "message" }, new String[] { String.class
                .getName() });
        assertTrue(false);
    } catch (MBeanException e) {
        assertEquals(e.getCause().getMessage(), "message");
    }
    assertTrue(isInvokedMethod());
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:52,代码来源:InvocationTest.java

示例9: testNegative

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify that invoke method never caches returned value of method if
 * currencyTimeLimit < 0.
 * <ul>
 * Step by step:
 * <li>Create operation method without parameters which always returns the
 * same value.
 * <li>Create ModelMBeanOperationInfo object for operation method.
 * <li>Set value currencyTimeLimit <0 in descriptor for
 * ModelMBeanOperationInfo object.
 * <li>Create ModelMBeanInfoSupport object with default descriptor. All
 * ModelMBeanXXXInfo except ModelMBeanOperationInfo are default.
 * <li>Create RequiredModelMBean object.
 * <li>Instance of class created in 1st step sets managed resource for
 * RequiredModelMBean using setManagedResource method.
 * <li>Create ObjectName object.
 * <li>Register RequiredModelMBean object in MBeanServer with above
 * ObjectName.
 * <li>Invoke operation method thru invoke method of MBeanServer.
 * <li>Verify value which the invoke method returned is the same as value
 * which the operation method returned.
 * <li>Verify that operation method was invoked.
 * <li>Invoke again operation method thru invoke method of MBeanServer.
 * <li>Verify value which the invoke method returned is the same as value
 * which the operation method returned.
 * <li>Verify that operation method was invoked.
 * </ul>
 */
public Result testNegative() throws Exception {
    Method method = class1.getDeclaredMethod("simpleMethod", null);
    ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
        "description", method);
    Descriptor descriptor = operationInfo1.getDescriptor();
    descriptor.setField("currencyTimeLimit", "-1");
    operationInfo1.setDescriptor(descriptor);
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", null, null,
        new ModelMBeanOperationInfo[] { operationInfo1 }, null);
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    requiredModelMBean.setManagedResource(this, "ObjectReference");
    ObjectName objectName = new ObjectName("domain", "name", "simple name");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    Object value = server.invoke(objectName, method.getName(), null, null);
    assertEquals(value, returnedObject);
    assertTrue(isInvokedMethod());
    ModelMBeanOperationInfo operationInfo2 = (ModelMBeanOperationInfo)server
        .getMBeanInfo(objectName).getOperations()[0];
    assertTrue(operationInfo1 == operationInfo2);

    value = server.invoke(objectName, method.getName(), null, null);
    assertEquals(value, returnedObject);
    assertTrue(isInvokedMethod());
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:57,代码来源:InvocationTest.java

示例10: getMBeanInfo

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {

        if ((defaultManagedBean == null && customManagedBean == null) || objectName == null)
            return null;
        // skip proxy classes
        if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
            LOGGER.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
            return null;
        }

        // maps and lists to contain information about attributes and operations
        Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<>();
        Set<ManagedOperationInfo> operations = new LinkedHashSet<>();
        Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<>();
        Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<>();
        Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<>();

        // extract details from default managed bean
        if (defaultManagedBean != null) {
            extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
            extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
            extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
            extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
        }

        // extract details from custom managed bean
        if (customManagedBean != null) {
            extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
            extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
            extractMbeanOperations(customManagedBean, operations, mBeanOperations);
            extractMbeanNotifications(customManagedBean, mBeanNotifications);
        }

        // create the ModelMBeanInfo
        String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
        String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
        ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
        ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
        ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);

        ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
        LOGGER.trace("Created ModelMBeanInfo {}", info);
        return info;
    }
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:45,代码来源:MBeanInfoAssembler.java

示例11: getMBeanInfo

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Gets the {@link ModelMBeanInfo} for the given managed bean
 *
 * @param defaultManagedBean  the default managed bean
 * @param customManagedBean   an optional custom managed bean
 * @param objectName   the object name
 * @return the model info, or <tt>null</tt> if not possible to create, for example due the managed bean is a proxy class
 * @throws JMException is thrown if error creating the model info
 */
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
    // skip proxy classes
    if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
        LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
        return null;
    }

    // maps and lists to contain information about attributes and operations
    Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
    Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
    Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
    Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
    Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();

    // extract details from default managed bean
    if (defaultManagedBean != null) {
        extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
    }

    // extract details from custom managed bean
    if (customManagedBean != null) {
        extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(customManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(customManagedBean, mBeanNotifications);
    }

    // create the ModelMBeanInfo
    String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
    ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
    ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);

    ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
    LOG.trace("Created ModelMBeanInfo {}", info);
    return info;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:51,代码来源:MBeanInfoAssembler.java

示例12: testModelMBeanInfoSupport

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify default fields of descriptor from ModelMBeanInfoSupport:
 * name=nameofClassUsedInConstructor, descriptorType=mbean,
 * displayName=nameofClassUsedInConstructor, persistPolicy=never, log=F,
 * visibility=1.
 * <ul>
 * Step by step:
 * <li>Create ModelMBeanInfoSupport object using ModelMBeanInfoSupport.
 * <li>Extract a descriptor from created object using getMBeanDescriptor()
 * method.
 * <li>Verify that all default fields of the descriptor exist using
 * getFieldValue(String inFieldName) method.
 * <li>There are no other fields.
 * <li>Convert the descriptor to xml.
 * <li>Create new descriptor from xml using DescriptorSupport(String inStr)
 * constructor.
 * </ul>
 */
public Result testModelMBeanInfoSupport() throws Exception {
    ModelMBeanInfoSupport modelMBeanInfoSupport = new ModelMBeanInfoSupport(
        sampleClass.getName(), "description", null, null, null, null);
    descriptor = modelMBeanInfoSupport.getMBeanDescriptor();
    assertEquals(descriptor.getFieldValue("name"), sampleClass.getName());
    assertEquals(descriptor.getFieldValue("descriptorType"), "mbean");
    assertEquals(descriptor.getFieldValue("displayName"), sampleClass
        .getName());
    assertEquals(descriptor.getFieldValue("persistPolicy"), "never");
    assertEquals(descriptor.getFieldValue("log"), "F");
    assertEquals(descriptor.getFieldValue("visibility"), "1");
    assertEquals(descriptor.getFieldValue("export"), "F");
    assertEquals(descriptor.getFields().length, 7);
    commonCheck();
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:35,代码来源:DefaultDescriptorTest.java

示例13: testNegative

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify that value of attribute return value which return getter method if
 * currencyTimeLimit < 0.
 * <ul>
 * Step by step:
 * <li>1.Create java class, which is not MBean. This class has getter and
 * setter methods.
 * <li>2.Create ModelMBeanAttibuteInfo object for class in 1st step.
 * <li>3.Extract descriptor from ModelMBeanAttibuteInfo class and set
 * additional fields currencyTimeLimit < 0 and setMethod=nameOfSetterMethod.
 * <li>4.Create ModelMBeanInfoSupport object.
 * <li>5.Create RequiredModelMBean object.
 * <li>6.Create notification listener and register it in RequiredModelMBean
 * object for attribute using addAttributeChangeNotificationListener.
 * <li>7.Instance of java class in 1st step sets managed resource for
 * RequiredModelMBean using setManagedResource method.
 * <li>8.Create objectName.
 * <li>9.Register RequiredModelMBean object in MBeanServer with objectName
 * specified in previous step.
 * <li>10.Set attribute on MBeanServer using setAttribute method.
 * <li>11.Verify that notification listener was notified about change
 * attribute.
 * <li>12.Verify that setter method was invoked.
 * <li>13.Verify that getAttribute of MBeanServer returns correct value of
 * attribute and getter method was invoked.
 * <li>14. Invoke again getAttribute of MBeanServer method and verify
 * returned value. Also verify that getter method was invoked.
 * </ul>
 */
public Result testNegative() throws Exception {
    Method getter = class1.getMethod("getG", null);
    Method setter = class1.getMethod("setG", new Class[] { String.class });
    ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
        "name", "description", getter, setter);
    Descriptor descriptor = attributeInfoForG.getDescriptor();
    descriptor.setField("currencyTimeLimit", "-1");
    descriptor.setField("setMethod", setter.getName());
    descriptor.setField("getMethod", getter.getName());
    attributeInfoForG.setDescriptor(descriptor);
    ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
    ModelMBeanOperationInfo[] operationInfos = new ModelMBeanOperationInfo[] {
        new ModelMBeanOperationInfo("description", setter),
        new ModelMBeanOperationInfo("description", getter) };
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", attributeInfos, null,
        operationInfos, null);
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    ManageResourceAndNotification notificationListener = new ManageResourceAndNotification();
    requiredModelMBean.addAttributeChangeNotificationListener(
        notificationListener, attributeInfoForG.getName(),
        ManageResourceAndNotification.handback);
    ManageResourceAndNotification managedResource = new ManageResourceAndNotification();
    requiredModelMBean.setManagedResource(managedResource,
        "ObjectReference");
    ObjectName objectName = new ObjectName("domain", "name", "simple name");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    String newValue = "new value";
    server.setAttribute(objectName, new Attribute(attributeInfoForG
        .getName(), newValue));
    assertTrue(notificationListener.isWasHandleNotificationInvoked());
    assertEquals(managedResource.getG(), newValue);
    managedResource.isGetGWasInvoked();
    assertEquals(server.getAttribute(objectName, attributeInfoForG
        .getName()), newValue);
    assertTrue(managedResource.isGetGWasInvoked());
    assertTrue(server.getMBeanInfo(objectName).getAttributes()[0] == attributeInfoForG);
    assertNull(attributeInfoForG.getDescriptor().getFieldValue("value"));
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:72,代码来源:RequiredModelMBeanTest.java

示例14: testZero

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify that value of attribute retrieves a value from cache if
 * currencyTimeLimit = 0.
 * <ul>
 * Step by step:
 * <li>1.Create java class, which is not MBean. This class has getter and
 * setter methods.
 * <li>2.Create ModelMBeanAttibuteInfo object for class in 1st step.
 * <li>3.Extract descriptor from ModelMBeanAttibuteInfo class and set
 * additional fields currencyTimeLimit = 0 and setMethod=nameOfSetterMethod.
 * <li>4.Create ModelMBeanInfoSupport object.
 * <li>5.Create RequiredModelMBean object.
 * <li>6.Create notification listener and register it in RequiredModelMBean
 * object for attribute using addAttributeChangeNotificationListener.
 * <li>7.Instance of java class in 1st step sets managed resource for
 * RequiredModelMBean using setManagedResource method.
 * <li>8.Create objectName.
 * <li>9.Register RequiredModelMBean object in MBeanServer with objectName
 * specified in previous step.
 * <li>10.Set attribute on MBeanServer using setAttribute method.
 * <li>11.Verify that notification listener was notified about change
 * attribute.
 * <li>12.Verify that setter method was invoked.
 * <li>13.Verify that getAttribute returns correct value of attribute and
 * getter method was not invoked.
 * <li>14.Verify value of field value of descriptor of
 * ModelMBeanAttibuteInfo.
 */
public Result testZero() throws Exception {
    Method getter = class1.getMethod("getG", null);
    Method setter = class1.getMethod("setG", new Class[] { String.class });
    ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
        "name", "description", getter, setter);
    Descriptor descriptor = attributeInfoForG.getDescriptor();
    descriptor.setField("currencyTimeLimit", "0");
    descriptor.setField("setMethod", setter.getName());
    descriptor.setField("getMethod", getter.getName());
    attributeInfoForG.setDescriptor(descriptor);
    ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
    ModelMBeanOperationInfo[] operationInfos = new ModelMBeanOperationInfo[] {
        new ModelMBeanOperationInfo("description", setter),
        new ModelMBeanOperationInfo("description", getter) };
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", attributeInfos, null,
        operationInfos, null);
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    ManageResourceAndNotification notificationListener = new ManageResourceAndNotification();
    requiredModelMBean.addAttributeChangeNotificationListener(
        notificationListener, attributeInfoForG.getName(),
        ManageResourceAndNotification.handback);
    ManageResourceAndNotification managedResource = new ManageResourceAndNotification();
    requiredModelMBean.setManagedResource(managedResource,
        "ObjectReference");
    ObjectName objectName = new ObjectName("domain", "name", "simple name");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    String newValue = "new value";
    server.setAttribute(objectName, new Attribute(attributeInfoForG
        .getName(), newValue));
    assertTrue(notificationListener.isWasHandleNotificationInvoked());
    assertEquals(managedResource.getG(), newValue);
    managedResource.isGetGWasInvoked();
    assertEquals(server.getAttribute(objectName, attributeInfoForG
        .getName()), newValue);
    assertFalse(managedResource.isGetGWasInvoked());
    assertTrue(server.getMBeanInfo(objectName).getAttributes()[0] == attributeInfoForG);
    assertEquals(attributeInfoForG.getDescriptor().getFieldValue("value"),
        newValue);
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:72,代码来源:RequiredModelMBeanTest.java

示例15: testNotPresent

import javax.management.modelmbean.ModelMBeanInfoSupport; //导入依赖的package包/类
/**
 * Verify that value of attribute always retrieves from returned value of
 * getter method if currencyTimeLimit is not defined in descriptor.
 * <p>
 * Instructions are the same as in testNegative.
 */
public Result testNotPresent() throws Exception {
    Method getter = class1.getMethod("getG", null);
    Method setter = class1.getMethod("setG", new Class[] { String.class });
    ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
        "name", "description", getter, setter);
    Descriptor descriptor = attributeInfoForG.getDescriptor();
    descriptor.setField("setMethod", setter.getName());
    descriptor.setField("getMethod", getter.getName());
    attributeInfoForG.setDescriptor(descriptor);
    ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
    ModelMBeanOperationInfo[] operationInfos = new ModelMBeanOperationInfo[] {
        new ModelMBeanOperationInfo("description", setter),
        new ModelMBeanOperationInfo("description", getter) };
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", attributeInfos, null,
        operationInfos, null);
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
        beanInfoSupport);
    ManageResourceAndNotification notificationListener = new ManageResourceAndNotification();
    requiredModelMBean.addAttributeChangeNotificationListener(
        notificationListener, attributeInfoForG.getName(),
        ManageResourceAndNotification.handback);
    ManageResourceAndNotification managedResource = new ManageResourceAndNotification();
    requiredModelMBean.setManagedResource(managedResource,
        "ObjectReference");
    ObjectName objectName = new ObjectName("domain", "name", "simple name");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    String newValue = "new value";
    server.setAttribute(objectName, new Attribute(attributeInfoForG
        .getName(), newValue));
    assertTrue(notificationListener.isWasHandleNotificationInvoked());
    assertEquals(managedResource.getG(), newValue);
    managedResource.isGetGWasInvoked();
    assertEquals(server.getAttribute(objectName, attributeInfoForG
        .getName()), newValue);
    assertTrue(managedResource.isGetGWasInvoked());
    assertTrue(server.getMBeanInfo(objectName).getAttributes()[0] == attributeInfoForG);
    assertNull(attributeInfoForG.getDescriptor().getFieldValue("value"));
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:48,代码来源:RequiredModelMBeanTest.java


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