/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>The default implementation delegates to {@link JmxUtils#isMBean}, * which checks for {@link javax.management.DynamicMBean} classes as well * as classes with corresponding "*MBean" interface (Standard MBeans) * or corresponding "*MXBean" interface (Java 6 MXBeans). * @param beanClass the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.support.JmxUtils#isMBean(Class) */ protected boolean isMBean(@Nullable Class<?> beanClass) { return JmxUtils.isMBean(beanClass); }
/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>The default implementation delegates to {@link JmxUtils#isMBean}, * which checks for {@link javax.management.DynamicMBean} classes as well * as classes with corresponding "*MBean" interface (Standard MBeans) * or corresponding "*MXBean" interface (Java 6 MXBeans). * @param beanClass the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.support.JmxUtils#isMBean(Class) */ protected boolean isMBean(@Nullable Class<?> beanClass) { return JmxUtils.isMBean(beanClass); }
@Test public void testIsMBean() { // Correctly returns true for a class assertTrue(JmxUtils.isMBean(JmxClass.class)); // Correctly returns false since JmxUtils won't navigate to the extended interface assertFalse(JmxUtils.isMBean(SpecializedJmxInterface.class)); // Incorrectly returns true since it doesn't detect that this is an interface assertFalse(JmxUtils.isMBean(JmxInterface.class)); }
@Test public void testSimpleMBeanThroughInheritance() throws Exception { Bar bar = new Bar(); Abc abc = new Abc(); assertTrue("Simple MBean (through inheritance) not detected correctly", JmxUtils.isMBean(bar.getClass())); assertTrue("Simple MBean (through 2 levels of inheritance) not detected correctly", JmxUtils.isMBean(abc.getClass())); }
@Test public void notMXBean() throws Exception { assertFalse("MXBean annotation not detected correctly", JmxUtils.isMBean(FooNotX.class)); }
@Test public void testSimpleMBean() throws Exception { Foo foo = new Foo(); assertTrue("Simple MBean not detected correctly", JmxUtils.isMBean(foo.getClass())); }
@Test public void testNotAnMBean() throws Exception { assertFalse("Object incorrectly identified as an MBean", JmxUtils.isMBean(Object.class)); }
@Test public void annotatedMXBean() throws Exception { assertTrue("MXBean annotation not detected correctly", JmxUtils.isMBean(FooX.class)); }
@Test public void testIsMBeanWithStandardMBeanInherited() throws Exception { StandardMBean mbean = new StandardMBeanImpl(); assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass())); }
@Test public void testSimpleMXBean() throws Exception { FooX foo = new FooX(); assertTrue("Simple MXBean not detected correctly", JmxUtils.isMBean(foo.getClass())); }
@Test public void testIsMBeanWithDynamicMBean() throws Exception { DynamicMBean mbean = new TestDynamicMBean(); assertTrue("Dynamic MBean not detected correctly", JmxUtils.isMBean(mbean.getClass())); }
@Test public void testIsMBeanWithStandardMBeanWrapper() throws Exception { StandardMBean mbean = new StandardMBean(new JmxTestBean(), IJmxTestBean.class); assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass())); }
/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>The default implementation delegates to {@link JmxUtils#isMBean}, * which checks for {@link javax.management.DynamicMBean} classes as well * as classes with corresponding "*MBean" interface (Standard MBeans) * or corresponding "*MXBean" interface (Java 6 MXBeans). * @param beanClass the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.support.JmxUtils#isMBean(Class) */ protected boolean isMBean(@Nullable Class<?> beanClass) { return JmxUtils.isMBean(beanClass); }
/** * Exclude candidate bean from {@link MBeanExporter} to auto-scan the instance and export it via JMX. * * @param candidate candidate object * @param beanName bean name */ protected final void excludeMBeanIfNecessary(Object candidate, String beanName) { if (this.mbeanExporter != null && JmxUtils.isMBean(candidate.getClass())) { this.mbeanExporter.addExcludedBean(beanName); } } }