javax.management.modelmbean.ModelMBean Java Examples

The following examples show how to use javax.management.modelmbean.ModelMBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
	Assert.notNull(managedResource, "Managed resource must not be null");
	Assert.notNull(objectName, "ObjectName must not be null");
	try {
		if (isMBean(managedResource.getClass())) {
			doRegister(managedResource, objectName);
		}
		else {
			ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
			doRegister(mbean, objectName);
			injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
		}
	}
	catch (JMException ex) {
		throw new UnableToRegisterMBeanException(
				"Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
	}
}
 
Example #2
Source File: DefaultManagementMBeanAssemblerTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testHappyPath() throws MalformedObjectNameException, JMException {
  TestMbean testMbean = new TestMbean();
  ModelMBean mbean = defaultManagementMBeanAssembler.assemble(testMbean, new ObjectName("org.activiti.jmx.Mbeans:type=something"));
  assertNotNull(mbean);
  assertNotNull(mbean.getMBeanInfo());
  assertNotNull(mbean.getMBeanInfo().getAttributes());
  MBeanAttributeInfo[] attributes = mbean.getMBeanInfo().getAttributes();
  assertEquals(2, attributes.length);
  assertTrue((attributes[0].getName().equals("TestAttributeString") && attributes[1].getName().equals("TestAttributeBoolean") || (attributes[1].getName().equals("TestAttributeString") && attributes[0]
      .getName().equals("TestAttributeBoolean"))));
  assertNotNull(mbean.getMBeanInfo().getOperations());
  MBeanOperationInfo[] operations = mbean.getMBeanInfo().getOperations();
  assertNotNull(operations);
  assertEquals(3, operations.length);

}
 
Example #3
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
	Assert.notNull(managedResource, "Managed resource must not be null");
	Assert.notNull(objectName, "ObjectName must not be null");
	try {
		if (isMBean(managedResource.getClass())) {
			doRegister(managedResource, objectName);
		}
		else {
			ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
			doRegister(mbean, objectName);
			injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
		}
	}
	catch (JMException ex) {
		throw new UnableToRegisterMBeanException(
				"Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
	}
}
 
Example #4
Source File: MBeanExporter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
	Assert.notNull(managedResource, "Managed resource must not be null");
	Assert.notNull(objectName, "ObjectName must not be null");
	try {
		if (isMBean(managedResource.getClass())) {
			doRegister(managedResource, objectName);
		}
		else {
			ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
			doRegister(mbean, objectName);
			injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
		}
	}
	catch (JMException ex) {
		throw new UnableToRegisterMBeanException(
				"Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
	}
}
 
Example #5
Source File: MBeanExporter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
	Assert.notNull(managedResource, "Managed resource must not be null");
	Assert.notNull(objectName, "ObjectName must not be null");
	try {
		if (isMBean(managedResource.getClass())) {
			doRegister(managedResource, objectName);
		}
		else {
			ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
			doRegister(mbean, objectName);
			injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
		}
	}
	catch (JMException ex) {
		throw new UnableToRegisterMBeanException(
				"Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
	}
}
 
Example #6
Source File: DefaultManagementMBeanAssemblerTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotificationAware() throws MalformedObjectNameException, JMException {
    NotificationSenderAware mockedNotificationAwareMbean = mock(NotificationSenderAware.class);
    ModelMBean modelBean = defaultManagementMBeanAssembler.assemble(mockedNotificationAwareMbean, new ObjectName("org.flowable.jmx.Mbeans:type=something"));
    assertNotNull(modelBean);
    ArgumentCaptor<NotificationSender> argument = ArgumentCaptor.forClass(NotificationSender.class);
    verify(mockedNotificationAwareMbean).setNotificationSender(argument.capture());
    assertNotNull(argument);
    assertNotNull(argument.getValue());

}
 
Example #7
Source File: MBeanExporter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * If the supplied managed resource implements the {@link NotificationPublisherAware} an instance of
 * {@link org.springframework.jmx.export.notification.NotificationPublisher} is injected.
 */
