bea.com | products | dev2dev | support | askBEA
 Download Docs   Site Map   Glossary 
Search

Programming WebLogic Management Services with JMX

 Previous Next Contents Index View as PDF  

Accessing and Changing Configuration Information

WebLogic Server managed resources are configured from the values in Local Configuration MBeans, which are replicas of the Administration MBeans on the Administration Server.

If you want to programmatically view or change the configuration data for managed resources, you must first use the MBeanServer interface or the WebLogic Server type-safe interface to retrieve Local Configuration MBeans or Administration MBeans. Then you use APIs in the weblogic.management.configuration package to view or change the configuration data. For information about viewing the API documentation, refer to Documentation for Configuration MBean APIs.

Note: The values in the Local Configuration MBeans can differ from the Administration MBeans if you use a startup option to override the Administration MBean values, or if you use an API to change values in a Local Configuration MBean directly. For more information about the distribution of configuration data in a WebLogic Server domain, refer to WebLogic Server Managed Resources and MBeans.

This topic provides examples for programmatically retrieving and modifying the configuration of WebLogic Server resources using the weblogic.Admin utility, the JMX MBeanServer APIs, and the WebLogic Server type-safe interface:

 


Example: Using weblogic.Admin to Configure the Message Level for Standard Out

This example uses weblogic.Admin to find the WebLogicObjectName of the Local Configuration MBean instance of weblogic.management.configuration.ServerMBean. Then it sets the level of messages that a server instance named peach sends to standard out. Because it sets the value of a Local Configuration MBean, the updated value applies only to the current server session.

Listing 3-1 Configuring the Message Level

C:\myWLDomains\mydomain>java weblogic.Admin -url http://peach:8001 -username weblogic -password weblogic GET -pretty -type ServerConfig
---------------------------
MBeanName: "mydomain:Location=peach,Name=peach,Type=ServerConfig"
AcceptBacklog: 50
AdministrationPort: 0
...
        StdoutDebugEnabled: false
StdoutEnabled: true
StdoutFormat: standard
StdoutLogStack: true
StdoutSeverityLevel: 16
C:\myWLDomains\mydomain>java weblogic.Admin -url http://peach:8001 -username weblogic -password weblogic SET -mbean
mydomain:Location=peach,Name=peach,Type=ServerConfig
-property StdoutSeverityLevel 64
Ok

The weblogic.Admin utility returns the string Ok to indicate that the SET command succeeded.

 


Example: Using MBeanServer to Configure the Message Level for Standard Out

The class in this example uses the Local Configuration MBean instance of weblogic.management.configuration.ServerMBean to temporarily change the level of messages that a server instance named peach sends to standard out. It uses the standard JMX MBeanServer interface to change the ServerMBean configuration.

The class as written runs on the Administration Server and uses the Administration MBeanHome to retrieve the Local Configuration MBean for peach, but you could modify it to run on a local server and use the local server's MBeanHome to retrieve ServerMBean.

Instead of retrieving a list of all MBeans and then filtering the list to find the local ServerMBean for a specific server instance, this example uses the MBean naming conventions to construct the WebLogicObjectName for the ServerMBean. For more information about naming conventions, refer to WebLogicObjectNames for WebLogic Server MBeans.

In the example, weblogic is a user who has permission to view attributes of the ServerMBean. For information about permissions to view and modify MBeans, refer to "Protecting System Administration Operations" in the WebLogic Server Administration Guide.

Listing 3-2 Configuring EJB Deployment Descriptors

