Previous Next Contents Index


7


Adaptor Clients

An adaptor client enables a Java manager to access m-beans in an agent through a particular communications protocol. Each adaptor client is accessed through an adaptor API.


Operation of the Adaptor Clients

An adaptor client enables Java managers to perform management operations on a Java Dynamic Management agent. It does this by providing a Java manager with handles on m-beans in an agent. These handles enable the Java manager to manage the m-beans directly. The manager does not need information on the protocol used to communicate with the agent; rather it needs the class names of the objects to be managed.


The adaptorMO Interface

An adaptor client implements the adaptorMO interface. This interface is protocol independent. Therefore, all code you write using this interface can run on any adaptor client that implements the interface, regardless of the protocol that the adaptor client uses. The implementations of the adaptorMO interface supplied with the Java Dynamic Management Kit are described in "Supported Protocols" on page 82.

Two levels exist within the adaptorMO interface:

The high-level interface is built on top of the low-level interface. Using the high-level interface is much easier than using the low-level interface. However it requires its own representation of an m-bean. It also requires that the manager has information on the semantics of the m-beans it manages.

Use of C-Beans by the adaptorMO Interface

The high-level interface of an adaptor client requires its own representation of an m-bean. Such a representation is called a client bean or c-bean. Like an m-bean, a c-bean is a JavaBeans component. A c-bean defines how a Java manager accesses an m-bean. A c-bean consists of:

A Java manager obtains a reference to a c-bean by using an adaptor client. Methods in the adaptor client instantiate the c-bean. A Java manager performs management operations on an m-bean by invoking methods on the c-bean that represents it. To the Java manager, a c-bean is a local representation of a remote Java object (an m-bean). FIGURE 7-1 shows the relationship between a c-bean and an m-bean.

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.

TABLE  7-1 Default Mapping Rules for Class Names

Type of Bean
Class Part of Object Name
Java Class

M-bean

mbeanMOStub

mbean

mbeanMO

mbean

mbean

mbean

C-bean

cbeanMOStub

cbeanMOStub

cbeanMO

cbeanMOStub

cbean

cbeanMOStub



Supported Protocols

Java Dynamic Management provides adaptor clients for accessing m-beans through these protocols:

RMI Adaptor Client

The RMI adaptor client enables a Java manager to access the RMI adaptor in an agent. The manager needs to instantiate and initialize the adaptor client. When initializing the adaptor client, the manager must provide the URL of the RMI adaptor. The default URL is: rmi://localhost:1099/com.sun.jaw.impl.adaptor.rmi.AdaptorServer.

HTTP/TCP Adaptor Client

The HTTP/TCP adaptor client enables a Java manager to access the HTTP/TCP adaptor server in an agent. The manager must instantiate and initialize the adaptor client. When initializing the adaptor client, the manager must provide the host name, port number, and object name of the HTTP/TCP adaptor server. If no port number is specified, the HTTP/TCP adaptor client uses the default, port 8081.

HTTP/UDP Adaptor Client

The HTTP/UDP adaptor client enables a Java manager to access the HTTP/UDP adaptor server in an agent. The manager must instantiate and initialize the adaptor client. When initializing the adaptor client, the manager must provide the host name, port number, and object name of the HTTP/UDP adaptor server. If no port number is specified, the HTTP/UDP adaptor client uses the default, port 8083.

HTTP/SSL Adaptor Client

The HTTP/SSL adaptor client enables a Java manager to access the HTTP/SSL adaptor server in an agent. The manager must instantiate and initialize the adaptor client. When initializing the adaptor client, the manager must provide the host name, port number, and object name of the HTTP/SSL adaptor server. If no port number is specified, the HTTP/SSL adaptor client uses the default, port 8084.

IIOP Adaptor Client

The IIOP adaptor client enables a Java manager to access the IIOP adaptor server in an agent. The manager must instantiate and initialize the adaptor client. When initializing the adaptor client, the manager must provide the host name on which the CORBA name service is running and the port number on which the name service listens, for example sky:80. If no port number is specified, the IIOP adaptor uses the default, port 8085.


Initializing an Adaptor Client

Initializing an adaptor client consists of:

Adding an Adaptor Client to the Manager

To add an adaptor client to a manager, create an instance of the Java class that implements the adaptor client you want to use.

Adaptor Client
Java Class

RMI

com.sun.jaw.impl.adaptor.rmi.AdaptorClient

HTTP/TCP

com.sun.jaw.impl.adaptor.http.AdaptorClient

HTTP/UDP

com.sun.jaw.impl.adaptor.udp.AdaptorClient

