Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Exploring WebLogic JMX Part 2

Exploring WebLogic JMX Part 2

The Java Management Extensions (JMX) API provides a standard way of adding management capabilities to Java applications. BEA WebLogic 6.1 provides a full implementation of the JMX 1.0 specification, with all of its management features based on the JMX standard. As a result, the management capabilities in WLS are open and extensible, which makes it easy to build specialized management utilities for applications deployed on WLS.

In Part 1 of this series (WLDJ, Vol. 1, issue 4), we saw how JMX represents manageable resources as Managed Beans (MBeans), and provides a set of APIs for management applications to access those resources. In this article, we'll look at some of the details of how WebLogic Server 6.1 is instrumented using JMX, and how the JMX services offered by WebLogic can be used to monitor deployed applications. Using WLS JMX, we will gather runtime information from the application as it services client requests using the Java Pet Store example.

Before looking at the Pet Store example, though, we'll examine a few of the features of WebLogic JMX that simplify the creation of management applications.

Accessing MBeans in WebLogic Server
Management applications access the instrumented resources of a system to perform tasks such as monitoring or administration. These applications may take the form of graphical resource monitors, Web-based administration consoles, report-generating utilities, or other similar applications.

JMX allows the management interface of an application or resource to be exposed as a set of MBeans. These MBeans can then be accessed by management applications through the JMX agent level, whose main component is the MBeanServer.

WebLogic JMX is implemented in a way that simplifies the creation of management applications by making it easier to access MBeans and invoke methods on them. To gain access to MBeans, WebLogic JMX provides an MBeanHome - an augmentation of the standard MBeanServer that provides direct access to all the WebLogic Server predefined MBeans through a simplified API. The standard MBeanServer, by contrast, can provide only indirect access to the MBeans of the system. Access to MBeans is further simplified through WebLogic Server's use of JNDI and RMI in its JMX distribution level - providing direct access to the MBeans for both remote and local clients. Finally, all of the predefined WebLogic MBeans are implemented as standard MBeans (as opposed to dynamic and model MBeans, described in Part 1), which allows clients to make direct use of interfaces, instead of invoking MBean methods through reflection.

Together, these enhancements within the WebLogic Server JMX implementation simplify the creation of management applications that are specifically targeted for WebLogic Server. Applications that are meant to be portable to other application servers can still be written using the standard JMX APIs.

To observe the difference between the standard approach to accessing MBeans and the simplified approach using the WLS specific features, we'll look at two code samples, one that doesn't make use of these features and one that does. Listing 1 shows how to use standard JMX protocols to access MBeans in WebLogic Server. In particular, this example shows how to look at the "ServerRuntime" MBean, an MBean that is provided by WebLogic Server to supply overall information about the runtime system. After obtaining a reference to the MBeanServer, a JMX ObjectName instance is created using the full MBean name. The full name of this MBean is:

"petstore:Location=petstoreServer,Name=petstore Server,Type=ServerRuntime"

Before the colon, we see the domain name; additional attribute/value pairs identify the MBean from others deployed on that domain. Once the ObjectName is created, it is passed to the MBeanServer, along with the name of the method to be invoked on the bean. The method "getWeblogicVersion" is called through the "invoke" method defined on the MBeanServer, which uses reflection to call the corresponding method on the ServerRuntime MBean - the client never directly accesses the MBean itself.

