Skip to main content

Day 16: Creating JMX MBeans in AEM



AEM Developer Series

Java Management Extensions (JMX) is a Java technology that provides an architecture to manage resources dynamically at runtime. JMX is used mostly in enterprise applications to make the system configurable or to get the state of the application at any point in time. Those resources are represented by objects called MBeans (for Managed Bean).

In AEM also, sometimes we need to use this architecture to manage resources dynamically. Although AEM provides a rich set of out of the box MBeans, we also create our own MBeans as and when required.

In this post, we will be creating an MBean that will take a set of input parameters and return the status of all the bundles/services/components in the AEM instance in a JSON format.

Let us look at the steps of creating such an MBean.

Create an MBean

  • The first step is to create the layout of our MBean. By layout, I mean the input parameters that the MBean requires to function.
  • All the parameters are specified by the specified parameters. In our case, we need the server's hostname, port number and the entity which we want to examine (bundles/services/components).
  • Create an interface named SystemInfo and paste the following code in it
  • Here we have three methods that take host, port and protocol and gives us the JSON response of the bundles, services and components
  • Now let us create the implementation class of the SystemInfo interface and paste the following code in it
  • Here we are registering this class of service DynamicMBean which exposes a dynamic management interface. We are using property jmx.objectname which defines the name of our MBean. We are reading the passed parameters and creating an appropriate URL to get the JSON response.
  • Now deploy the code and navigate to http://<host>:<port>/system/console/jmx. There you will see all the registered MBean. Search for your MBean.
System Info MBean
  • Open the MBean, you will see three methods each for bundles, components and services.
  • Open the getBundles() methods, and configure it. After clicking on invoke, you will see the JSON response returned.
JSON Response returned

Conclusion

Congratulations!! 🙋 today we have worked with MBeans and their configurations. I hope you enjoyed this post.

You can find the complete code of this project on my GitHub in this commit. Feel free to fork or open issues, if any.

I would love to hear your thoughts on this and would like to have suggestions from you to make it better. 

Feel free to befriend me on FacebookTwitter or Linked In or say Hi by email.

Happy Coding 😊

Comments

  1. In conclusion error
    "Congratulations!! Today we have worked with Clientlibs and their basic structures and properties. I hope you enjoyed this post."

    ReplyDelete
    Replies
    1. My bad. Long hours of work lead to careless copy pasting. Fixed it. Thanks for pointing that out.

      Delete

Post a Comment

Popular posts from this blog

Day 00: AEM Developer Series

Hello everyone! Welcome to this AEM development series. We can all see the revolution of Digital Marketing today. Companies are dying to be a part of it and they have made this a war for the Digital Marketing tools.
Adobe is way ahead in this war and has gained a lot of market capture. They are leaders in the Digital Marketing platforms since 2014-15. One of the flagship product in Adobe's Digital Marketing suite is Adobe Experience Manager (AEM).
Since AEM is in huge demand, the people who know how to develop on AEM are also in huge demand. But developing on AEM is not easy as it is made up of various open-source technologies such as Apache Felix (OSGi), Apache Sling, Apache Oak and Adobe's own technologies like Granite, HTL etc. Learning all these technologies in conjunction can sometimes become confusing and frustrating 😫.
When I first started learning AEM in 2016, I was dumbfounded to see there is so much going on under the hood. I then spent months to gather all the res…

Day 01: Introduction to AEM

Day 04: Developing first OSGi bundle