private void injectNotificationPublisherIfNecessary(
		Object managedResource, @Nullable ModelMBean modelMBean, @Nullable ObjectName objectName) {

	if (managedResource instanceof NotificationPublisherAware && modelMBean != null && objectName != null) {
		((NotificationPublisherAware) managedResource).setNotificationPublisher(
				new ModelMBeanNotificationPublisher(modelMBean, objectName, managedResource));
	}
}
 
Example #8
Source File: MBeanExporter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the {@code MBeanServer}.
 * @param bean the bean to register, either an MBean or a plain bean
 * @param beanKey the key associated with this bean in the beans map
 * @return the {@code ObjectName} under which the bean was registered
 * with the {@code MBeanServer}
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
	ObjectName objectName = getObjectName(bean, beanKey);
	Object mbeanToExpose = null;
	if (isMBean(bean.getClass())) {
		mbeanToExpose = bean;
	}
	else {
		DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
		if (adaptedBean != null) {
			mbeanToExpose = adaptedBean;
		}
	}

	if (mbeanToExpose != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Located MBean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		doRegister(mbeanToExpose, objectName);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
		doRegister(mbean, objectName);
		injectNotificationPublisherIfNecessary(bean, mbean, objectName);
	}

	return objectName;
}
 
Example #9
Source File: MBeanExporter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * If the supplied managed resource implements the {@link NotificationPublisherAware} an instance of
 * {@link org.springframework.jmx.export.notification.NotificationPublisher} is injected.
 */
private void injectNotificationPublisherIfNecessary(
		Object managedResource, @Nullable ModelMBean modelMBean, @Nullable ObjectName objectName) {

	if (managedResource instanceof NotificationPublisherAware && modelMBean != null && objectName != null) {
		((NotificationPublisherAware) managedResource).setNotificationPublisher(
				new ModelMBeanNotificationPublisher(modelMBean, objectName, managedResource));
	}
}
 
Example #10
Source File: MBeanExporter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the {@code MBeanServer}.
 * @param bean the bean to register, either an MBean or a plain bean
 * @param beanKey the key associated with this bean in the beans map
 * @return the {@code ObjectName} under which the bean was registered
 * with the {@code MBeanServer}
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
	ObjectName objectName = getObjectName(bean, beanKey);
	Object mbeanToExpose = null;
	if (isMBean(bean.getClass())) {
		mbeanToExpose = bean;
	}
	else {
		DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
		if (adaptedBean != null) {
			mbeanToExpose = adaptedBean;
		}
	}

	if (mbeanToExpose != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Located MBean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		doRegister(mbeanToExpose, objectName);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
		doRegister(mbean, objectName);
		injectNotificationPublisherIfNecessary(bean, mbean, objectName);
	}

	return objectName;
}
 
Example #11
Source File: MBeanExporter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Creates an MBean that is configured with the appropriate management
 * interface for the supplied managed resource.
 * @param managedResource the resource that is to be exported as an MBean
 * @param beanKey the key associated with the managed bean
 * @see #createModelMBean()
 * @see #getMBeanInfo(Object, String)
 */
protected ModelMBean createAndConfigureMBean(Object managedResource, String beanKey)
		throws MBeanExportException {
	try {
		ModelMBean mbean = createModelMBean();
		mbean.setModelMBeanInfo(getMBeanInfo(managedResource, beanKey));
		mbean.setManagedResource(managedResource, MR_TYPE_OBJECT_REFERENCE);
		return mbean;
	}
	catch (Throwable ex) {
		throw new MBeanExportException("Could not create ModelMBean for managed resource [" +
				managedResource + "] with key '" + beanKey + "'", ex);
	}
}
 
Example #12
Source File: DefaultManagementMBeanAssembler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
  ModelMBeanInfo mbi = null;

  // use the default provided mbean which has been annotated with JMX
  // annotations
  LOG.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;
}
 
