Previous Next Contents Index


D


Java Beans Development Kit Example

This example shows how any JavaBeans component can be made manageable by a Java Dynamic Management agent. To make a JavaBeans component manageable, all you need to do is add code required to enable it to register itself with the Core Management Framework. You do not need to modify any existing code.

The example shows an agent and an m-bean that are designed to be loaded into the BeanBox as .jar files. Once these objects have been instantiated, you can manage the agent through an adaptor client, such as the Java Dynamic Management M-Bean Browser.


Directories and Files

The files contained in the example directory are described in the following subsections.

The directory containing the source files for this example depend on the platform shown in the table.


Platform
Directory

Solaris

installDir/SUNWconn/jaw/examples/src/agentbean

Windows NT

installDir\SUNWconn\jaw\examples\src\agentbean


AgentMain.java
AgentMain.java provides an implementation of a Java Dynamic Management agent in which the core management framework object is declared as static. This class is designed to be loaded into the BeanBox application by means of a .jar file. The AgentMain class, once instantiated, can interact with any m-bean instantiated in the BeanBox application, provided the m-bean contains the code required to register itself with the repository.

TextSample.java
TextSample.java defines a simple m-bean for use with this example. It contains in its constructor the code required to register itself with the m-bean repository, as shown in CODE EXAMPLE D-1.

Makefile
The Makefile compiles the example Java classes and creates the manifest files and .jar files required to enable the example to be used with the BeanBox application.


Making a Manageable JavaBeans Component

The Java Dynamic Management agent, once instantiated, can manage any bean instantiated in the BeanBox that contains the lines in its code shown in CODE EXAMPLE D-1.

CODE  EXAMPLE  D-1     Registering an M-Bean With the Repository


        try{
((Framework)AgentMain.getFramework()).addObject((Object)this, new
ObjectName(((Framework)AgentMain.getFramework()).getDomain()+":com.sun.jaw.
imp.base.TextSample"));
} catch (Exception e) {
e.printStackTrace();
}


In addition, TextSample.java contains the import lines for Java Dynamic Management Kit packages shown in CODE EXAMPLE D-2:


CODE  EXAMPLE  D-2     Import Lines for Packages


import com.sun.jaw.reference.agent.cmf.*;
import com.sun.jaw.reference.common.*;



Compiling the Agent

Before compiling the example, copy the contents of the directory containing the example to another location. The file access permissions of the directories under the home directory of your Java Dynamic Management Kit installation do not allow write access to ordinary users.

1. Copy the source files of this example to another directory.

2. Change to the directory where you copied the example files.

3. Edit the JAWPATH in the Makefile to specify the directory to which the compiled Java classes will be written.

4. Compile the agent application by typing:

prompt% make

This will create the JAR files AgentMain.jar and TextSample.jar, which can then be loaded into the BeanBox.


Using the Java Beans Development Kit With the Agent Example

Before using this example, ensure that your class path defines the paths to:

 

To Set a Property Using the BeanBox

1. Start the BeanBox:

prompt% java sun.beanbox.BeanBoxFrame

The path to this command must be defined either in the command you type or in your PATH variable.

2. Load these jar files into the BeanBox:

3. Instantiate these classes, starting with AgentMain.

When you instantiate TextSample, the Properties window contains a field named text.

4. Use the Properties window to change the context of the text field.

To view the changes, preview the m-bean using either the job tool (See "The job Tool" on page 107) or a Web browser (See "The M-Bean Browser Web Page" on page 102).



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

Previous Next Contents Index