Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API
J2SE 5.0's monitoring and management support is comprehensive, with remote monitoring capabilities for the Java platform and for applications that run on it. Included in J2SE 5.0 is Java Management Extensions (JMX) remote monitoring, a new addition to the list of monitoring capabilities on a JVM. Java Specification Request 160 is the specification for JMX remote monitoring. It focuses on the mechanism for remote access by building a remote client API for a JMX-based agent.
Tomcat 5.5 is designed to leverage J2SE 5.0's built-in JMX capabilities. Version 5.5 (which was branched based on Tomcat 5.0.27) implements the latest Servlet (2.4) and JavaServer Pages (2.0) specifications and is the result of an extensive redesign and refactoring of the Tomcat server architecture. It proves more stable and improves upon Tomcat 4.x with enhanced performance, scalability and reliability, JMX monitoring, integrated session clustering, and application deployment.
With the latest version of Tomcat and J2SE 5.0's JMX capabilities, we can make the servlet container's attributes and methods available via JMX while simultaneously reducing the complexity of JMX-related code. In this article, I discuss how to launch the Tomcat servlet container with remote JMX monitoring enabled. We also look at a sample Web application that runs in a Tomcat cluster with session replication turned on. And, finally, we use a JMX client to view the details of cluster elements and HTTP sessions. But before we delve into the discussion of remote JMX monitoring, let's look at the components that make up a Tomcat cluster.
A Tomcat cluster consists of six main components: cluster, membership, sender, receiver, replication valve, and deployer.
Table 1 shows how each component makes the clustering and session replication work in Tomcat.
Table 1. Tomcat cluster elements
|
Fore more details on the clustering elements, refer to Tomcat 5.5's clustering documentation.
Tomcat 5.5 provides several improvements over its predecessors (Tomcat versions 4.1 and 5.0) in terms of clustering, session replication, and server monitoring and manageability. In Tomcat 4, several server components (such as host, engine, and service) could be monitored using MBeans (managed beans). But in Tomcat 5.5, Yoav Shapira, Filip Hanik, and the other Tomcat developers wrote JMX implementations for the cluster elements.
Now that we know the function of each element in a Tomcat cluster, let's look at various JMX client tools used for connecting to a Tomcat server cluster and monitoring the cluster details.
A JMX client is a graphical user interface (client/server or thin client) used to connect to a JMX agent (running on a local or remote machine). An ideal JMX client should have the following features to monitor an application server effectively without incurring any additional overhead:
J2SE 5.0 comes with a JMX client tool called JConsole that can be used to look into the runtime JVM details. Tomcat installation
includes a JMX servlet called JMXProxyServlet that can view and update Tomcat MBean attributes. It is a lightweight proxy for viewing and manipulating the MBeans running
in a Tomcat container and proves helpful in integrating command line scripts for monitoring and changing Tomcat internals.
JMX Query and Set commands can be used to query the MBeans and modify their attributes and operations respectively.
Other than these two tools, several third-party open source JMX client applications are available (links to which are available in Resources):
In this article, I discuss how to install and configure MC4J to remotely connect to a Tomcat servlet container and monitor all the MBean components in a server cluster.
The MC4J console provides the following capabilities:
I used MC4J 1.2 Beta 9 for this article's sample application. To install MC4J, download the executable (MC4J-12b9-Windows.exe) from SourceForge. Double-click on the exe file and select JDK Home and the MC4J installation directory (c:\dev\tools in the sample setup) when prompted during the installation process.
You must specify some system properties to see the remote JMX monitoring in action. These properties are specified in a properties
file called management.properties located in the JAVA_HOME/lib/management directory. Table 2 shows the properties that must be set for JMX monitoring.
Table 2. System properties to enable JMX monitoring
|
Setting the password file is very important especially in a multi-user environment. I set up the password file in the JAVA_HOME/lib/management directory as follows:
jmxremote.password.template) into a file called jmxremote.passwordmonitorRole and controlRoleI installed Tomcat 5.5.9 to set up the Tomcat cluster. The server cluster used in this article includes two Tomcat instances
sharing the session state and a load balancer to distribute the requests between the server nodes. I used SimpleTcpCluster and DeltaManager (which are default options) in the cluster configuration. I explain the cluster setup in more detail in my series "Clustering and Load Balancing in Tomcat" (ONJava.com, 2004).
To enable remote JMX monitoring when starting Tomcat server, modify the Tomcat startup script (catalina.bat or catalina.sh) located in the CATALINA_HOME/bin directory as shown below:
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=8999
Note: You must use a different port for the jmxremote port option on the second Tomcat instance (9999).
Figure 1 shows the cluster topology details.
Figure 1. Tomcat cluster architecture diagram. Click on thumbnail to view full-sized image.
Table 3 lists various configuration parameters used in setting up the Tomcat cluster.
Table 3. Cluster configuration details
|
Before we dive into the details of Tomcat monitoring using MC4J, let's briefly discuss a sample Java application that connects to a remote JMX agent (in this case, a Tomcat servlet container) using the remote JMX API. Begin by starting Tomcat with JMX monitoring enabled.
The sample JMX remote client is called RemoteJMXClient, which is basically a standalone Java application that acts as a JMX connector. This Java class is located in the sample
Web application's src\com\remotejmx\client directory. Add the jmx-remote.jar and jmxri.jar files in the classpath when running the Java application. The following steps explain how to remotely connect to the JMX
server:
JMXServiceURL with the protocol, host name, remote JMX port number, and credentials HashMap (with username and password): JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi");
Map map = new HashMap();
String[] credentials = new String[] { "monitorRole" , "QED" };
map.put("jmx.remote.credentials", credentials);
JMXConnector using the URL and credentials HashMap defined in Step 1. Once you obtain a reference to the JMX connector, call the getConnectionId() method to ensure you have a valid connection ID: JMXConnector conn = JMXConnectorFactory.connect(url, map);
System.out.println("JMXConnector="+conn.toString());
String id = conn.getConnectionId();
System.out.println("Connection Id=" + id);
MBeanServerConnection from the JMXConnector object: mbsc = conn.getMBeanServerConnection();
String domains[] = mbsc.getDomains();
System.out.println("# of domains="+domains.length);
for (int i = 0; i < domains.length; i++) {
System.out.println("Domain[" + i + "] = " + domains[i]);
}
MBeanServerConnection object, call the MBeans-related methods just as you would call on an MBeanServer if connected to the JMX server locally (within the same JVM). You can check the number of domains and their types in the
JMX server. You can also get the number of MBeans registered in the server and their attributes and operations. The code snippet
below shows these steps: mbsc = conn.getMBeanServerConnection();
String domains[] = mbsc.getDomains();
System.out.println("# of domains="+domains.length);
for (int i = 0; i < domains.length; i++) {
System.out.println("Domain[" + i + "] = " + domains[i]);
}
// Get MBean count
Integer mbeanCount = mbsc.getMBeanCount();
System.out.println("mbeanCount : " + mbeanCount.intValue());
Cluster's object type, as shown in the code below. We look at the same cluster details using MC4J in the following section. Set mBeanSet = mbsc.queryMBeans(null, null);
System.out.println("mBeanSet.size() : " + mBeanSet.size());
Iterator mBeanSetIterator = mBeanSet.iterator();
while (mBeanSetIterator.hasNext()) {
ObjectInstance objectInstance = (ObjectInstance)mBeanSetIterator.next();
ObjectName objectName = objectInstance.getObjectName();
String canonicalName = objectName.getCanonicalName();
System.out.println("canonicalName : " + canonicalName);
if (canonicalName.equals("Catalina:host=localhost,type=Cluster"))
{
// Get details of cluster MBean
System.out.println("Cluster MBean Details:");
System.out.println("=========================================");
getMBeanDetails(canonicalName);
}
String canonicalKeyPropList = objectName.getCanonicalKeyPropertyListString();
}
conn.close();
This section explains the sample Web application used to test the failover and session replication in the Tomcat cluster. I deployed the Web application on both cluster nodes and wrote a test client program to run a load test by creating and modifying HTTP sessions in the servlet container.
The following steps get the server cluster and load balancer up and running:
I used the following command to start the load balancer using the round-robin load balancing option:
pen -r -a -f -d localhost:8080 192.168.0.10:9080 192.168.0.20:10080
where
Figure 2 Screenshot of MC4J console window. Click on thumbnail to view full-sized image.
After starting the console, create a new connection to bind to the JMX server. Create a new connection called Tomcat-5.5.9-instance1 using the Create Server Connection option from the Management menu. Use the settings shown in Table 4 for Tomcat connection.
Table 4. MC4J Tomcat connection settings
|
Note: You need the catalina.jar, catalina-cluster.jar, and catalina-optional.jar files (located in %CATALINA_HOME%\server\lib\) specified in the classPathEntries property.
Once we have the Tomcat servers running with remote JMX enabled and have configured MC4J to connect to the servers, we need to run the test Java client and log the session details using Log4J. In the following section, we look at the instrumentation layer details and test the client runtime parameters.
| Subject | Replies |
Last post
|
|
By cooltonesa2 |
2 |
05/09/08 03:22 PM
by Anonymous |
|
By cooltonesa2 |
2 |
05/09/08 03:22 PM
by Anonymous |
|
By cooltonesa2 |
1 |
05/09/08 03:21 PM
by Anonymous |
|
By cooltunesi1 |
1 |
05/09/08 02:25 PM
by Anonymous |
|
By ( 1 2 all )
|
20 |
04/22/08 06:02 AM
by Anonymous |
|
By JavaWorld
( 1 2 all )
|
37 |
04/22/08 06:02 AM
by Anonymous |
|
By analkiana |
0 |
04/22/08 06:02 AM
by Anonymous |
|
By asdkjhuewr32 |
0 |
04/21/08 06:36 AM
by Anonymous |
|
By asdkjhuewr23 |
0 |
04/17/08 07:11 AM
by Anonymous |
|
By asdkjhuewr23 |
0 |
04/17/08 06:28 AM
by Anonymous |
|
By asdkjhuewr23 |
0 |
04/17/08 05:42 AM
by Anonymous |
|
By asdkjhuewr23 |
0 |
04/17/08 04:57 AM
by Anonymous |
|
By abramoviesi |
0 |
04/13/08 04:23 PM
by Anonymous |
|
By abramoviesi |
0 |
04/13/08 03:43 PM
by Anonymous |
|
By abramoviesi |
0 |
04/13/08 03:03 PM
by Anonymous |
|
By cooltonesa3 |
0 |
04/13/08 10:31 AM
by Anonymous |
|
By cooltonesa3 |
0 |
04/13/08 09:43 AM
by Anonymous |
|
By cooltonesa3 |
0 |
04/12/08 12:01 PM
by Anonymous |
|
By mypicst |
0 |
04/12/08 09:24 AM
by Anonymous |
|
By Memmorium |
0 |
04/11/08 11:55 AM
by Anonymous |
Free Download - 5 Minute Product Review. When slow equals Off: Manage the complexity of Web applications - Symphoniq
![]()
Free Download - 5 Minute Product Review. Realize the benefits of real user monitoring in less than an hour. - Symphoniq