In contrast, Listing 2 shows how this process works using the simplified WLS interfaces. In this case, a reference to the MBeanHome is obtained. From there, we can get a direct reference to the ServerRuntime MBean using a much simpler lookup name than the full ObjectName of the bean (we only need to supply the "Name" and "Type" - the MBeanHome is already aware of the domain and server that it's deployed on). The ServerRuntime MBean can be sent messages just like any regular Java object; there's no need to use the reflective "invoke" protocol required by the MBeanServer.

There are several advantages to the WebLogic approach to looking up and using MBeans. The code is simpler - using direct invocation rather than reflection makes the code easier to write and understand. Moreover, using the interfaces directly means that type checking can occur - many coding errors will be caught at compilation, while the "reflective" style is more prone to error.

In addition to providing an augmented and simplified API for accessing MBeans, WebLogic provides a large number of MBeans so that applications deployed on the server are "preinstrumented" and ready to be configured and monitored by management applications. Consequently, users of WebLogic JMX will generally find that they can create management applications based solely on the MBeans provided by WebLogic Server - only less frequently will users have to create their own MBeans to add additional instrumentation.

To get an appreciation of the amount of instrumentation that WLS provides with a deployed application, we can use MBeanHome to count the number of MBeans made available. Listing 3 shows how the MBeanHome can be queried for information about the MBeans available in the system. Running the code with the default "clean" domain (mydomain) and comparing this with the number of MBeans made available for the domain that has the Pet Store deployed in it shows that 577 MBeans are in the system for a clean WebLogic Server installation, but that 697 MBeans are in the system for the domain running the Pet Store. These 120 additional MBeans are beans used to configure the resources required by the Pet Store application (the JDBC connection pools, for example), and beans that can be used to monitor the state of the resources and components that make up the Pet Store.

Our main purpose is to show how these additional MBeans, created by WebLogic Server for deployed applications, can be used to carry out some simple runtime monitoring of the Pet Store. However, you may be wondering, "What are all these hundreds of MBeans in the default domain doing?"

WebLogic Server MBeans
Many of the MBeans that live within the server are there to provide an API for configuring the server itself. All of the configurable aspects of the WebLogic Server are represented as MBeans - from security, connection pools, and clustering, to the servers, and domains themselves. To get an idea of the scope of what can be configured, you only have to look at the WebLogic Administration Console. Virtually every element configurable through the console is also available through an MBean. Providing this layer means that all of the manual configuration that is normally done through the console can also be done programmatically, and that other utilities can provide the same functions as the console.

In addition to the configuration information represented as MBeans, a large amount of transient runtime data is also available in MBean form. This includes information about open servlet sessions, active JDBC connections, JTS transactions, pooled EJBs, JMS messages, and so on.

To provide access to this configuration and transient runtime data, WebLogic Server provides three types of MBeans: Administration, Configuration, and Runtime.

Administration and Configuration MBeans
Administration and Configuration MBeans represent the configuration data found in the config.xml file and accessible through the Administration Console. Administration MBeans represent this data in its persistent form - any changes to these MBeans will be saved to the config.xml file. Configuration MBeans represent this data in its active form; changes made to these beans will affect the running system, but won't be saved to the config.xml file. The distinction between Administration and Configuration MBeans gives management applications the option of making either temporary changes to the configuration of the running system (through the Configuration MBeans), or permanent changes (through the Administration MBeans).

Administration and Configuration MBeans implement the same interfaces - they're differentiated based on their ObjectName and in how they can be accessed. While Configuration MBeans are obtained from the MBeanHome as shown in Listing 2, Administration MBeans must be obtained from a distinct Administration MBeanHome. Each WebLogic Server instance has its own MBeanHome, while the Administration MBeanHome resides only on the administration server and is shared across a domain.

Runtime MBeans
Runtime MBeans provide information about the state of deployed components (EJBs, servlets, etc.), resources (JDBC connection pools, sockets, etc.), and the server.

The large numbers of MBeans in the "empty" domain can be attributed to the one Web application that is deployed to it - the Administration Console. The vast majority of the MBeans deployed in the "default" domain are actually MBeans associated with the Administration Console. Over 400 of the 577 MBeans that were counted in the default domain are associated with the console. These MBeans are runtime, administration, and configuration beans for the servlets and other components that make up the console, or additional MBeans created by the console to help it more easily administer the server.

Why Runtime Monitoring?
Many of the MBeans provided by WebLogic Server are involved with tracking the evolving runtime state of the system and the application and resource components that reside in it. This runtime information can be very useful for application developers and for those administering already deployed systems.

Building runtime monitoring into a system is difficult - it often takes the clumsy form of "System.out.println" statements scattered throughout the code. Sometimes the monitoring can interfere with the running code, and in some cases what needs to be monitored is inaccessible - information that is hidden within a resource that the application is accessing.

The runtime monitoring provided by WebLogic JMX provides a better alternative to putting monitoring code directly into an application - and since the monitoring is built into the application server, it can track resource-related state that may be difficult to access from within the application code.

Runtime MBeans allow monitoring facilities to be built around an already existing and deployed application - without taking down the server or affecting the application in any way.

As an example, in the next section we will show you how to obtain some runtime statistics about the transactional behavior of some of the components within the Java Pet Store.

Runtime Monitoring of the Java Pet Store
The Java Pet Store application is the canonical J2EE example application. The Pet Store uses EJBs, JSPs, JMS, and other Enterprise Java features, and is built using an application architecture based on the J2EE blueprints described by Sun. It's a classic "online shopping" application based around the well-known "shopping-cart" paradigm for tracking purchases as users browse through an online merchandise inventory.

A version of the Java Pet Store is provided with the WebLogic 6.1 installation - a fully configured domain for the Pet Store is found in the "config" folder under the WebLogic home directory. All of the discussion and examples here use this Pet Store example, unmodified. The Pet Store included in the WebLogic 6.1 install is slightly modified from Version 1.1.2 of Sun's Java Pet Store.

Transaction Monitoring Example
For our runtime-monitoring example using WebLogic JMX, our goal will be to find how many JTS transactions are committed, rolled back, or timed-out against the "Shopping Cart" component in a typical user interaction with the Pet Store. We'll do this with a small Java class CartTransactionTracker that connects to the running server remotely.

In an EJB-based application, transactional overhead can be a significant performance issue, so this kind of monitoring is quite relevant. By extending this example to the other components in the system, it's possible to detect the components that are the most "transaction intensive."

There are actually several ways to get information about the transaction load from WebLogic's JMX services. The method that we'll use involves looking at several Runtime MBeans that are associated with deployed EJB components.

Information about the transactions committed, rolled back, or timed out against the shopping cart EJB can be obtained from the EJBTransaction Runtime MBean associated with it. Each EJB deployed in WebLogic has the EJBTransactionRuntime MBean that carries this information.

To look up the EJBTransactionRuntime for a particular bean, there are, again, several methods. Every MBean in the system can be looked up directly based on its full name. However, WebLogic Server provides a more intuitive system, by which MBeans can be accessed from other MBeans related to them.

A good entry point to the MBeans associated with a particular EJB is provided by the EJBComponentRuntime. The EJBComponentRuntime of an ejb-jar is one way to access the MBeans for all the EJBs deployed in that archive. From EJBComponentRuntime, we obtain a reference to the MBean associated with the particular bean - an EJBRuntime. The EJBRuntime maintains a reference to the EJBTransactionRuntime, which (as previously mentioned) tracks transaction information for a particular EJB. The relationship between these Runtime MBeans is shown in Figure 1.

In our example we want to find out about the transactions associated with the Shopping Cart EJB. This bean, whose EJB name is "TheCart", consists of a bean-class, ShoppingCartEJB; a remote interface, ShoppingCart; and a home interface, ShoppingCartHome. It is deployed in the ejb-jar called "shoppingcartEJB.jar" within the "petstore.ear" enterprise archive.

To get to the EJBRuntime MBean associated with the Shopping Cart, we'll look up the EJBComponentRuntime for the "shopping cart.jar". WebLogic's naming convention for EJBComponentRuntime MBeans is straightforward - the ejb-jar name, followed by an underscore, followed by the EAR name; in this case, "shoppingcartEJB_petstore". Listing 4 shows the code required to obtain the MBean for this ejb-jar.

The shoppingcartEJB.jar file contains two EJBs - the Shopping Cart entity bean, and the Catalog session bean. To find the Shopping Cart, we can ask the EJBComponentRuntime MBean for all of its beans, and select the bean with the matching EJB Name. Listing 5 looks at the EJBRuntime MBeans returned from the EJBComponent Runtime for the MBean with the ejb-name "TheCart".

Finally, we can obtain information about the transactions from the EJBTransactionRuntime that is available from the EJBRuntimeMBean. Listing 6 briefly shows how this can be done.

Combining these steps - looking up the MBeans that represent the JAR, the individual EJB, and the transactions for the bean - yields a simple client that reports the transactional activity of the Shopping Cart EJB. Running this after single-user tests can provide some insight into bean behavior. Extending this across other EJBs in the system can reveal which components do the most transactional work, and can, in stress tests, detect points of failure.

Possible Extensions
What other information could we have obtained from the various EJB Runtime MBeans that we accessed in this example? Additional information includes caching, pooling, and locking data (all available on the bean type-specific subinterfaces of the EJBRuntimeMBean).

In this example, a simple remote client was used to log the results each time the client was run. Other implementation possibilities include:

  • Having the program implement the javax.management.NotificationListener interface, and publish Transaction data as it becomes available. WebLogic JMX supports both remote listeners and listeners running inside the server.
  • Using the various MBean monitors provided with JMX, we could set the logging options to record when the number of transactions rolled-back or timed-out reach certain threshold values.
  • Creating a new MBean that ties together the relevant monitoring information for the Pet Store application. This PetStoreRuntime MBean would access the other standard MBeans we discussed, but tie them together so that they are more specifically tailored for the particular application. The benefit of extending WebLogic Server Administration by adding new MBeans is that any generic JMX monitoring tool could then access this customized management interface. However, user-defined MBeans must be accessed through the MBeanServer, and not the WLS MBeanHome.

Other possibilities include extending the monitoring to cover servlet runtime behavior and JDBC connection pools.

Many enterprise-critical applications have been deployed on the J2EE platform - a key requirement of such applications is the availability of flexible and useful management utilities.

WebLogic 6.1 and its JMX-based administration facilities provide several enhancements over the standard JMX API that make it easy to build simple management applications while still allowing users to create standard applications that can run against any JMX implementation. These can be used to monitor existing applications without affecting the application code, and can be particularly helpful in locating problem areas or generating data to help in performance tuning.

In addition to providing enhancements to the JMX distribution and access levels, WebLogic JMX provides a full instrumentation of the WebLogic Server. Administration, configuration, and runtime data can be easily accessed through simple applications running inside or outside the server.

Finally, WebLogic's management capabilities are extensible, which means that any custom interfaces built using JMX can be accessed by JMX-compliant management applications.

By taking advantage of the APIs and MBeans provided by WebLogic Server, developers can create applications that are easier to monitor and administer, and can also create sophisticated management tools for those applications.


More Stories By Dan MacKinnon

About 7 years ago I wrote these two articles for the now defunct "WebLogic Developers Journal." They have now shown up on 'ulitzer'. They are now horribly out of date - please ignore them! :) Thanks, -- Dan

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@ThingsExpo Stories
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
"Digital transformation - what we knew about it in the past has been redefined. Automation is going to play such a huge role in that because the culture, the technology, and the business operations are being shifted now," stated Brian Boeggeman, VP of Alliances & Partnerships at Ayehu, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...