Hi,

Jay SenSharma

Jay SenSharma

Here is a Simple code on JMX …How to utilize the DomainConfigurationMBean . In this simple sample we are going to fetch the Remote Server Start Arguments  (Which we configure in the AdminConsole: Home —>Summary of Servers —>MS1—>Configurations(Tab)—>ServerStart(Tab)—->Argument(TextField) ) . This Value of JVM Argument and Classpath is Picked by the Server when we start it using Nodemanager (generally we call it as Remote Start)…If we are starting our Servers using StartScripts like (startWebLogic.sh/startManagedWebLogic.cmd) then these values we need to define in the StartScript …and not in the Admin Console.

In this case we get the Following entry in our “config.xml” file:

<server>
<name>MS1</name>
<machine>Machine-A</machine>
<listen-port>7003</listen-port>
<cluster>Cluster-A</cluster>
<web-server>
<web-server-log>
<number-of-files-limited>false</number-of-files-limited>
</web-server-log>
</web-server>
<listen-address></listen-address>
<server-start>
<class-path>C:AAA;%classpath%</class-path>
<arguments>-Xmx1024m -Xss512k -Xms1024m</arguments>
<password-encrypted></password-encrypted>
</server-start>
<jta-migratable-target>
<user-preferred-server>MS1</user-preferred-server>
<cluster>Cluster-A</cluster>
</jta-migratable-target>
</server>
<server>

Code is Simple “DomainConfigurationMBeanTest.java

import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean;
import weblogic.management.runtime.ServerRuntimeMBean;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import weblogic.management.jmx.MBeanServerInvocationHandler;
import java.util.Hashtable;
import java.io.IOException;
import java.net.MalformedURLException;
import weblogic.management.runtime.JDBCDataSourceRuntimeMBean;
import javax.management.*;
import javax.naming.*;

public class DomainConfigurationMBeanTest
{
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static final ObjectName service;
private static String combea = "com.bea:Name=";
private static String service1 = "DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
private static String service2 = "RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean";
static
{
try
{
service =new ObjectName(combea + service1);
} catch (MalformedObjectNameException e) {
throw new AssertionError(e.getMessage());
}
}

public static void initConnection(String hostname,String portString,String username,String password) throws IOException,MalformedURLException
{
String protocol = "t3";
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.domainruntime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection();
}

public static ObjectName[] getServerRuntimes() throws Exception
{
return (ObjectName[]) connection.getAttribute(service,"ServerRuntimes");
}

public void printNameAndState() throws Exception
{
ObjectName[] serverRT = getServerRuntimes();
System.out.println("got server runtimes");
int length = (int) serverRT.length;
ObjectName domain = (ObjectName) connection.getAttribute(service,"DomainConfiguration");
System.out.println("Domain: " + domain.toString());
ObjectName[] servers = (ObjectName[]) connection.getAttribute(domain,"Servers");
for (ObjectName server : servers)
{
System.out.println("nt---------------------------------------");
String aName = (String) connection.getAttribute(server,"Name");
System.out.println("Server Name: " + aName.toString());

ObjectName serverName=new ObjectName("com.bea:Name="+aName+",Type=Server");

ObjectName serverStart = (ObjectName) connection.getAttribute(serverName,"ServerStart");

String arguments = (String) connection.getAttribute(serverStart,"Arguments");
System.out.println("JVM ServerStart Arguments: " + arguments);
}
}

public static void main(String[] args) throws Exception
{
String hostname = args[0];
String portString = args[1];
String username = args[2];
String password = args[3];
DomainConfigurationMBeanTest s = new DomainConfigurationMBeanTest();
initConnection(hostname, portString, username, password);
s.printNameAndState();
connector.close();
}
}

OUTPUT:

C:DELETE>java DomainConfigurationMBeanTest localhost 7001 weblogic weblogic
got server runtimes
Domain: com.bea:Name=7001_Domain,Location=7001_Domain,Type=Domain

—————————————
Server Name: AdminServer
JVM ServerStart Arguments: null

—————————————
Server Name: MS1
JVM ServerStart Arguments: -Xmx1024m -Xss512k -Xms1024m

—————————————
Server Name: MS2
JVM ServerStart Arguments: null

Thanks

Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.