HTTP/SSL

com.sun.jaw.impl.adaptor.https.AdaptorClient

IIOP

com.sun.jaw.impl.adaptor.iiop.AdaptorClient


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.


CODE  EXAMPLE  7-1     Instantiating an Adaptor Client

  // Instantiates an HTTP/TCP adaptor client.
  Class adaptorClass=
    Class.forName("com.sun.jaw.impl.adaptor.http.AdaptorClient");
  AdaptorMO MOFactory= (AdaptorMO) adaptorClass.newInstance();


If you want to use more than one RMI adaptor per client (or agent), you must run the rmiregistry command, specifying the port number that the new adaptor is going to use:  


% rmiregistry portNumber

portNumber

This refers to the port number for the new RMI adaptor.

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:

This information could be provided by a name server or directory service at the same time the Java class name of the adaptor client is given. CODE EXAMPLE 7-2 shows how to connect an adaptor client to an agent.

CODE  EXAMPLE  7-2     Connecting an Adaptor Client

   // Connect the MOFactory of the client to the server
   try {
      MOFactory.connect(auth, host, port, logicalName);
   }


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.

The client sends a request to the server to login to the server. If login/password information is defined for the adaptor server (see page 58) the server responds with a request for login/password information. The client sends its login/password information, which is compared by the server with the information for users with login/passwords authenticated by the server.

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

   // Set up the HTTP adaptor client.
   //
   com.sun.jaw.impl.adaptor.http.AdaptorClient adaptor = new
   com.sun.jaw.impl.adaptor.http.AdaptorClient();

   // Initialize the client authentication info.
   //
   AuthInfo authinfo = new AuthInfo("username2", "password2");

   // Initialize communication with the remote object server.
   //
   try {
      adaptor.connect(authinfo, agentHost, agentPort, ServiceName.APT_HTTP);
   } catch (com.sun.jaw.impl.adaptor.comm.UnauthorizedSecurityException use) {
      System.err.println("Server couldn't authenticate this client. Invalid login/password");
   }


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:

Mapping Service

An adaptor client uses a mapping service to determine:

A mapping service is supplied as the com.sun.jaw.impl.mapper.DefaultMapper Java class. The mapping rules it uses are defined in "Mapping Rules for Class Names" on page 81. The mapping service implements the com.sun.jaw.reference.mapper.MapperSrvIf Java interface.

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.

When you add a class loader to a manager, you must assign it an object name. The object name you assign to a class loader must contain configuration information that the class loader requires. For more information, refer to "Object Name of an RMI Network Class Loader" on page 150.

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 

   ObjectName name;
   name= new ObjectName        ("D:A.host=sky,port=1099,service=NetClassServer");
   NetClassLoader loader= new NetClassLoader(name);


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

   MOFactory.setClassLoader((ClassLoader) loader);


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:

Low-level and high-level interfaces are used to perform some operations on an agent; these interfaces are defined in "The adaptorMO Interface" on page 79.

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:

Using the Low-Level Interface to Retrieve M-Beans

CODE EXAMPLE 7-6 shows how to retrieve all the object names of all the objects managed by an agent.

CODE  EXAMPLE  7-6     Retrieving the Names of all M-Beans

   ObjectName name = new ObjectName(":");
   Vector result = MOFactory.getOnlyNames(name, null);


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

   ObjectName name = new ObjectName(":");
   Vector result = MOFactory.getObject(name, null);
   if (result.isEmpty()) {
      return;
   }
   for(Enumeration e = result.elements(); e.hasMoreElements(); ) {
      ManagedObject cbean= (ManagedObject) e.nextElement();
      ObjectName name = cbean.getObjectName();
      System.out.println(name.toString());
   }


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 

   ObjectName name = new ObjectName("sky:SimpleMO");
   Vector result= MOFactory.getObject(name, null);
   if (result.isEmpty()) {
      return;
   }
   SimpleMO cbean= (SimpleMO) result.firstElement();


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:

Getting 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 get properties of m-beans.

Using the Low-Level Interface to Get a Property

To use the low-level interface of an adaptor client to get a property of an m-bean, you need to know the property name. CODE EXAMPLE 7-9 shows how to retrieve a property called State.

CODE  EXAMPLE  7-9     Getting a Property Value Through an Adaptor

   ObjectName name= new ObjectName("sky:SimpleMO");
   String value= (String) MOFactory.getValue(name,"State");


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 

   ObjectName name= new ObjectName("sky:SimpleMO");
   Vector list= new Vector();
   list.addElement("State");
   list.addElement("NbChanges");
   PropertyList propList= MOFactory.getValues(name,list);


