• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RequiredModelMBean类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testRegisterandUnregister

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
@Test
public void testRegisterandUnregister() throws JMException {
    reset();

    // Register MBean and return different ObjectName
    when(mbeanServer.isRegistered(sourceObjectName)).thenReturn(false);
    when(mbeanServer.registerMBean(any(RequiredModelMBean.class), any(ObjectName.class))).thenReturn(instance);

    when(instance.getObjectName()).thenReturn(registeredObjectName);
    when(mbeanServer.isRegistered(registeredObjectName)).thenReturn(true);

    agent.register(object, sourceObjectName);

    verify(mbeanServer).isRegistered(sourceObjectName);
    verify(mbeanServer).registerMBean(any(RequiredModelMBean.class), any(ObjectName.class));

    assertTrue(agent.isRegistered(sourceObjectName));

    agent.unregister(sourceObjectName);
    verify(mbeanServer).unregisterMBean(registeredObjectName);
    assertFalse(agent.isRegistered(sourceObjectName));

}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:24,代码来源:DefaultManagementAgentTest.java


示例2: testSendNotification

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
/**
 * Verify that RequiredModelMBean generates correct generic notification.
 * <ul>
 * Step by step:
 * <li>Create RequiredModelMBean object using RequiredModelMBean()
 * constructor.
 * <li>Set Integer class as managed resource for RequiredModelMBean object.
 * <li>Create ObjectName object.
 * <li>Register RequiredModelMBean object in MBeanServer with above
 * objectName.
 * <li> Create notification listener and add this listener in server.
 * <li>Send notification using sendNotification(msg) method of
 * RequiredModelMBean.
 * <li> Verify that handleNotification method of listener was invoked.
 * <li>Verify notification in parameter of handleNotification method: its
 * type=jmx.modelmbean.generic, its message=msg in 4 step and sequence
 * number=1.
 * </ul>
 */
