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

Related Topics: Weblogic

Weblogic: Article

Application Management with WebLogic Server for Developers, part 4

The Basics of Writing Custom Java Applications using JMX

  • For the previous four parts of this series, and the sixth and final part, please see links at foot of article

    This article is the fourth in a series of articles on BEA WebLogic Server administration and management for developers (WLDJ, Vol. 2, issues 10–12). The first installment focused on administration concepts and terminology, and the graphical tools for packaging an application and setting up and configuring a WebLogic Server domain.

    In the second article, we focused on application deployment, runtime management, and the monitoring facilities available with WebLogic Server that did not require knowledge of JMX. The last article discussed the basic concepts and terminology of JMX and the WebLogic Server 8.1 JMX infrastructure, as well as showing you how to use JMX-specific tools that come with WebLogic Server 8.1.

    In this article, we'll show you the basics of how to write custom Java applications that use JMX to configure, administer, and manage BEA WebLogic Server 8.1–based applications.

    JMX Programming Fundamentals
    When writing a Java application that uses BEA WebLogic Server's JMX capabilities, the first thing you need to do is decide whether to use the standard JMX MBeanServer interface or WebLogic Server's strongly typed interface. As we discussed in our last article, the MBeanServer interface allows you to write Java applications that manage any JMX-compliant application through its weakly typed, Java reflection–style interface. While this interface is perfect for tool vendors that want to work with a wide variety of applications and discover functionality at runtime, it can be more tedious to write and debug when the JMX program is intended to manage a well-known JMX-compliant application. BEA WebLogic Server 8.1 provides a strongly typed interface that is simpler to use and provides better compile-time checking of your code.

    Using the MBeanServer Interface
    The basic steps to writing a JMX program that uses the MBeanServer interface are:

    • Obtain a reference to the MBeanServer implementation
    • Determine the MBean(s) of interest
    • Determine the MBean's attributes and/or operations of interest
    • Invoke the appropriate methods on the MBeanServer to perform the action
    When writing a JMX application for managing BEA WebLogic Server, the easiest way to obtain a reference to the MBeanServer implementation is to look it up from the admin server's JNDI tree using the JNDI name weblogic.management.server. Administration MBeans are accessible through the admin server's MBeanServer. All configuration changes for a domain must be made through the admin server's MBeanServer.

    Managed servers also have their own MBeanServer. Through these MBeanServers you can access local configuration and runtime MBeans. Currently, the MBeanServers on the managed servers are only accessible through the WebLogic-specific MBeanHome interface discussed in the next section.

    BEA WebLogic Server's MBeanServer supports transparent remote access capabilities through the normal WebLogic RMI mechanisms so your JMX program does not need to concern itself with whether the MBeanServer is in the local or remote process. If you intend to change MBean attributes or invoke operations that modify the domain, you will need to authenticate your application to WebLogic Server with sufficient permissions to do so. Although the JNDI authentication mechanism is deprecated in favor of JAAS-style authentication, we show the older authentication mechanism for brevity (see Listing 1)

    To get information about an MBean, you first need to know its object name. JMX uses the javax.management.ObjectName class to represent an MBean's object name. If you don't know what MBeans are available, use one of the MBeanServer's query methods to get a list of the matching MBeans. For example, use the queryNames() method with null arguments to return a java.util.Set containing the ObjectName objects for all registered MBeans, as shown here:

    Set mbeansSet = mbeanServer.queryNames(null, null);
    Iterator mbeans = mbeansSet.iterator();
    while (mbeans.hasNext()) {
    ObjectName mbeanName = (ObjectName)mbeans.next();

    Once you determine the object name for the MBean of interest, you get detailed information about the MBean's attributes and operations by using the MBeanServer's getMBeanInfo() method (see Listing 2).

    Finally, you invoke the appropriate method on the MBeanServer to get or set the attribute or to invoke the operation (see Listing 3).

    If you know the target JMX application you want to manage, the relevant MBean object names and their attributes and operations of interest, it is possible to make the JMX programming more straightforward if you are willing to give up some of the flexibility. Listing 4 shows a simple JMX program to get the default execute queue's configured number of threads for the domain's admin server.

    Notice that we use the fact that there is an MBean of type AdminServer in the default domain to get the domain name and the server name from the related MBeans. With BEA WebLogic Server 8.1, the default domain name is always weblogic so we could have skipped calling getDefaultDomain() and simply used weblogic as the domain name (or omitted it entirely since it is the default) when creating the object name for the admin server MBean.

    Using the Strongly Typed WebLogic JMX Interface
    BEA WebLogic Server 8.1 also provides an MBeanHome interface that gives you access to the strongly typed interface. You obtain references to a server's MBeanHome implementation by looking it up in JNDI. As was the case with the MBeanServers, administrative MBeans must be accessed through the admin server's special MBeanHome, known as the Administration MBeanHome. To obtain a reference to the Administration MBeanHome implementation, do a JNDI lookup on the admin server using the JNDI name weblogic.management.adminhome. This JNDI name is defined as the ADMIN_JNDI_NAME constant on the MBeanHome interface to help insulate your program from any further JNDI changes.

    All servers, including the admin server, also have local MBeanHome implementations that provide access to local configuration and runtime MBeans. These local MBeanHome implementations are accessible by performing a JNDI lookup directly against the server of interest using the JNDI names weblogic.management.home.localhome or weblogic.management.home.<server_name>, where <server_name> is the name of the WebLogic Server instance. The MBeanHome interface defines two additional constants, LOCAL_JNDI_NAME and JNDI_NAME, that you should use in place of weblogic.management.home.localhome and weblogic.management.home, respectively. The admin server also has references to all managed servers' local MBeanHome implementations through the weblogic.management.home.<server_name> JNDI names.

    To get a reference to the Administration MBeanHome, use code that looks very similar to the code shown to obtain the MBeanServer:

    MBeanHome mbeanHome = null;
    try {
    ... // Same as earlier example

    mbeanHome =(MBeanHome)
    catch (NamingException ne) { ... }

    The MBeanHome interface provides a wide variety of methods to create MBeans and get different types of MBeans. For example, the getAllMBeans() methods return the type-safe stubs for all MBeans in the specified domain, for which you could then use Java reflection to determine the set of attributes and operations each MBean supports. Of course, you typically choose to use the strongly typed interface because you already know the types of MBeans that you need to manipulate. The getAdminMBean() methods allow you to get a type-safe reference to an administration MBean:

    String domainName = mbeanHome.getDomainName();
    ServerMBean myserver = (ServerMBean)
    mbeanHome.getAdminMBean("myserver", "Server", domainName);

    Once you have the type-safe reference, you can access the attributes and operation directly:

    int listenPort = myserver.getListenPort();

    Listing 5 shows the strongly typed interface version of the same program contained in Listing 4. Notice that we are using the getAdminMbean(name, type, domain) method to locate the MBean references of interest. This interface tends to be much simpler than the JMX standard interface where we had to use ObjectName representations of the MBean's object name. However, it is still a little confusing when you need to supply more than the Name and Type attributes to uniquely identity the MBean because you have to tack on the extra attribute name-value pairs, delimited by commas, to the value of the name attribute. For example, the following code snippet from Listing 5 shows the form of the name argument where we also have to specify the Server attribute to uniquely locate the ExecuteQueueMBean of interest:

    String defaultExecuteQueueName =
    "weblogic.kernel.Default,Server=" + adminServerName;
    ExecuteQueueMBean defaultExecuteQueueMBean = (ExecuteQueueMBean)
    "ExecuteQueue", domainName);

    We hope you can see that the type-safe version of the program is simpler and provides better compile-time checking. If you need to write JMX programs to automate the management of your BEA WebLogic Server–based applications, we recommend using the type-safe interface in most circumstances. If you are building JMX management tools to work with a variety of JMX-compliant application, then using the JMX MBeanServer interface will make your job easier.

    In this article, we showed you the basics of the two different JMX programming interfaces that are available to build JMX management programs for BEA WebLogic Server 8.1. The JMX standard MBeanServer interface provides a loosely typed, reflection-style interface that allows tool vendors to write tools that discover MBeans and their attributes and operations at runtime. The strongly typed WebLogic JMX MBeanHome interface provides a simpler interface for building JMX management programs to perform predefined tasks with a WebLogic Server–based application.

    The next article in this series will dive into the more advanced Java APIs for building custom JMX programs that use JMX notification with monitors and timers. Our final installment will discuss creating custom MBeans and extending the Admin Console to display them.

  • More Stories By Vadim Rosenberg

    Vadim Rosenberg is the product marketing manager for BEA WebLogic Server. Before joining BEA two years ago, Vadim had spent 13 years in business software engineering, most recently at Compaq Computers (Tandem Division) developing a fault-tolerant and highly scalable J2EE framework.

    More Stories By Robert Patrick

    Robert Patrick is a director of technology in BEA's CTO Office and coauthor of the book Mastering BEA WebLogic Server: Best Practices for Building and Deploying J2EE Applications.  Robert has spent his career helping customers design, build, and deploy high performance, fault-tolerant, mission-critical distributed systems using BEA Tuxedo and BEA WebLogic Server.

    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.

    IoT & Smart Cities Stories
    All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
    Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
    Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
    DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
    The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
    CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
    Cell networks have the advantage of long-range communications, reaching an estimated 90% of the world. But cell networks such as 2G, 3G and LTE consume lots of power and were designed for connecting people. They are not optimized for low- or battery-powered devices or for IoT applications with infrequently transmitted data. Cell IoT modules that support narrow-band IoT and 4G cell networks will enable cell connectivity, device management, and app enablement for low-power wide-area network IoT. B...
    The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
    SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
    When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...