import java.util.Set;
import java.util.Iterator;
import java.rmi.RemoteException;
import javax.naming.*;
import javax.management.MBeanServer;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import weblogic.management.WebLogicObjectName;
public class changeStandardOut {
  public static void main(String[] args) {
    MBeanHome home = null;
MBeanServer homeServer = null;
   //domain variables
String url = "t3://localhost:7001";
String username = "weblogic";
String password = "weblogic";
//setting the initial context
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
//getting the Administration MBeanHome
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
} catch (Exception e) {
System.out.println("Exception caught: " + e);
}
// Constructing a WebLogicObjectName for the local ServerMBean
// that is associated with the server instance named peach.
String mbeanName = "examples:Location=peach,Name=peach,Type=ServerConfig";
WebLogicObjectName objName = new WebLogicObjectName(mbeanName);
// Retrieving the MBeanServer interface. 
homeServer = home.getMBeanServer();
// Using MBeanServer to set the value of the StdoutSeverityLevel attribute
homeServer.setAttribute(mbeanName,StdoutSeverityLevel,64);
//  Providing feedback that operation succeeded.
System.out.println("Changed standard out severity level to: " +
homeServer.getAttribute(mbeanName,StdoutSeverityLevel));
     } catch (Exception e) { 
System.out.println("Caught exception: " + e);
}
  }
}

 


Example: Using the Type-Safe Interface to Retrieve Information About a JMS Configuration

The example in this section collects all the JMS-related configuration information in a domain. To retrieve JMS-related Administration MBeans, it uses the getMBeansByType method of the Administration MBeanHome.

You could add more functionality to this program by using the get and set methods of the JMS-related Administration MBeans that the program retrieves.

Listing 3-3 Retrieving Information About a JMS Configuration

import java.util.Set;
import java.util.Iterator;
import java.rmi.RemoteException;
import javax.naming.*;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import javax.management.ObjectName;
import weblogic.management.WebLogicMBean;
import weblogic.management.configuration.ServerMBean;
import weblogic.management.runtime.ServerRuntimeMBean;
public class getJMSInfo {
  public static void main(String[] args) {
   MBeanHome home = null;
String url = "t3://localhost:7001";
String username = "weblogic";
String password = "weblogic";
WebLogicMBean bean = null;
//setting the initial context
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
System.out.println("got the IC");
//getting the Administration MBeanHome
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
System.out.println("Got the MBeanHome " + home);
} catch (Exception e) {
System.out.println("Exception caught: " + e);
}
/*Getting the Administration MBeans. The getMBeansByType method
* retrieves Administration MBeans because there is no "Config"
* or "Runtime" suffix in the value that is passed.
* For example, "JMSConnectionFactory" retrieves an Administration
* MBean, while "JMSConnectionFactoryConfig" retrieves a Configuration
* MBean.
Set myset = home.getMBeansByType("JMSConnectionFactory");
Iterator iter = myset.iterator();
System.out.println("Iterating over: ");
while(iter.hasNext()) {
bean = (WebLogicMBean) iter.next();
System.out.println("Got the server mbean: " + bean);
}
   myset = home.getMBeansByType("JMSServer");
iter = myset.iterator();
System.out.println("Iterating over: ");
while(iter.hasNext()) {
bean = (WebLogicMBean) iter.next();
System.out.println("Got the config mbean: " + bean);
}
   myset = home.getMBeansByType("JMSSessionPool");
iter = myset.iterator();
System.out.println("Iterating over: ");
while(iter.hasNext()) {
bean = (WebLogicMBean) iter.next();
System.out.println("Got the runtime mbean: " + bean);
}
   myset = home.getMBeansByType("JMSQueue");
iter = myset.iterator();
System.out.println("Iterating over: ");
while(iter.hasNext()) {
bean = (WebLogicMBean) iter.next();
System.out.println("Got the runtime mbean: " + bean);
}
   myset = home.getMBeansByType("JMSConnectionFactory");
iter = myset.iterator();
System.out.println("Iterating over: ");
while(iter.hasNext()) {
bean = (WebLogicMBean) iter.next();
System.out.println("Got the runtime mbean: " + bean);
}
   myset = home.getMBeansByType("JMSConnectionConsumer");
iter = myset.iterator();
System.out.println("Iterating over: ");
while(iter.hasNext()) {
bean = (WebLogicMBean) iter.next();
System.out.println("Got the runtime mbean: " + bean);
}
}
}

 

Back to Top Previous Next