public Result testSendNotification() throws Exception {
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean();
    requiredModelMBean
        .setManagedResource(new Integer(7), "ObjectReference");
    ObjectName objectName = new ObjectName("modelmbean:type=Operation");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    final String message = "message";
    NotificationListener notificationListener = new NotificationListener() {
        public void handleNotification(Notification arg0, Object arg1) {
            ishandleNotificationInvoked = true;
            assertEquals(arg0.getType(), "jmx.modelmbean.generic");
            assertEquals(arg0.getMessage(), message);
            assertEquals(arg0.getSequenceNumber(), 1);
        }

    };
    server.addNotificationListener(objectName, notificationListener, null,
        null);
    requiredModelMBean.sendNotification(message);
    assertTrue(ishandleNotificationInvoked);
    server.unregisterMBean(objectName);
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:44,代码来源:DefaultRequiredModelMBeanTest.java


示例3: testNotPresent

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例4: registerMBean

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
/**
 * Registers an mBean at an MBeanServer. If there is already an mbean registered
 * under the specified name, it is first de-registered.
 *
 * @param name  the objectName
 * @param mbean the modelMbean to register
 * @throws ConfigurationException
 */
private static void registerMBean(ObjectName name, RequiredModelMBean mbean) throws ConfigurationException {
    MBeanServer server = getMBeanServer();
    if (server != null) {
        LOG.debug("got an MBean server");
        try {
            if (server.isRegistered(name)) {
                LOG.debug("unregistering [" + name.getCanonicalName() + "] as it already exists");
                server.unregisterMBean(name);
            }
            server.registerMBean(mbean, name);
        } catch (InstanceAlreadyExistsException iae) {
            LOG.warn("Could not register mbean " + iae.getMessage());
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
        LOG.debug("MBean [" + name.getCanonicalName() + "] registered");
    } else {
        LOG.warn("No MBean server found");
    }
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:29,代码来源:JmxMbeanHelper.java


示例5: testRegisterExistingMBeanWithUserSuppliedObjectName

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例6: assemble

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
@Override
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;

    // use the default provided mbean which has been annotated with JMX
    // annotations
    LOGGER.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
    mbi = assembler.getMBeanInfo(obj, null, name.toString());

    if (mbi == null) {
        return null;
    }

    RequiredModelMBean mbean = new RequiredModelMBean(mbi);

    try {
        mbean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException e) {
        throw new JMException(e.getMessage());
    }

    // Allows the managed object to send notifications
    if (obj instanceof NotificationSenderAware) {
        ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
    }

    return mbean;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:29,代码来源:DefaultManagementMBeanAssembler.java


示例7: test01

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例8: testLogging

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例9: testException

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例10: testNegative

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例11: hookupAdapter

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
/**
 * Hooks an {@link nl.nn.adapterframework.core.Adapter Adapter} to the MBean server
 *
 * @param adapter the adapter
 * @throws ConfigurationException when something goes wrong
 */
public static void hookupAdapter(IAdapter adapter) throws ConfigurationException {
    try {
        ObjectName objectName = getObjectName(adapter);

        RequiredModelMBean modelMbean =
                new RequiredModelMBean(createMBeanInfo(adapter));
        modelMbean.setManagedResource(adapter, "ObjectReference");
        LOG.debug("modelMBean generated for object " + objectName);
        registerMBean(objectName, modelMbean);
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:20,代码来源:JmxMbeanHelper.java


示例12: registerMBean

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
/**
	 * Registers an mBean at an MBeanServer. If there is already an mbean registered 
	 * under the specified name, it is first de-registered.
	 * @param name	the objectName
	 * @param mbean	the modelMbean to register
	 * @throws ConfigurationException
	 */
	public static void registerMBean(ObjectName name, RequiredModelMBean mbean) throws Exception {

		MBeanServer server = getMBeanServer(); 
//		if (server.isRegistered(name)) {
//				log.debug("unregistering ["+name.getCanonicalName()+"] as it already exists");
//				server.unregisterMBean(name);
//		}
		server.registerMBean(mbean, name);
	
		log.debug("MBean [" + name.getCanonicalName() + "] registered");
		return;		
	}
 
开发者ID:ibissource,项目名称:iaf,代码行数:20,代码来源:JmxUtils.java


示例13: testQueryMBeans

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
@Test
public void testQueryMBeans() throws Exception {
    DummyTransport transport = new DummyTransport(new SequencedRequestMatcher());
    transport.addExchange(ConnectorTest.class, "queryMBeans");
    Connector connector = transport.createConnector();
    Iterator<ObjectInstance> mbeans = connector.queryMBeans(new ObjectName("WebSphere:type=Server,*"), null).iterator();
    assertTrue(mbeans.hasNext());
    ObjectInstance mbean = mbeans.next();
    assertEquals(RequiredModelMBean.class.getName(), mbean.getClassName());
    ObjectName name = mbean.getObjectName();
    assertEquals("WebSphere", name.getDomain());
    assertEquals("server1", name.getKeyProperty("name"));
    assertFalse(mbeans.hasNext());
}
 
开发者ID:veithen,项目名称:visualwas,代码行数:15,代码来源:ConnectorTest.java


示例14: assemble

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;

    // prefer to use the managed instance if it has been annotated with Spring JMX annotations
    if (obj instanceof ManagedInstance) {
        Object custom = ((ManagedInstance) obj).getInstance();
        if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
            LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom);
            // get the mbean info from the custom managed object
            mbi = springAssembler.getMBeanInfo(custom, name.toString());
            // and let the custom object be registered in JMX
            obj = custom;
        }
    }

    if (mbi == null) {
        if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class)) {
            // the object has a Spring ManagedResource annotations so assemble the MBeanInfo
            LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
            mbi = springAssembler.getMBeanInfo(obj, name.toString());
        } else {
            // fallback and let the default mbean assembler handle this instead
            return super.assemble(mBeanServer, obj, name);
        }
    }

    LOG.trace("Assembled MBeanInfo {}", mbi);

    RequiredModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
    mbean.setModelMBeanInfo(mbi);

    try {
        mbean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException e) {
        throw new JMException(e.getMessage());
    }

    // Allows the managed object to send notifications
    if (obj instanceof NotificationSenderAware) {
        ((NotificationSenderAware)obj).setNotificationSender(new NotificationSenderAdapter(mbean));
    }

    return mbean;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:45,代码来源:SpringManagementMBeanAssembler.java


示例15: testNegative

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例16: testZero

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例17: testNotPresent

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的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


示例18: testPositive

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
/**
 * Verify that invoke method retrieves returned value of method from cache
 * or invoke operation depends on currencyTimeLimit > 0 and
 * lastUpdatedTimeStamp.
 * <ul>
 * Step by step:
 * <li>Create operation method without parameters which always returns
 * 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>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>Verify value of field `value` in descriptor for
 * ModelMBeanOperationInfo object.
 * <li>Invoke again operation method thru invoke method of MBeanServer.
 * <li>Verify returned value is not changed.
 * <li>Verify that operation method wasn't invoked.
 * <li>Verify value of field `value` in descriptor for
 * ModelMBeanOperationInfo object is not changed.
 * <li>Change returned value of operation method.
 * <li> Wait currencyTimeLimit seconds.
 * <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.
 * <li>Verify value of field `value` in descriptor for
 * ModelMBeanOperationInfo object is changed and verify this value.
 * </ul>
 */
public Result testPositive() throws Exception {
    Method method = class1.getMethod("simpleMethod", null);
    ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
        "description", method);
    Descriptor descriptor = operationInfo1.getDescriptor();
    int currencyTimeLimit = 5;
    descriptor.setField("currencyTimeLimit", currencyTimeLimit + "");
    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());
    printValue(server.getMBeanInfo(objectName));
    value = server.invoke(objectName, method.getName(), null, null);
    assertEquals(value, returnedObject);
    assertFalse(isInvokedMethod());
    printValue(server.getMBeanInfo(objectName));
    returnedObject = new Integer(10);
    Thread.sleep(1000 * currencyTimeLimit + latancy);
    value = server.invoke(objectName, method.getName(), null, null);
    assertEquals(value, returnedObject);
    printValue(server.getMBeanInfo(objectName));
    assertTrue(isInvokedMethod());
    return result();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:73,代码来源:InvocationTest.java


示例19: testMethodWithParameter

import javax.management.modelmbean.RequiredModelMBean; //导入依赖的package包/类
/**
 * Verify that invoke method invokes correctly method with parameter and
 * without it.
 * <ul>
 * Step by step:
 * <li>Create operation method without parameters which always returns the
 * same value.
 * <li>Create operation method with name as in 1 step with parameter which
 * always returns the parameter.
 * <li>Create 2 ModelMBeanOperationInfo object for both operation method.
 * <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 1st operation method thru invoke method of MBeanServer:
 * server.invoke(objectName, methodName, null, null).
 * <li>Verify value which the invoke method returned is the same as value
 * which the 1st operation method returned.
 * <li>Invoke 2nd operation method thru invoke method of MBeanServer:
 * server.invoke(objectName, methodName, argument, signature).
 * <li>Verify value which the invoke method returned is the same as
 * argument.
 * </ul>
 */
public Result testMethodWithParameter() throws Exception {
    Method method1 = class1.getDeclaredMethod("simpleMethod",
        new Class[] { int.class });
    ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
        "description", method1);
    Method method2 = class1.getMethod("simpleMethod", n 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XmlResponse类代码示例发布时间:2022-05-21
下一篇:
Java Preloader类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap