JMX Web App Framework Elements
The main components in the JMX Web application framework are:
- JMXUtility: The utility class for defining the cluster MBeans instantiation and registration in the MbeanServer. The custom servlet context listener class calls the methods in this class to register MBeans when jmxapp Web application context is initialized.
- JMXMonitor: This class has methods to get MBean attribute details for the manageable server components. The jmx console script (jmxmonitor.jsp) calls these methods to get the details of JMX components.
- CustomDeltaManager: This is the custom session manager class created to access the session information. It provides the getter methods for session attributes to get the details of HTTP Session.
- CustomReplicationValve: This is the custom replication valve created to access the request filter details. It was created so the filter pattern (*.js, *.jpg, *.html, etc) can be viewed and modified dynamically using MBean methods.
- SimpleLoadBalancer: This class represents MBean for the load balancer used in the cluster Web application. SimpleLoadBalancer encapsulates the load-balancing algorithm, number of cluster members, their IP addresses, and port numbers.
- RuleBean: This is a java bean to store the load balancer rules used by Tomcat server to perform load balancing. It has the getters and setters to access and manipulate the load balancing algorithm rules.
- XMLUtility: A utility class to parse the load balancer rules XML file and populate the RuleBean. It uses Commons Digester package to simplify the XML processing to parse the load balancing details stored in rules.xml file and populate RuleBean object.
- ClusterJMXContextListener: This is the custom servlet context listener created to call the MBean instantiation methods (in JMXUtility) when Tomcat server is started.
- WebAppLogger: Implementation of Log4J for logging debug messages in the Web application.
|Figure 2. JMX Web Application Class Diagram: The diagram shows the relationship among the classes that administer Load Balancer and Clustering components and their relationship.|
shows the class diagram with the custom java classes created to administer Load Balancer and Clustering components and their relationship.
The sample project contains only two JSP files. JmxMonitor.jsp
is the main page for the Web application. It is used to check the status of the cluster components. JmxOutput.jsp
displays the MBean details for the cluster elements. There are HTML links for each component to view the MBean attributes using the HTML adapter.
You need the following three configuration files:
- server.xml configures clustering in a Tomcat server instance. The version that ships with the Tomcat installation has the cluster configuration commented out. You enable the cluster by uncommenting the <Cluster> XML element. You also specify the custom cluster classes in this configuration file.
- Web.xml specifies whether Web application session data needs to be replicated. You also use this file to configure the custom servlet context listener.
- rules.xml defines the custom load-balancing rules. This is the file where you specify which load-balancing rule you want to use to distribute the load among the cluster members.
You'll find one additional file called log4jconfig.properties
. This is the properties file created for Log4J configuration.
The sample code
provided with this article includes all the source files you need to run the Web application.
Web App Request Flow:
Here's the sequence of events for each Web request handled by the sample Web application:
- Launch the startup page (http://localhost:8080/jmxapp/jmxmonitor.jsp).
- JSP calls the methods in the JMXMonitor class to retrieve the MBeans details and forwards the request to jmxoutput.jsp.
|Figure 3. JMX Web Application Sequence Diagram: The figure shows a visual representation of the sequence of events in the sample Web application.|
- jmxoutput.jsp displays the MBean details for the elements in the Tomcat cluster. This page also has links to show more MBean information using the jmx-html HTML adapter.
- Click on the jmx-html view link to see the MBean attributes using the HTML adapter user interface.
- Open a new Web browser and launch the cluster application's main page (http://localhost:8080/balancer/testLB.jsp).
- Modify the session data by adding or changing a session attribute.
- Refresh the MBean details on the jmxoutput.jsp Web page and ensure that the session details have been updated to reflect the changes you made.
The sequence diagram in Figure 3
provides a visual representation of these steps.