Hi all, I've written a library that uses Java 8 functions and some type inference to create MBeans in a single statement:
class UserExample { static final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); public static void registerUser() throws Exception { Address address = new Address("street1", "city", "state"); final User user = new User("name", 12, address); final DynamicMBean userBean = DynamicBean.builder() .withSimpleAttribute(String.class, "name", user::getName, user::setName) .withSimpleAttribute(Integer.TYPE, "age", user::getAge, user::setAge) .build(); ObjectName objectName = new ObjectName("com.tersesystems.jmxbuilder:type=UserBean,name=User"); mBeanServer.registerMBean(userBean, objectName); } } The code's available at https://github.com/tersesystems/jmxbuilder I wrote a blog post as well explaining the use case -- OpenMBean API restrictions, no need for annotations or interface/class creation, and being able build up CompositeData and TabularData so that more complex MBeans can be created. Blog post is here https://tersesystems.com/blog/2019/12/24/controlling-logging-in-a-running-jvm/ I've also got an MBeanServerInterceptor put together at https://github.com/tersesystems/jmxmvc although that's a lot more fiddly and I'm not sure I have the details worked out. I am probably going to work on automatic registration using using Guice and Sangria https://tavianator.com/announcing-sangria/ next, so anything implementing an interface can have a JMX bean created for it, without tying the interface directly to JMX implementation.