Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 2. Tutorial Example | ![]() |
The SimpleAgent example shows the code required in an agent for:
Initializing the framework
Adding the metadata service
Adding adaptors for two protocols
The Java source code of this example is shown in Example 2-2.
// Copyright (c) 03/12/99, by Sun Microsystems, Inc. // All rights reserved. // "@(#)SimpleAgent.java 3.3 99/03/12 SMI" import com.sun.jaw.reference.common.* ; import com.sun.jaw.reference.agent.cmf.* ; import com.sun.jaw.reference.agent.services.*; import com.sun.jaw.impl.agent.services.light.* ; public class SimpleAgent { public static void main(String argv[]) { try { String domain = "defaultDomain" ; // Set up the Framework. Framework cmf = new Framework() ; // Set up the Metadata service. String mtdSrvClass = "com.sun.jaw.impl.agent.services.light.MetaDataSrv" ; String mtdSrvName = domain + ":" + ServiceName.META ; cmf.newObject(mtdSrvClass, mtdSrvName, null) ; // Set up the RMI Adaptor. String rmiSrvClass = "com.sun.jaw.impl.adaptor.rmi.AdaptorServerImpl" ; String rmiSrvName = domain + ":" + ServiceName.ADAPTOR + ".protocol=rmi" ; cmf.newObject(rmiSrvClass, rmiSrvName, null) ; // Set up the HTTP Adaptor. String httpSrvClass = "com.sun.jaw.impl.adaptor.http.AdaptorServerImpl" ; String httpSrvName = domain + ":" + ServiceName.ADAPTOR + ".protocol=http" ; cmf.newObject(httpSrvClass, httpSrvName, null) ; } catch(Exception e) { System.out.println("Got an exception !") ; e.printStackTrace() ; System.exit(1) ; } } } |
To initialize the framework, create an instance of the Java class com.sun.jaw.reference.agent.cmf.Framework. Example 2-3 shows code for initializing the framework. In this example, the default constructor of the com.sun.jaw.reference.agent.cmf.Framework is used.
Example 2-3. Initializing the Framework
import com.sun.jaw.reference.common.* ; import com.sun.jaw.reference.agent.cmf.* ; import com.sun.jaw.reference.agent.services.*; import com.sun.jaw.impl.agent.services.light.* ; ... // Set up the Framework Framework cmf = new Framework() ; |
To add an instance of the metadata service supplied with the Java Dynamic Management Kit, create an instance of the Java class com.sun.jaw.impl.agent.services.light.MetaDataSrv and pass this instance to the framework. Example 2-4 shows code for adding the metadata service to a Java Dynamic Management agent.
Example 2-4. Adding the Metadata Service
// Set up the Metadata service. String mtdSrvClass = "com.sun.jaw.impl.agent.services.light.MetaDataSrv" ; String mtdSrvName = domain + ":" + ServiceName.META ; cmf.newObject(mtdSrvClass, mtdSrvName, null) ; |
For a Java Dynamic Management agent to be manageable, it must contain at least one adaptor. Example 2-5 shows code for adding the HTTP/TCP adaptor to a Java Dynamic Management agent. In this example, the newObject() method of the Framework class is called to create an instance of the adaptor.
Example 2-5. Adding an Adaptor
// Set up the HTTP Adaptor. String httpSrvClass = "com.sun.jaw.impl.adaptor.http.AdaptorServerImpl" ; String httpSrvName = domain + ":" + ServiceName.ADAPTOR + ".protocol=http" ; cmf.newObject(httpSrvClass, httpSrvName, null) ; |
Before running the example agent, make sure that the Java Dynamic Management base agent is not running on the same machine. You must also make sure that the CLASSPATH environment variable is set correctly. The class path must include the directory which contains the compiled SimpleAgent class. It must also include the directory containing Java Dynamic Management Kit classes; see Appendix B for further details.
In the Solaris operating environment, type
prompt% installDir/SUNWconn/jaw/bin/jaw stop |
In the Windows NT operating environment, use the Task Manager, or in the window where you started the base agent, type Control+C.
prompt% java SimpleAgent |
![]() | ![]() | ![]() |
Developing an M-Bean | ![]() | Generating a C-Bean |