Example #13
Source File: DefaultManagementMBeanAssemblerTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotificationAware() throws MalformedObjectNameException, JMException {
  NotificationSenderAware mockedNotificationAwareMbean = mock(NotificationSenderAware.class);
  ModelMBean modelBean = defaultManagementMBeanAssembler.assemble(mockedNotificationAwareMbean, new ObjectName("org.activiti.jmx.Mbeans:type=something"));
  assertNotNull(modelBean);
  ArgumentCaptor<NotificationSender> argument = ArgumentCaptor.forClass(NotificationSender.class);
  verify(mockedNotificationAwareMbean).setNotificationSender(argument.capture());
  assertNotNull(argument);
  assertNotNull(argument.getValue());

}
 
Example #14
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the {@code MBeanServer}.
 * @param bean the bean to register, either an MBean or a plain bean
 * @param beanKey the key associated with this bean in the beans map
 * @return the {@code ObjectName} under which the bean was registered
 * with the {@code MBeanServer}
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
	ObjectName objectName = getObjectName(bean, beanKey);
	Object mbeanToExpose = null;
	if (isMBean(bean.getClass())) {
		mbeanToExpose = bean;
	}
	else {
		DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
		if (adaptedBean != null) {
			mbeanToExpose = adaptedBean;
		}
	}
	if (mbeanToExpose != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		doRegister(mbeanToExpose, objectName);
	}
	else {
		if (logger.isInfoEnabled()) {
			logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
		doRegister(mbean, objectName);
		injectNotificationPublisherIfNecessary(bean, mbean, objectName);
	}
	return objectName;
}
 
Example #15
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * If the supplied managed resource implements the {@link NotificationPublisherAware} an instance of
 * {@link org.springframework.jmx.export.notification.NotificationPublisher} is injected.
 */
private void injectNotificationPublisherIfNecessary(
		Object managedResource, ModelMBean modelMBean, ObjectName objectName) {

	if (managedResource instanceof NotificationPublisherAware) {
		((NotificationPublisherAware) managedResource).setNotificationPublisher(
				new ModelMBeanNotificationPublisher(modelMBean, objectName, managedResource));
	}
}
 
Example #16
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If the supplied managed resource implements the {@link NotificationPublisherAware} an instance of
 * {@link org.springframework.jmx.export.notification.NotificationPublisher} is injected.
 */
private void injectNotificationPublisherIfNecessary(
		Object managedResource, ModelMBean modelMBean, ObjectName objectName) {

	if (managedResource instanceof NotificationPublisherAware) {
		((NotificationPublisherAware) managedResource).setNotificationPublisher(
				new ModelMBeanNotificationPublisher(modelMBean, objectName, managedResource));
	}
}
 
Example #17
Source File: DefaultManagementMBeanAssembler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an MBean that is configured with the appropriate management
 * interface for the supplied managed resource.
 * @param managedResource the resource that is to be exported as an MBean
 * @param beanKey the key associated with the managed bean
 * @see #createModelMBean()
 * @see #getMBeanInfo(Object, String)
 */
protected ModelMBean createAndConfigureMBean(Object managedResource, String beanKey)
		throws MBeanExportException {
	try {
		ModelMBean mbean = createModelMBean();
		mbean.setModelMBeanInfo(getMBeanInfo(managedResource, beanKey));
		mbean.setManagedResource(managedResource, MR_TYPE_OBJECT_REFERENCE);
		return mbean;
	}
	catch (Exception ex) {
		throw new MBeanExportException("Could not create ModelMBean for managed resource [" +
				managedResource + "] with key '" + beanKey + "'", ex);
	}
}
 
