Hi All,

Jay SenSharma

Jay SenSharma

“weblogic.management.runtime.ServerRuntimeMBean” is a very useful MBean.. which provides us a methods for retrieving runtime information about a server instance and for transitioning a server from one state to another. This MBean inherits the “weblogic.management.runtime.ServerState”  interface, This interface defines the lifecycle states that a server can be in. For more details on ServerRuntimeMBean Please refer to:

ServerRuntimeMBean

Here is a Simple sample to get all the Server State in WLS JMX  8.1 style…

import java.util.*;
import java.util.Enumeration;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.management.ObjectName;
import weblogic.jndi.Environment;
import weblogic.management.*;
import weblogic.management.runtime.*;
import javax.management.*;

import weblogic.management.configuration.ServerMBean;
import weblogic.management.configuration.*;
import weblogic.management.configuration.DomainMBean;
import weblogic.management.configuration.ServerMBean;

public class ServerStatusChecker81
{
MBeanServer server = null; // MBeanServer
MBeanHome mbeanHome=null;
Hashtable inStart = new Hashtable();
public ServerStatusChecker81()
{
try {
Environment env = new Environment();
env.setProviderUrl("t3://localhost:7003");
env.setSecurityPrincipal("weblogic"); // username
env.setSecurityCredentials("weblogic"); // password
Context myCtx = env.getInitialContext();
mbeanHome =(MBeanHome)myCtx.lookup("weblogic.management.adminhome");
server = mbeanHome.getMBeanServer();
}
catch (Exception ex)
{
System.err.println("nntCannot get MBeanServer: "+ex);
}
}

public void getServerState(String type,MBeanHome home)
{
Set set=home.getMBeansByType(type);
Iterator it=set.iterator();
while(it.hasNext())
{
ServerRuntimeMBean  serverRuntime=(ServerRuntimeMBean)it.next();
System.out.println("ntNAME: "+serverRuntime.getName()+"tSTATE: "+serverRuntime.getState());
}
}

public static void main(String ar[]) throws Exception
{
ServerStatusChecker81 sm=new ServerStatusChecker81();
sm.getServerState("ServerRuntime",sm.mbeanHome);
}
}
OUTPUT:

F:Test81_JMX>java ServerStatusChecker81
************************************************************
SERVER ######    AdminServer    ######  STATE: RUNNING
************************************************************
SERVER ######    ms1    ######  STATE: RUNNING
************************************************************
SERVER ######    ms2    ######  STATE: RUNNING
—————————–

Thanks
Jay SenSharma
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.