Two levels exist within the adaptorMO interface:
The mogen compiler enables you to generate a c-bean automatically from an m-bean. It enables you to generate several different c-beans from the same m-bean. This enables different representations of the same m-bean to be presented to different Java managers. For information on how to use the mogen compiler, refer to Chapter 6.

FIGURE 7-1 Relationship Between a C-Bean and an M-Bean
Mapping Rules for Class Names
The mapping service supplied with the Java Dynamic Management Kit defines the default rules for obtaining the Java class name of an m-bean or a c-bean from its object name. The default mapping rules are defined in TABLE 7-1. The mbean or cbean in the class part of the object name must be the Java class of the m-bean or c-bean.
Supported Protocols
Java Dynamic Management provides adaptor clients for accessing m-beans through these protocols:
The constructor of each of these classes is a public constructor that takes no parameters. This enables you to instantiate an adaptor client without hard-coding its Java class. CODE EXAMPLE 7-1 shows how to do this. In this example, the class of the adaptor client to be instantiated is specified as a hard-coded string. Such information can be provided by a command-line argument, a name server, or a directory service.
|
% rmiregistry portNumber
|
portNumber
Connecting an Adaptor Client
An adaptor client must be connected to the adaptor of an agent. To connect an adaptor client, make sure that the manager invokes the connect method of the adaptor client. In the connect method you have to specify:
| CODE EXAMPLE 7-2 Connecting an Adaptor Client |
When a manager invokes the connect method, it is possible that no messages are exchanged between the adaptor client and the agent. Whether this happens depends on the underlying communication mechanism used by the adaptor client.
Authentication
Authentication is supported by HTTP adaptor clients and servers. Whether an adaptor client requires login/password information is determined by the adaptor server. The authentication information is initialized as part of the connection. Each time one of the AdaptorMO methods is invoked, the login/password information is verified. If the login/password information is invalid at any time (it can change on the server even after the initial authentication), an UnauthorizedSecurityException is thrown. The client must disconnect and then reconnect.
To add an adaptor client with login/password information to a manager, create an instance of the Java class that implements the adaptor. The classes are shown on page 83. To add login/password authentication, create an instance of the AuthInfo class. CODE EXAMPLE 7-3 shows the instantiation of an HTTP/TCP adaptor client and an authentication information object.
| CODE EXAMPLE 7-3 Authentication for an Adaptor Client |
If the server has no login/password information defined, client authentication is not performed. Where authentication is not performed, any client is able to connect to the server.
Required Services
You have to add the following services to an adaptor client to enable it to operate:
Class Loader
An adaptor client uses a class loader to load c-beans. If all the Java classes for the c-beans are present on the machine where the adaptor client is running, you do not need to specify the class loader to be used. It is possible to use the system class loader. Otherwise, you have to add a class loader to the manager that uses the adaptor client.
To add the supplied class loader to a manager, include in the manager the code required for instantiating the com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoader class. If you add this class loader, the Java classes it loads must be present on a machine on which the class and library server is running. For more information, refer to "Class and Library Server" on page 147.
CODE EXAMPLE 7-4 shows how to add a network class loader to a manager. The newly instantiated class loader obtains classes and libraries from an RMI server that has the URL rmi://sky:1099/NetClassServer.
| CODE EXAMPLE 7-4 Instantiating a Network Class Loader in a Manager |
After you have added a class loader to a manager, register the class loader with the adaptor client. To register the class loader, set the ClassLoader property of the adaptor client as illustrated in CODE EXAMPLE 7-5.
| CODE EXAMPLE 7-5 Associating a Network Class Loader With an Adaptor Client |
For information on how to use an adaptor client to instantiate a class loader in an agent, refer to "Adding an RMI Network Class Loader Through a Manager" on page 151.
Operations on an Agent
After an adaptor client has been initialized, the manager that uses it is ready to perform the following management operations on an agent:
Retrieving M-Beans
An adaptor client enables you to write applications that can retrieve a subset of, or all of the m-beans managed by an agent. When retrieving m-beans, you can specify filters to limit the m-beans retrieved. The result of the retrieval depends on which level of interface you use:
| CODE EXAMPLE 7-6 Retrieving the Names of all M-Beans |
Using the High-Level Interface to Retrieve C-Beans
CODE EXAMPLE 7-7 shows how to retrieve c-beans. In the example, the getObjectName method is used to retrieve the name of the associated m-bean. The getObjectName method is included in all c-beans.
| CODE EXAMPLE 7-7 Retrieving C-Beans |
CODE EXAMPLE 7-8 shows how to retrieve a specific c-bean. Retrieving a specific c-bean enables a manager to invoke methods defined in the SimpleMO interface directly for performing management operations on the Simple m-bean.
| CODE EXAMPLE 7-8 Retrieving a Specific C-Bean |
Getting All Objects by Using an Adaptor Client
It is possible to get all objects by using the getObject method of an adaptor client. You can filter unwanted objects (for example, the base services or adaptors) in either of the following ways:
State.| CODE EXAMPLE 7-9 Getting a Property Value Through an Adaptor |
Using the Low-Level Interface to Get Several Properties
The Java Dynamic Management Kit enables you to use the low-level interface to get several properties in a single method invocation. CODE EXAMPLE 7-10 shows how to retrieve several properties using the low-level interface.
| CODE EXAMPLE 7-10 Getting Several Properties Through an Adaptor |
Using the High-Level Interface to Get a Property
The steps in using the high level interface to get a property are:
CODE EXAMPLE 7-11
Getting a Property Value Through a C-Bean
ObjectName name= new ObjectName("sky:SimpleMO");
Vector result= MOFactory.getObject(name, null);
if (result.isEmpty()) {
return;
}
SimpleMO cbean= (SimpleMO) result.firstElement();
String value= cbean.getState();
Getting all of the properties of a c-bean involves:
GroupOper property of the c-bean to true
| CODE EXAMPLE 7-12 Retrieving Properties from the Cache |
Getting a subset of the properties of a c-bean involves:
GroupOper property of the c-bean to true
| CODE EXAMPLE 7-13 Reading Several Properties |
Setting Properties of M-Beans
The Java Dynamic Management Kit enables you to use the low-level or high-level interface of an adaptor client to set properties of m-beans. Using the Low-Level Interface to Set a Property
To use the low-level interface of an adaptor client to set a property of an m-bean, you need to know the property name. CODE EXAMPLE 7-14 shows how to set a property called State.
| CODE EXAMPLE 7-14 Setting a Property Value Through an Adaptor Client |
The Java Dynamic Management Kit enables you to specify the name of an operator class when setting a property. The framework instantiates the specified operator and invokes it to set the property value.
Using the Low-Level Interface to Set Several Properties
The Java Dynamic Management Kit enables you to use the low-level interface to set several properties in a single method invocation. Before invoking the method, you have to build a list of modifications:
| CODE EXAMPLE 7-15 Using a Modification List |
Using the High-Level Interface to Set a Property
The steps in using the high-level interface to set a property are:
CODE EXAMPLE 7-16
Setting a Property Value Through a C-Bean
ObjectName name= new ObjectName("sky:SimpleMO");
Vector result= MOFactory.getObject(name, null);
if (result.isEmpty()) {
return;
}
SimpleMO cbean= (SimpleMO) result.firstElement();
cbean.setState("OK");
GroupOper property of the c-bean to true
| CODE EXAMPLE 7-17 Setting Several Properties Using the Cache |
Instantiating M-Beans
You can use an adaptor client to request that m-beans are instantiated in a remote Java Dynamic Management agent.
| CODE EXAMPLE 7-18 Instantiating an M-Bean and a C-Bean |
In this example, the name of the Java class to be instantiated in the agent is specified explicitly. If you do not specify the Java class name explicitly, you can use the mapping service to enable the adaptor to obtain the name of the Java class to be instantiated in the agent. If you do not specify the Java class name explicitly, and do not use the mapping service, you must ensure that the agent includes the code required to determine the Java class name of the class to be instantiated.
Transferring M-Bean Instances
You can use an adaptor client to transfer Java objects from the client to the Java Dynamic Management agent. To do this, the adaptor serializes the object, sends the object to the agent and deserializes it in the agent. This means that the object must implement the java.io.Serializable interface. Deleting M-Bean Instances
You can use an adaptor client to remove an m-bean from a remote Java Dynamic Management agent. The m-bean is not removed from the Java Virtual Machine, but is only removed from the repository.
| CODE EXAMPLE 7-19 Using the Low-Level Interface to Delete an M--Bean |
CODE EXAMPLE 7-20 shows how to use the high-level interface of an adaptor client to delete an m-bean from the repository.
| CODE EXAMPLE 7-20 Using the High-Level Interface to Delete an M--Bean |