Using the High-Level Interface to Get a Property

The steps in using the high level interface to get a property are:

1. Getting a c-bean, as explained in "Using the High-Level Interface to Retrieve C-Beans" on page 89.

2. Invoking the getter associated with the property as illustrated in CODE EXAMPLE 7-11, which shows how to retrieve a property called State through a c-bean.

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 Properties From the Cache in a C-Bean

Getting properties from the cache in a c-bean improves the performance of applications by limiting the network traffic between an m-bean and a c-bean.

Getting all of the properties of a c-bean involves:

CODE EXAMPLE 7-12 shows how to retrieve the properties of the SimpleMO c-bean from the cache in a c-bean.

CODE  EXAMPLE  7-12     Retrieving Properties from the Cache 

   // Read all values and put them in the cache
   cbean.readAll();

   // Indicate to the object that values in cache should
   // be returned. It means that the calls below will not
   // generate requests for the target agent
   cbean.setGroupOper(true);
   String state= cbean.getState();
   Integer counter= cbean.getNbChanges();

   // Now go and read the value in the target agent
   cbean.setGroupOper(false);
   String newState= cbean.getState();


Getting a subset of the properties of a c-bean involves:

This subset retrieval is shown in CODE EXAMPLE 7-13.

CODE  EXAMPLE  7-13     Reading Several Properties 

   // Read several values and put them in the cache
   cbean.setGroupOper(true);

   // The values returned are cached values
   // Build list of properties to be read into the cache
   state= cbean.getState();
   counter= cbean.getNbChanges();

   // Read values into the cache
   cbean.readObject();

   // Read the values from cache
   state= cbean.getState();
   counter= cbean.getNbChanges();


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

   ObjectName name= new ObjectName("sky:SimpleMO");
   MOFactory.setValue(name,"State", "OK", null);


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 shows how to use a modification list for setting several properties.

CODE  EXAMPLE  7-15     Using a Modification List

   ModificationList modifList= new ModificationList();
   modifList.addElement( new Modification("State", "OK"));
   modifList.addElement( new Modification("Color", "green"));

   MOFactory.setValues(name, modifList);


Using the High-Level Interface to Set a Property

The steps in using the high-level interface to set a property are:

1. Getting a c-bean, as explained in "Using the High-Level Interface to Retrieve C-Beans" on page 89

2. Invoking the setter associated with the property as illustrated in CODE EXAMPLE 7-16

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");


Setting Properties Using the Cache of a C-Bean

Setting the properties in an agent and updating the cache involves:

CODE EXAMPLE 7-17 shows how to set the properties of the SimpleMO c-bean using the cache.

CODE  EXAMPLE  7-17     Setting Several Properties Using the Cache

   // Set several values in the agent and update the cache
   cbean.setGroupOper(true);

   // Build list of properties to be set and give the values
   cbean.setState("OK");
   cbean.setNbChanges("5");

   // Set the values in the agent and update the cache
   cbean.modifyObject();


Instantiating M-Beans

You can use an adaptor client to request that m-beans are instantiated in a remote Java Dynamic Management agent.

When requesting that m-beans be instantiated, it is possible to specify the class loader the agent must use to load the new class to instantiate. The class loader is specified using its object name. If no class loader is specified, the agent uses its default class loader.

When instantiating a remote m-bean, you can directly obtain a c-bean to represent the newly created m-bean. This is illustrated in CODE EXAMPLE 7-18.


CODE  EXAMPLE  7-18     Instantiating an M-Bean and a C-Bean

   String aClass= new
      String("example.mo.Simple.Simple");

   domain= MOFactory.getDomain();
   ObjectName name= new ObjectName(domain + ":SimpleMO");

   SimpleMO newMoi= (SimpleMO)
      MOFactory.cb_newMO(aClass, name, null);



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.

When instantiating an m-bean in the agent, you can explicitly request the object to be persistent using the cb_newDBMO method.

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 shows how to use the low-level interface of an adaptor client to delete an m-bean from the repository.


CODE  EXAMPLE  7-19     Using the Low-Level Interface to Delete an M--Bean

   ObjectName name=new ObjectName("sky:SimpleMO");
   MOFactory.deleteMO(name);


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 

   ObjectName name= new ObjectName("sky:SimpleMO");
   Vector result= MOFactory.getObject(name, null);
   if (result.isEmpty()) {
      return;
   }
   SimpleMO cbean= (SimpleMO) result.firstElement();

   cbean.deleteObject();




Copyright 1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303 U.S.A.
Copyright in French

Previous Next Contents Index