Welcome!

Machine Learning Authors: Zakia Bouachraoui, Yeshim Deniz, Elizabeth White, Pat Romanski, Liz McMillan

Related Topics: Java IoT

Java IoT: Article

Integrating AJAX with the JMX Notification Framework

Opposite Ends of the Systems Management Stack

Each step is described in detail below.

Register MBeans and MBean Listeners
On each J2EE server instance, two start-up classes are run at server start-up:

  • ManagementStartup: Registers the UserWeb MBean in the local MBean server. Startup class parameters include default settings of the alert status, as well as the MBean name and MBean class. For example:

    <StartupClass
       Arguments="ServerName=admin,
         MBeanName=ExampleApp:Name=UserWeb,
         MBeanClass=com.grahamh.management.userWeb.UserWeb"
         ClassName="com.grahamh.management.startup.ManagementStartup"
       FailureIsFatal="true" Name="UserWEB" Notes=""
       Targets="admin,OLTPCluster"/>

  • MbeanRegistrations: Used to register a Singleton POJO, ManagementListener, with the UserWeb MBean on the administration server.

    A javax.management.NotificationFilterSupport object is used to list the notification types that the UserWeb MBean will generate and the listener will receive:

    // MbeanRegistrations.java
    MBeanHelperFactory.getWebHelper().registerListener();

    // UserWebMbeanListener.java
    public void registerListener() throws UserWebException{

    try {
    // get listener and filter
    ManagementListener listener = MBeanHelperFactory.getListener();
    NotificationFilterSupport filter = listener.getSupportedEvents();

    // get admin mbean server;
    //register the listener and filter with the UserWeb MBean
    RemoteMBeanServer rmbs = getAdminMbeanServer();
    rmbs.addNotificationListener
    ("ExampleApp:Name=UserWeb", listener, filter, null);
    }
    catch (Exception e) {
    throw new UserWebException
    ("Unable to registerListener: "+ e.getMessage(), e);
    }
    }

    The listener.getSupportedEvents() method returns the following filter:

    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType("alert.broadcast");

When ManagementListener is run at server start-up, a connection is made to the MBean server on the (remote) administration server and the (local) ManagementListener is registered as a listener on events generated by the UserWeb MBean, with a filter set to "alert.broadcast" event types.

Because the ManagementListener implements Weblogic.management.RemoteNotificationListener, it can get JMX notifications that are generated in either the local JVM or a remote JVM; in this case, generated in the remote administration server JVM.

Broadcast Admin MBean properties
The administration and managed UserWeb MBeans can be set independently, giving any one J2EE server a localized AJAX response. However, a general Operations, Administration & Support (OA&M) support pattern would set the admin MBean properties and then broadcast these properties to the MBeans on the remote application servers, using the Notification model, for subsequent AJAX retrieval.

Because the UserWeb MBean is based on ApplicationMBean, which extends javax.management.NotificationBroadcasterSupport, the infrastructure is in place for the UserWeb MBean to notify all listeners. Hence, the administrator sets the relevant MBean properties (using the HTMLAdaptor) and clicks BroadcastState (see Figure 2).

Consequently, the UserWeb.broadcastState()method is executed, which notifies all listeners synchronously with the state of the admin MBean:

public void broadcastState() throws Exception {
try {
Notification n = new Notification
("alert.broadcast", "ExampleApp:Name=UserWeb", 0);
n.setUserData(new UserWeb(this));
this.sendNotification(n);
}
catch (Exception e) {
throw e;
}
}

Because the data is serialized over the network, the non-transient object graph must be serializable.

Receive Notification of MBean Props via Listener
The event listener is the ManagementListener Singleton. The JMX Notification framework on the administration server makes a remote call to the ManagementListener handleNotification() method in each listener on each of the OLTP cluster JVMs, which registered on server start-up:

public void handleNotification(Notification notification, Object handback) {
System.out.println("Received alert: " + notification.getType());

// get event userdata from notification
Object userData = notification.getUserData();

if (userData instanceof UserWeb) {
// comes from destin8 Web
UserWeb WebVo = (UserWeb)userData;
UserWebMBeanHelper helper = MBeanHelperFactory.getWebHelper();

// get from value object and set into local MBean using
MBeanHelper
helper.setAlertMessage(WebVo.getAlertMessage());
helper.setAlertStatus(WebVo.getAlertStatus());
helper.setCallBack(WebVo.getCallBack());
helper.setRefreshAlertStatus(WebVo.getRefreshAlertStatus());
}
}

The 'master' UserWeb data is set into the local User-Web MBean via its MBean helper. Consequently each managed server is updated with the master UserWeb state.

That's as far as the JMX elements need to go.

AJAX Request of Management State
The browser client is AJAX-enabled as follows:

  • main.jsp - instrumented JSP page that checks the (JMX) alert status and polls the server for alerts. It includes admin.js
  • admin.js - JavaScript utilities that use XMLHttpRequest to poll the server for the management state, parse the XML response, and repaint the 'status' area of the screen
JavaScript (described below) is included in main.jsp as follows:

<script type="text/javascript" src="./js/admin.js" ></script>

Rather than poll continuously, we will only poll if alerting is enabled. We use the UserWebMBeanHelper to check this status. If enabled, the JavaScript function initAdmin() is invoked when the page loads:

<%
if (MBeanHelperFactory.getWebHelper().isAlertEnabled()) {
%>
<body bgcolor="#F4FFE4" onload="initAdmin();">
<%
} else {
%>
<body bgcolor="#F4FFE4">
<%
}
%>

More Stories By Graham P. Harrison

Previously a Senior Consultant with BEA, Graham is the author of Dynamic Web Programming using Java (Prentice Hall, 2000) in addition to a number of articles for the Java Developers Journal and IBM DeveloperWorks. He has a focus on Enterprise Architecture, Performance Tuning and Capacity Planning

Comments (7)

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.


CloudEXPO Stories
Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO 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 over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throughout enterprises of all sizes. We are offering early bird savings on all ticket types where you can save significant amount of money by purchasing your conference tickets today.
This is going to be a live demo on a production ready CICD pipeline which automate the deployment of application onto AWS ECS and Fargate. The same pipeline will automate deployment into various environment such as Test, UAT, and Prod. The pipeline will go through various stages such as source, build, test, approval, UAT stage, Prod stage. The demo will utilize only AWS services including AWS CodeCommit, Codebuild, code pipeline, Elastic container service (ECS), ECR, and Fargate.
SAP is the world leader in enterprise applications in terms of software and software-related service revenue. Based on market capitalization, we are the world's third largest independent software manufacturer. Harness the power of your data and accelerate trusted outcome-driven innovation by developing intelligent and live solutions for real-time decisions and actions on a single data copy. Support next-generation transactional and analytical processing with a broad set of advanced analytics - run securely across hybrid and multicloud environments.
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also received the prestigious Outstanding Technical Achievement Award three times - an accomplishment befitting only the most innovative thinkers. Shankar Kalyana is among the most respected strategists in the global technology industry. As CTO, with over 32 years of IT experience, Mr. Kalyana has architected, designed, developed, and implemented custom and packaged software solutions across a vast spectrum o...
Despite being the market leader, we recognized the need to transform and reinvent our business at Dynatrace, before someone else disrupted the market. Over the course of three years, we changed everything - our technology, our culture and our brand image. In this session we'll discuss how we navigated through our own innovator's dilemma, and share takeaways from our experience that you can apply to your own organization.