WebLogic and JMX

September 23, 2004

I know I rarely use JMX, the Java Management Extensions (JMX) 1.0 specification that provide open and extensible management services. But there are instances when it's a great thing to have in your tool-belt, specially dealing with applications deployed in a WebLogic cluster in a distributed environment. As users of WebLogic know, WebLogic Server has implemented JMX 1.0 and added its own set of convenience methods and other extensions to facilitate working in the WebLogic Server.

The WebLogic JMX services expose the management attributes and operations of managed resources through one or more managed beans (MBeans). An MBean is really a concrete Java class that is developed per JMX specifications that provides getters and setters for each attribute. For more information, check out the WebLogic documentation for Programming WebLogic Management Services with JMX.

My usage of JMX is fairly limited and it's usually something simple like discovering all the names and addresses of managed servers in a cluster. For redundancy and fault tolerance, I will create caches of data at the individual server level (No, we don't use Coherence :) ) that need to be managed across the cluster. My typical pattern is to create a simple admin servlet that sits in each member of the cluster and interacts with the cache via the exposed destroy, reset, display, etc operations. Here's a snippet of code that allows you to discover members of a WebLogic cluster:

        try {
            Environment env = new Environment();
            env.setProviderUrl("t3://adminserver:port");
            env.setSecurityPrincipal("username");
            env.setSecurityCredentials("password");
            Context ctx = env.getInitialContext();
            home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
        } catch (NamingException e) {
            System.out.println("Exception caught: " + e);
            //do something useful here
            //         } 

            if (home != null) {
                System.out.println("Active Domain: " + home.getActiveDomain().getName());
            } 

            //getting the names of servers in the domain
            System.out.println("Active Servers: ");
            Set mbeanSet = home.getMBeansByType("ServerRuntime");
            Iterator mbeanIterator = mbeanSet.iterator();

            while (mbeanIterator.hasNext()) {
                ServerRuntimeMBean serverRuntime = (ServerRuntimeMBean) mbeanIterator.next();

                if (serverRuntime.getState().equals(ServerStates.RUNNING)) {

                    if (!serverRuntime.isAdminServer()) {
                        String[] serverName = serverRuntime.getListenAddress().split("/");
                        String serverURL = "http://" + serverName[1] + ":" + serverRuntime.getListenPort();
                        reloadCache(serverURL);
                    }
                }
            }

More information is at dev2dev.bea.com and Programming WebLogic Management Services with JMX.

Comments on this entry are closed.

Previous post: Hibernate in Action

Next post: Discover how XMLBeans is revolutionizing data binding


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser
Mobilytics