Programming WebLogic Management Services with JMX

 Previous Next Contents Index View as PDF  

Accessing WebLogic Server MBeans

All JMX tasks—viewing or changing MBean attributes, using notifications, and monitoring changes—use the same process to access MBeans.

The following sections describe how to access WebLogic Server MBeans:

 


Accessing MBeans: Main Steps

The main steps for accessing MBeans in WebLogic Server are as follows:

  1. Use a weblogic.management.MBeanHome interface to access the MBean Server. See Accessing an MBeanHome Interface.

  2. Use one of the following interfaces to retrieve, look up, and invoke operations on MBeans:

    In most cases, you use these interfaces to retrieve a list of MBeans and then filter the list to retrieve and invoke operations on a specific MBean. However, if you know the WebLogicObjectName of an MBean, you can retrieve an MBean directly by name.

 


Determining Which Interfaces to Use

When accessing MBeans, you must make two choices about which interfaces you use:

 


Accessing an MBeanHome Interface

The simplest process for retrieving a local MBeanHome interface or an Administration MBeanHome interface is to use the WebLogic Server Helper class. If you are more comfortable with a standard J2EE approach, you can use the Java Naming and Directory Interface (JNDI) to retrieve MBeanHome.

Using the Helper APIs to Retrieve an MBeanHome Interface

WebLogic Server provides the weblogic.management.Helper APIs to simplify the process of retrieving MBeanHome interfaces.

To use the Helper APIs, collect the following information:

After you collect the information, use one of the following APIs:

For more information about the Helper APIs, refer to the WebLogic Server Javadoc.

Example: Retrieving a Local MBeanHome Interface

The following example (Listing 2-1) is a class that uses the Helper API to obtain the local MBeanHome interface for a server named MS1.

Listing 2-1 Retrieving a Local MBeanHome Interface

import weblogic.management.Helper;
import weblogic.management.MBeanHome;
public class UseHelper {
    public static void main(String[] args) {
        String url = "t3://localhost:7001";
        String username = "weblogic";
        String password = "weblogic";
        String msName = "MS1";
        MBeanHome localHome = null;
        try {
            localHome = (MBeanHome)Helper.getMBeanHome(username, password, url,
                       msName);
            System.out.println("Local MBeanHome for" + localHome +
                       " found using the Helper class");
        } catch (IllegalArgumentException iae) {
            System.out.println("Illegal Argument Exception: " + iae);
        }
    }
}

Using JNDI to Retrieve an MBeanHome Interface

While the Helper APIs provide a simple way to obtain an MBeanHome interface, you might be more familiar with the standard approach of using JNDI to retrieve the MBeanHome. From the JNDI tree of a Managed Server, you can access the server's local MBeanHome interface. From the JNDI tree of the Administration Server, you can access the Administration MBeanHome as well as the local MBeanHome interface for any server instance in the domain.

To use JNDI to retrieve an MBeanHome interface:

  1. Construct a weblogic.jndi.Environment object and use Environment methods to configure the object:

    1. Use the setSecurityPrincipal and setSecurityCredentials methods to specify user credentials.

      WebLogic Server verifies that the user credentials you supply have been granted permission to carry out requests through the MBeanHome interface. For more information, refer to "Protecting System Administration Operations" in WebLogic Server Administration Guide.

    2. If your application and the MBeanHome interface are in different JVMs, use the Environment.setProviderUrl method to specify the server instance that hosts the MBeanHome interface. The URL must specify the listen address of the server and the port on which the server listens for administrative requests.

      If you want to retrieve the Administration MBeanHome, setProviderUrl must specify the Administration Server.

    3. Use the getInitialContext method to initialize a javax.naming.Context object.

    For example, the following lines of code set the initial context to a server instance that runs on a host computer named WLServerHost and uses the default domain-wide administration port to receive administrative requests:

    Environment env = new Environment();
    env.setProviderUrl("t3://WLServerHost:9002");
    env.setSecurityPrincipal("weblogic");
    env.setSecurityCredentials("weblogic");
    Context ctx = env.getInitialContext();

    For more information about weblogic.jndi.Environment, refer to the WebLogic Server Javadoc.

  2. Use javax.naming.Context methods to look up and retrieve the MBeanHome interface for the current context.

    Use one of the following APIs, depending on whether you are retrieving a local MBeanHome interface or the Administration MBeanHome:

The following sections are examples of retrieving MBeanHome interfaces:

Example: Retrieving the Administration MBeanHome from an External Client

The following example (Listing 2-2) shows how an application running in a separate JVM looks up the Administration MBeanHome interface. 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 2-2 Retrieving the Administration MBeanHome from an External Client

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.AuthenticationException;
import javax.naming.CommunicationException;
import javax.naming.NamingException;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
public class RetrieveMBeanHome{
    public static void main(String[] args) {
        MBeanHome home = null;
        //domain variables
        String url = "t3://localhost:7001";
        String username = "weblogic";
        String password = "weblogic";
        //Setting an initial context.
        try {
            Environment env = new Environment();
            env.setProviderUrl(url);
            env.setSecurityPrincipal(username);
            env.setSecurityCredentials(password);
            Context ctx = env.getInitialContext();
            //Retrieving the Administration MBeanHome interface
            home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            System.out.println("Got the Admin MBeanHome: " + home + " from the
                               Admin server");
        } catch (Exception e) {
            System.out.println("Exception caught: " + e);
        }
    }
}

Example: Retrieving a Local MBeanHome from an Internal Client

If your client application resides in the same JVM as the Administration Server (or the WebLogic Server instance you want to manage), the JNDI lookup for the MBeanHome is simpler. Listing 2-3 shows how a JMX application running in the same JVM as a WebLogic Server instance would look up the local MBeanHome for a server instance that listens at t3://localhost:7001.

Listing 2-3 Retrieving a Local MBeanHome from an Internal Client

import javax.naming.Context;
import javax.management.ObjectName;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import weblogic.management.WebLogicObjectName;
import weblogic.jndi.Environment;
public class serverInfo {
public static void main(String[] args) {
        MBeanHome home = null;
//domain variables
String url = "t3://localhost:7001";
String username = "weblogic";
String password = "weblogic";
        try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
            //Setting the initial context
Context ctx = env.getInitialContext();
             //Retrieving the server-specific MBeanHome interface
home = (MBeanHome)ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
System.out.println("Got the Server-specific MBeanHome: " + home);

 


Using the Type-Safe Interface to Access MBeans

After you retrieve the MBeanHome interface, the easiest approach for accessing MBeans is to use methods in the MBeanHome interface that retrieve a type-safe interface for MBeans.

You can use this type-safe interface only with the MBeans that WebLogic Server provides. You cannot use this type-safe interface for MBeans that are based on MBean types that you create.

Retrieving a List of All MBeans

You can use the MBeanHome.getAllMBeans method to look up the object names of MBeans that are within the scope of the MBeanHome interface that you retrieve. For example, if you retrieve the Administration MBeanHome, using getAllMBeans() returns a list of all MBeans in the domain. If you retrieve a Local MBeanHome interface, using getAllMBeans() returns a list of the Runtime MBeans for the current server only and of all Local Configuration MBeans in the domain.

The example class in Listing 2-4:

  1. Uses JNDI APIs to retrieve the Administration MBeanHome interface.

  2. Uses the MBeanHome.getAllMBeans method to retrieve all MBeans in a domain.

  3. Assigns the list of MBeans to a Set object and uses methods of the Set and Iterator interfaces to iterate through the list.

  4. Uses the WebLogicMBean.getObjectName method to retrieve the WebLogicObjectName of each MBean.

  5. Uses the WebLogicObjectName.getName and getType methods to retrieve the Name and Type values of the WebLogicObjectName

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 2-4 Retrieving All MBeans in a Domain

import javax.naming.Context;
import java.util.Set;
import java.util.Iterator;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import weblogic.management.WebLogicObjectName;
public class ListAllMBeans{
    public static void main(String args[]) {
        String url = "t3://localhost:7001";
        String username = "weblogic";
        String password = "weblogic";
        try {
            //Obtaining an MBeanHome Using JNDI
            Environment env = new Environment();
            env.setProviderUrl(url);
            env.setSecurityPrincipal(username);
            env.setSecurityCredentials(password);
            Context ctx = env.getInitialContext();
            MBeanHome home = (MBeanHome)ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            Set allMBeans = home.getAllMBeans();
            System.out.println("Size: " + allMBeans.size());
            for (Iterator itr = allMBeans.iterator(); itr.hasNext(); ) {
                WebLogicMBean mbean = (WebLogicMBean)itr.next();
                WebLogicObjectName objectName = mbean.getObjectName();
                System.out.println(objectName.getName() + " is a(n) " +
                                        mbean.getType());
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }
}

For more information about the MBeanHome.getAllMBeans method, refer to the WebLogic Server Javadoc.

Retrieving MBeans By Type and Selecting From the List

Instead of retrieving a list of all MBeans in the scope of MBeanHome, you can retrieve a list of MBeans that match a specific type. Type indicates the type of resource that the MBean manages and whether the MBean is an Administration, Local Configuration, or Runtime MBean. For more information about types of MBeans, refer to the next section, Using WebLogicObjectNames for WebLogic Server MBeans.

The example class in Listing 2-5:

  1. Uses JNDI to retrieve the Administration MBeanHome interface.

  2. Uses the MBeanHome.getMBeansByType method to retrieve a list of all ServerRuntime MBeans in a domain.

  3. Assigns the list of MBeans to a Set object and uses methods of the Set and Iterator interfaces to iterate through the list.

  4. Uses the ServerRuntime.getName method to retrieve the name of each ServerRuntime MBean. The name of a ServerRuntime MBean corresponds to the name of a server instance.

  5. When it finds the ServerRuntime MBean for a server named Server1, it prints a message to standard out.

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 2-5 Selecting by Type from a List of MBeans

import java.util.Set;
import java.util.Iterator;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.management.ObjectName;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import weblogic.management.WebLogicObjectName;
import weblogic.management.configuration.ServerMBean;
import weblogic.management.runtime.ServerRuntimeMBean;
import weblogic.jndi.Environment;
public class serverRuntimeInfo {
    public static void main(String[] args) {
        MBeanHome home = null;
        //domain variables
        String url = "t3://localhost:7001";
        String serverName = "Server1";
        String username = "weblogic";
        String password = "weblogic";
        ServerRuntimeMBean serverRuntime = null;
        Set mbeanSet = null;
        Iterator mbeanIterator = null;
        //Using JNDI to retrieve the Administration MBeanHome
        //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);
            System.out.println("Got the Admin MBeanHome: " + home );
        } catch (Exception e) {
            System.out.println("Exception caught: " + e);
        }
        //Using the getMBeansByType method to get all ServerRuntime MBeans
        //in the domain.
        try {
            mbeanSet = home.getMBeansByType("ServerRuntime");
            //Iterating through the results and comparing the server names
            //find the one we want.
            mbeanIterator = mbeanSet.iterator();
            while(mbeanIterator.hasNext()) {
                serverRuntime = (ServerRuntimeMBean)mbeanIterator.next();
                //Using serverRuntime.getName to find the ServerRuntime
                //MBean for Server1.
                if(serverRuntime.getName().equals(serverName)) {
                    System.out.println("Got the serverRuntimembean: " +
                    serverRuntime + " for: " + serverName);
                 }
            }
         } catch (Exception e) {
               System.out.println("Exception caught: " + e);
         }
    }
}

For more information about the MBeanHome.getMBeansByType method, refer to the WebLogic Server Javadoc.

Walking the Hierarchy of Local Configuration and Runtime MBeans

WebLogic Server MBeans exist within a hierarchy that reflects the resources with which they are associated. For example, each server instance can contain multiple execute queues, and WebLogic Server represents this relationship by making each ExecuteQueueMBean a child of a ServerMBean.

Walking the hierarchy of MBeans is the easiest way to retrieve Local Configuration and Runtime MBeans. If you want to retrieve Administration MBeans, or if you want to use the Administration MBeanHome to retrieve MBeans, BEA recommends that you retrieve MBeans by type and then filter the list. See Retrieving MBeans By Type and Selecting From the List.

The root of the Configuration MBean hierarchy is DomainMBean. Below this root are MBeans such as:

The root of the Runtime hierarchy is ServerRuntimeMBean. Just below this root are MBeans such as:

Parent MBeans usually provide methods for retrieving their children. For example, ServerMBean.getExecuteQueues returns all ExecuteQueueMBeans that have been configured for the server.

To walk the hierarchy of Local Configuration MBeans or Runtime MBeans:

  1. From your JMX application, retrieve the local MBeanHome interface.

  2. From the local MBeanHome interface, retrieve one of the top-level MBeans by invoking one of the following methods:

    Use these methods to retrieve only MBeans that are immediately below DomainMBean or ServerRuntimeMBean. These methods do not return MBeans that are below the first level of the MBean hierarchy.

  3. From the MBean that you retrieved, invoke methods to retrieve the MBean's children.

    If a parent MBean does not provide methods to retrieve child MBeans, use getMBeanByType() and iterate over the results to find the MBean that matches your criteria. If you want to retrieve Local Configuration MBeans, be sure to append Config to the MBean type value. See Retrieving MBeans By Type and Selecting From the List.

Note: BEA recommends that you retrieve Local Configuration MBeans only to read values; do not change attribute values in Local Configuration MBeans. When the Managed Server replicates the data of other Managed Servers, 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.

Listing 2-6 is an example of retrieving all Local Configuration ExecuteQueueMBeans on a server instance named ManagedServer1.

Listing 2-6 Retrieving Local Configuration ExecuteQueueMBeans

import javax.naming.Context;
import javax.management.ObjectName;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import weblogic.management.WebLogicObjectName;
import weblogic.management.configuration.ConfigurationMBean;
import weblogic.management.configuration.ServerMBean;
import weblogic.management.configuration.ExecuteQueueMBean;
import weblogic.jndi.Environment;
public class serverConfigInfo {
public static void main(String[] args) {
MBeanHome home = null;
ServerMBean servercfg = null;
ExecuteQueueMBean[] xqueues = null;
ExecuteQueueMBean xqueue = null;
        //domain variables
String url = "t3://localhost:7001";
String serverName = "ManagedServer1";
String username = "weblogic";
String password = "weblogic";
        try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
            //Setting the initial context
Context ctx = env.getInitialContext();
            //Retrieving the server-specific MBeanHome interface
home = (MBeanHome)ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
System.out.println("Got the Server-specific MBeanHome: " + home);
           //Retrieving the Local Configuration ServerMBean
servercfg = (ServerMBean)home.getConfigurationMBean(serverName,
"ServerConfig");
System.out.println("Got the Server Config MBean: " + servercfg);
           //Retrieving all ExecuteQueue MBeans that have been
//configured for the server instance
xqueues = servercfg.getExecuteQueues();
           //Iterating through the results 
for (int i=0; i < xqueues.length; i++){
xqueue = xqueues[i];
System.out.println("Execute queue name: " +
xqueue.DEFAULT_QUEUE_NAME);
System.out.println("Thread count:" + xqueue.getThreadCount());
             }
} catch (Exception e) {
System.out.println("Exception caught: " + e);
}
}
}

If you want to create generic JMX code that you can run on any server instance to retrieve its Server Configuration MBean:

  1. From the local MBeanHome interface, use the getMBeansByType method to retrieve the server's ServerRuntimeMBean:
    serverRuntime = MBeanHome.getMBeansByType(ServerRuntime)

    The local MBeanHome interface can access only the runtime MBeans that are specific to the current server instance, so getMBeansByType(ServerRuntime) returns only the ServerRuntimeMBean for the current server.

  2. Use ServerRuntimeMBean's getName method to retrieve the name of the server:
    serverName = serverRuntime.getName()

  3. Use the server name when invoking MBeanHome.getConfigurationMBean:
    MBeanHome.getConfigurationMBean(serverName,"ServerConfig")

For more information, see Example: Determining the Active Domain and Servers.

 


Using the MBeanServer Interface to Access MBeans

A standard JMX approach for interacting with MBeans is to use the javax.management.MBeanServer interface to look up the MBeans that are registered in the MBean Server. Then you use the MBeanServer interface to get or set MBean attributes or to invoke MBean operations. For the complete list of MBeanServer methods, refer to the JMX 1.0 API documentation, which you can download from http://jcp.org/aboutJava/communityprocess/final/jsr003/index.html. The archive that you download includes the API documentation.

In the WebLogic Server implementation of JMX, you use the MBeanHome interface to look up the MBeanServer interface.

The example class in Listing 2-7:

  1. Uses JNDI to retrieve the Administration MBeanHome interface. Because this example retrieves Administration MBeans, it must use the Administration MBeanHome interface.

  2. Uses the Administration MBeanHome interface to retrieve the MBeanServer interface.

  3. Uses the MBeanServer.queryNames method to look up all instances of JDBCConnectionPoolMBean in the domain. Note that the queryNames method signature requires the example to cast the string "examples:Type=JDBCConnectionPool,*" as an Object.

  4. Assigns the list of MBeans to a Set object and uses methods of the Set and Iterator interfaces to iterate through the list.

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 2-7 Using the MBeanServer Interface

import java.util.Iterator;
import java.util.Set;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.AuthenticationException;
import javax.naming.CommunicationException;
import javax.naming.NamingException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.QueryExp;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.RemoteMBeanServer;
public class ListJDBCInfo {
    public static void main(String[] args) {
        QueryExp query = null;
        MBeanHome home = null;
        RemoteMBeanServer homeServer = null;
        //domain variables
        String url = "t3://localhost:7001";
        String username = "weblogic";
        String password = "weblogic";
        //Setting an initial context.
        try {
            Environment env = new Environment();
            env.setProviderUrl(url);
            env.setSecurityPrincipal(username);
            env.setSecurityCredentials(password);
            Context ctx = env.getInitialContext();
            //Retrieving the Administration MBeanHome interface
            home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            System.out.println("Got the Admin MBeanHome: " + home + " from the
                               Admin server");
            //Retrieving the MBeanServer interface
            homeServer = home.getMBeanServer();
            //Retrieving a list of MBeans with object names that include
            //"JDBCConnectionPool"
            Set JDBCMBeans = homeServer.queryNames(new
                    ObjectName("mydomain:Type=JDBCConnectionPool,*"), query);
            //where "query" could be any object that implements the JMX
            //javax.managementQueryExp
            for (Iterator itr = JDBCMBeans.iterator(); itr.hasNext(); ) {
                ObjectName mbean = (ObjectName)itr.next();
                System.out.println("Matches to the MBean query:" + mbean);
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }
}

 


Using WebLogicObjectNames for WebLogic Server MBeans

When you instantiate a WebLogic Server MBean, the MBean Server registers the instance under a name that conforms to the weblogic.management.WebLogicObjectName conventions. If you know the WebLogicObjectName of an MBean, after you retrieve an MBeanHome interface, you can retrieve an MBean directly by name.

The MBean's WebLogicObjectName uses the following conventions to provide a unique identification for a given MBean across all domains:

domain:Name=name,Type=type[,Location=serverName]
[,TypeOfParentMBean=NameOfParentMBean][,TypeOfParentMBean1=NameOfParentMBean1]...

The order of the attribute=value pairs is not significant, but the name must begin with domain:. Note also that MBeans can express multiple parent MBeans.

For example, the following is the WebLogicObjectName for an EJBComponentRuntime MBean for an EJB in an application that is deployed on a server instance named MyServer. The first and fourth attribute/value pairs in this name, ApplicationRuntime=MyServer_MyEAR and ServerRuntime=MyServer, identify the parent MBeans of this EJB.

mydomain:ApplicationRuntime=MyServer_MyEAR,Location=MyServer,Name=MyServer_MyEAR_SessionEJB,ServerRuntime=MyServer,Type=EJBComponentRuntime

The following table describes each name component.

Table 2-3 WebLogic Server MBean Naming Conventions

This Component

Specifies

domain

The name of the WebLogic Server administration domain.

Name=name

The string that you provided when you created the associated resource. For example, when you create a JDBC connection pool, you must provide a name for that pool, such as MyPool1. The JDBCConnectionPoolMBean that represents MyPool1 uses Name=MyPool1 in its JMX object name.

The WebLogicObjectName.getName method returns this value for any given MBean.

If you create an MBean, you must specify a value for this Name component that is unique amongst all other MBeans in a domain.

Type=type

Refers to the interface class of which the MBean is an instance. All WebLogic Server MBeans are an instance of one of the interface classes defined in the weblogic.management.configuration or weblogic.management.runtime packages. For Configuration MBeans, Type also refers to whether an instance is an Administration MBean or a Local Configuration MBean. For a complete list of all WebLogic Server MBean interface classes, refer to the WebLogic Server Javadoc for the weblogic.management.configuration or weblogic.management.runtime packages.

To determine the value that you provide for the Type component:

    1. Find the MBean's interface class and remove the MBean suffix from the class name. For example, for an MBean that is an instance of the weblogic.management.runtime.JDBCConnectionPoolRuntime
    MBean
    , use JDBCConnectionPoolRuntime.

    2. For a Local Configuration MBean, append Config to the name. For example, for a Local Configuration MBean that is an instance of the weblogic.management.configuration.JDBCConnectionPool
    MBean
    interface class, use JDBCConnectionPoolConfig. For the corresponding Administration MBean instance, use JDBCConnectionPool.

Location=servername

All Runtime and Local Configuration MBeans include a Location component that specifies the name of the server on which that MBean is located. Administration MBeans do not include this component.

For example, for the ServletRuntime MBean that runs on a server named myserver, the WebLogicObjectName includes the following components:

mydomain:Name=myServlet,Type=ServletRuntime,Location=
myserver
The WebLogicObjectName.getLocation method returns this value for any given MBean.

TypeOfParentMBean=
NameOfParentMBean

Runtime, Local Configuration, or Administration MBeans that have a child relationship with a parent MBean use this extra attribute in their object names to identify the relationship.

Note: With the exception of DomainMBean, all MBeans are direct or indirect children of the domain's DomainMBean. Because this parent-child relationship applies to all MBeans, it is not expressed in WebLogicObjectName.

For example, an instance of LogMBean is used by a domain to configure the domain-wide log file. Each WebLogic Server instance also maintains its own instance of LogMBean to configure its server-specific log file. The LogMBean that a domain uses does not express a child relationship, while the LogMBean that a server instance uses expresses its child relationship with the server's ServerMBean. (See Figure 2-1.)

To express the name of the Administration LogMBean that examplesServer uses to maintain its log file, use the following name:

examples:Name=examplesServer,Server=examplesServer,
Type=Log

To express the name of the Local Configuration LogMBean that examplesServer uses to maintain its log file, use the following name:

examples:Location=examplesServer,Name=examplesServer,
ServerConfig=examplesServer,Type=LogConfig

By convention, WebLogic Server child MBeans use the same value for the Name component as the parent MBean. For example, the LogMBean that is a child of the examplesServer Server MBean uses Name=examplesServer in its WebLogicObjectName. WebLogic Server cannot follow this convention when a parent MBean has multiple children of the same type.

To determine whether the WebLogicObjectName of an MBean expresses a parent-child relation, use the WebLogicObjectName.getParent method or the weblogic.Admin GET command.


 

Figure 2-1 illustrates that one instance of LogMBean is a child of DomainMBean and is used to manage the domain-wide log file. Another instance of LogMBean is a child of a server instance's ServerMBean and is used to manage the server-specific log file. The TypeOfParentMBean=NameOfParentMBean component of the WebLogicObjectName removes any ambiguity in the application of an MBean instance.

Figure 2-1 Parent-Child Relation of LogMBean Instances


 

 


Using weblogic.Admin to Find the WebLogicObjectName

If you are unsure which values to supply for an MBean's WebLogicObjectName, you can use the weblogic.Admin utility to find the WebLogicObjectName. The utility can return information only for WebLogic Server MBeans that are on an active server instance.

For example, to find the WebLogicObjectName for the Administration instance of the LogMBean in the examples domain, enter the following command on the examplesServer Administration Server, where the Administration Server is listening on port 8001 and weblogic is the name and password of a user who has permission to view MBean attributes:

java weblogic.Admin -url localhost:8001 -username weblogic
-password weblogic GET -pretty -type Log

The command returns the output in Listing 2-8. Notice that the command returns two MBeans of type Log on the Administration Server. The first MBean, examples:Name=examplesServer,Server=examplesServer,Type=Log, has a child relationship with the ServerMBean of examplesServer; this relationship indicates that the MBean is the LogMBean that configures the server-specific log file. The second MBean, examples:Name=examples,Type=Log, has no child relationship, which indicates that it configures the domain-wide log file.

The -pretty causes the weblogic.Admin utility to place each MBean attribute and value on a separate line. Without this argument, the utility surrounds each attribute/value pair with curly braces {}, but all output is on a single line.

Listing 2-8 Output from weblogic.Admin

---------------------------
MBeanName: "examples:Name=examplesServer,Server=examplesServer,Type=Log"
CachingDisabled: true
FileCount: 7
FileMinSize: 500
FileName: examplesServer\examplesServer.log
FileTimeSpan: 24
Name: examplesServer
Notes:
NumberOfFilesLimited: false
ObjectName: examplesServer
Parent: examplesServer
Registered: false
RotationTime: 00:00
RotationType: none
Type: Log
---------------------------
MBeanName: "examples:Name=examples,Type=Log"
CachingDisabled: true
FileCount: 7
FileMinSize: 500
FileName: ./logs/wl-domain.log
FileTimeSpan: 24
Name: examples
Notes:
NumberOfFilesLimited: false
ObjectName: examples
Parent: examples
Registered: false
RotationTime: 00:00
RotationType: none
Type: Log

To view the Local Configuration MBean instances of LogMBean, append Config to the value of the type argument:

java weblogic.Admin -url localhost:8001 -username weblogic -password weblogic GET -pretty -type LogConfig

The command returns output in Listing 2-9. Notice that the WebLogicObjectName of the Local Configuration MBeans includes a Location component.

Listing 2-9 Local Configuration MBeans

---------------------------
MBeanName: "examples:Location=examplesServer,Name=examplesServer,ServerConfig=examplesServer,Type=LogConfig"
CachingDisabled: true
FileCount: 7
FileMinSize: 500
FileName: examplesServer\examplesServer.log
FileTimeSpan: 24
Name: examplesServer
Notes:
NumberOfFilesLimited: false
ObjectName: examplesServer
Registered: false
RotationTime: 00:00
RotationType: none
Type: LogConfig
---------------------------
MBeanName: "examples:Location=examplesServer,Name=examples,Type=LogConfig"
CachingDisabled: true
FileCount: 7
FileMinSize: 500
FileName: ./logs/wl-domain.log
FileTimeSpan: 24
Name: examples
Notes:
NumberOfFilesLimited: false
ObjectName: examples
Registered: false
RotationTime: 00:00
RotationType: none
Type: LogConfig

 

Back to Top Previous Next