Example #19
Source File: JobExecutorMBeanTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {

    ModelMBean modelBean = assembler.assemble(jobExecutorMbean, new ObjectName("domain", "key", "value"));
    assertNotNull(modelBean);
    MBeanInfo beanInfo = modelBean.getMBeanInfo();
    assertNotNull(beanInfo);
    assertNotNull(beanInfo.getOperations());
    assertEquals(2, beanInfo.getOperations().length);
    int counter = 0;

    for (MBeanOperationInfo op : beanInfo.getOperations()) {
        if (op.getName().equals("setJobExecutorActivate")) {
            counter++;
            assertEquals("set job executor activate", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.Boolean", op.getSignature()[0].getType());
        }
    }
    assertEquals(1, counter);

    // check attributes
    assertNotNull(beanInfo.getAttributes());
    assertEquals(1, beanInfo.getAttributes().length);

    counter = 0;

    for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
        if (attr.getName().equals("JobExecutorActivated")) {
            counter++;
            assertEquals("check if the job executor is activated", attr.getDescription());
            assertEquals("boolean", attr.getType());
        }
    }
    assertEquals(1, counter);

}
 
Example #20
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the {@code MBeanServer}.
 * @param bean the bean to register, either an MBean or a plain bean
 * @param beanKey the key associated with this bean in the beans map
 * @return the {@code ObjectName} under which the bean was registered
 * with the {@code MBeanServer}
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
	ObjectName objectName = getObjectName(bean, beanKey);
	Object mbeanToExpose = null;
	if (isMBean(bean.getClass())) {
		mbeanToExpose = bean;
	}
	else {
		DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
		if (adaptedBean != null) {
			mbeanToExpose = adaptedBean;
		}
	}
	if (mbeanToExpose != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		doRegister(mbeanToExpose, objectName);
	}
	else {
		if (logger.isInfoEnabled()) {
			logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" +
					objectName + "]");
		}
		ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
		doRegister(mbean, objectName);
		injectNotificationPublisherIfNecessary(bean, mbean, objectName);
	}
	return objectName;
}
 
Example #21
Source File: JobExecutorMBeanTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {

  ModelMBean modelBean = assembler.assemble(jobExecutorMbean, new ObjectName("domain", "key", "value"));
  assertNotNull(modelBean);
  MBeanInfo beanInfo = modelBean.getMBeanInfo();
  assertNotNull(beanInfo);
  assertNotNull(beanInfo.getOperations());
  assertEquals(2, beanInfo.getOperations().length);
  int counter = 0;

  for (MBeanOperationInfo op : beanInfo.getOperations()) {
    if (op.getName().equals("setJobExecutorActivate")) {
      counter++;
      assertEquals("set job executor activate", op.getDescription());
      assertEquals("void", op.getReturnType());
      assertEquals(1, op.getSignature().length);
      assertEquals("java.lang.Boolean", op.getSignature()[0].getType());
    }
  }
  assertEquals(1, counter);

  // check attributes
  assertNotNull(beanInfo.getAttributes());
  assertEquals(1, beanInfo.getAttributes().length);

  counter = 0;

  for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
    if (attr.getName().equals("JobExecutorActivated")) {
      counter++;
      assertEquals("check if the job executor is activated", attr.getDescription());
      assertEquals("boolean", attr.getType());
    }
  }
  assertEquals(1, counter);

}
 
Example #22
Source File: CacheServerJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ModelMBean getModelMBean() {
  return this.modelMBean;
}
 
Example #23
Source File: AgentImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ModelMBean getModelMBean() {
	return this.modelMBean;
}
 
Example #24
Source File: SystemMemberCacheJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ModelMBean getModelMBean() {
	return this.modelMBean;
}
 
Example #25
Source File: SystemMemberJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ModelMBean getModelMBean() {
	return this.modelMBean;
}
 
Example #26
Source File: SystemMemberCacheJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void setModelMBean(ModelMBean modelMBean) {
	this.modelMBean = modelMBean;
}
 
Example #27
Source File: DistributionLocatorJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ModelMBean getModelMBean() {
	return this.modelMBean;
}
 
Example #28
Source File: SystemMemberJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ModelMBean getModelMBean() {
	return this.modelMBean;
}
 
Example #29
Source File: DistributionLocatorJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void setModelMBean(ModelMBean modelMBean) {
	this.modelMBean = modelMBean;
}
 
Example #30
Source File: SystemMemberJmxImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void setModelMBean(ModelMBean modelMBean) {
	this.modelMBean = modelMBean;
}