Accessing MBean Servers

Now that you know how WebLogic organizes MBeans across MBean Servers, we can turn to accessing MBean Servers. The first point of entry is to find a home interface for the MBean Server. The home interface provides access to the underlying MBean server and enables you to reach the MBeans hosted on the server.

20.2.1 Local and Administration Home Interfaces

The MBean Server running on a WebLogic Server instance can be reached through the weblogic.management.MBeanHome interface. Two implementations of this home interface can be obtained:

Local Home interface

This interface provides access to the local MBeans hosted on the MBean Server itself. This means that you can use the Local Home interface to access the Local Configuration and Runtime MBeans on that server instance, but not interact with any of the Administration MBeans.

Administration Home interface

This interface, exposed only by the Administration Server, provides access to the Administration MBeans and all other MBeans on all other server instances within the domain.

Figure 20-2 illustrates this architecture.

Figure 20-2. Home interfaces and their hosted MBeans

figs/wblgc_2002.gif

As indicated in Figure 20-2, you also can reach the Runtime MBeans on any Managed Server through the Administration Home interface itself, instead of using the Local Home interface of the Managed Server directly. Clearly, it is slower to access the local MBeans through the Administration interface rather than to access them directly through the Local interface. You incur an additional performance penalty due to the overhead imposed by the RMI communication with the local server MBeans. If you need to manipulate the local MBeans of a particular Managed Server, you should contact that server directly through its Local Home interface.

20.2.2 Retrieving the Home Interface

The home interfaces can be retrieved either by looking up the server's JNDI tree or by using a WebLogic-specific helper class. In both cases, you need to supply the authentication details of a user who is authorized to access the domain resource and the URL of the server that you wish to contact. If you intend to access a local home, you also need the name of the server that you would like to contact.

Use the getMBeanHome( ) method on the weblogic.management.Helper class to access the Local MBean home, and use the getAdminMBeanHome( ) method on the Helper class to access the Administration MBean home. The following code sample shows how to use these helper methods to retrieve the Local and Administration home interfaces:

public MBeanHome findLocalHomeHelper(String url, String serverName) {
 weblogic.management.MBeanHome localHome = null;
 localHome = 
 (MBeanHome) Helper.getMBeanHome(USERNAME, PASSWORD, url, serverName);
 return localHome;
}

public MBeanHome findAdminHomeHelper(String adminURL) {
 weblogic.management.MBeanHome adminHome = null;
 adminHome = 
 (MBeanHome) Helper.getAdminMBeanHome(USERNAME, PASSWORD, adminURL);
 return adminHome;
}

Now, if you need to access the Local home of ServerB, you need to simply issue the following call:

MBeanHome localHomeB = findLocalHomeHelper("t3://10.0.10.14:7001", "ServerB");

Using the JNDI to obtain a home is just as easy. The locations of the Local and Administration homes are stored in the constants MBeanHome.LOCAL_JNDI_NAME and MBeanHome.ADMIN_JNDI_NAME, respectively. Once you establish an initial context with a server, you simply look up the home interface using these names:

InitialContext ctx = new InitialContext( );
MBeanHome localHomeB = (MBeanHome) ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);

An initial JNDI context obtained from the Administration Server also allows you to access the Local home from any of the Managed Servers. In this case, the JNDI name used to look up the Local home matches the following string:

 "weblogic.management.home" + "." + ServerName

This prefix weblogic.management.home is conveniently bound to the constant MBeanHome.JNDI_NAME. The following code sample shows how to locate the Local Home interface of ServerB via the initial JNDI context obtained from the Administration Server:

//create an initial JNDI context using the URL of the Admin Server
Hashtable env = new Hashtable( );
env.put(Context.INITIAL_CONTEXT_FACTORY,
 "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://adminserver:8001");
//set other environment properties for the initial JNDI Context
InitialContext ctx = new InitialContext(env);
//now look up Local home by prefixing MBeanHome.JNDI_NAME to "ServerB"
MBeanHome localHomeB = (MBeanHome) ctx.lookup(MBeanHome.JNDI_NAME + "." + "ServerB");

Introduction

Web Applications

Managing the Web Server

Using JNDI and RMI

JDBC

Transactions

J2EE Connectors

JMS

JavaMail

Using EJBs

Using CMP and EJB QL

Packaging and Deployment

Managing Domains

Clustering

Performance, Monitoring, and Tuning

SSL

Security

XML

Web Services

JMX

Logging and Internationalization

SNMP



WebLogic. The Definitive Guide
WebLogic: The Definitive Guide
ISBN: 059600432X
EAN: 2147483647
Year: 2003
Pages: 187

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net