![]() |
![]() |
e-docs > WebLogic Server > Programming WebLogic Management Services with JMX > Accessing and Changing Configuration Information |
Programming WebLogic Management Services with JMX
|
Accessing and Changing Configuration Information
Configuration MBeans on the Administration Server (Administration MBeans) configure the managed resources on all WebLogic Server instances in a domain. To enhance performance, each server instance creates and uses local replicas of the Administration MBeans. These local replicas are called Local Configuration MBeans.
Note: While you can view the values of Local Configuration MBeans, BEA recommends that you do not change attribute values in Local Configuration MBeans. Instead, change only the values of Administration MBean attributes. When the Managed Server replicates the domain's configuration data, it uses the values that are stored in Administration MBeans. Communication problems can occur if the values in Administration MBeans and Local Configuration MBeans differ.
The following sections provide examples for programmatically viewing 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 View the Message Level for Standard Out
This example uses the weblogic.Admin utility to connect directly to a Managed Server and look up the value of its StdoutSeverityLevel attribute. This attribute, which belongs to the server's ServerMBean, specifies a threshold for determining which severity-level of messages a server prints to its standard out.
While BEA recommends that you use only Administration MBeans to change values, there might be situations in which it is preferable to look up the values that are in Local Configuration MBeans. For example, the Administration Server might be down, making it impossible for you to access Administration MBeans.
To specify a Local Configuration MBean, it removes MBean and appends Config to the ServerMBean interface name. Note that the -type value for a Local Configuration instance of the ServerMBean is ServerConfig while the -type value for the corresponding Administration MBean instance is Server. For more information, refer to the description of Type in Table 2-3.
Listing 3-1 Configuring the Message Level
java weblogic.Admin -url myHost:8001 -username weblogic -password weblogic
GET -pretty -type ServerConfig
---------------------------
MBeanName: "examples:Location=examplesServer,Name=examplesServer,Type=ServerConfig"
AcceptBacklog: 50
AdministrationPort: 0
...
StdoutDebugEnabled: false
StdoutEnabled: true
StdoutFormat: standard
StdoutLogStack: true
StdoutSeverityLevel: 16
Example: Configuring the Message Level for Standard Out
The class in this example changes the value of the StdoutSeverityLevel attribute in the weblogic.management.configuration.ServerMBean to change the level of messages that a server instance named examplesServer sends to standard out.
Because the example is changing configuration values, it changes the value in the Administration MBean and relies on the WebLogic management services to propagate the change to the Managed Server.
In the example, weblogic is a user who has permission to view and modify MBean attributes. For information about permissions to view and modify MBeans, refer to "Protecting System Administration Operations" in WebLogic Server Administration Guide.
Listing 3-2 Configuring Standard Out Severity Level
import java.util.Set;
import java.util.Iterator;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.management.MBeanServer;
import javax.management.Attribute;
import java.lang.Object;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.configuration.ServerMBean;
public class ChangeStandardOut1 {
public static void main(String[] args) {
MBeanHome home = null;
ServerMBean server = null;
//domain variables
String url = "t3://localhost:7001";
String username = "weblogic";
String password = "weblogic";
String serverName = "Server1";
//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);
// Using MBeanHome.getMBean(name, type) to retrieve a type-safe
// interface for a ServerMBean
server = (ServerMBean)home.getMBean(serverName,"Server");
// Using ServerMBean.setStdoutSeverityLevel
server.setStdoutSeverityLevel(64);
// Providing feedback that operation succeeded.
System.out.println("Changed standard out severity level to: " +
server.getStdoutSeverityLevel());
} catch (Exception e) {
System.out.println("Caught exception: " + e);
}
}
}
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |