Solstice Enterprise Manager 4.1 Developing Java Applications Doc Set ContentsPreviousNextIndex


Chapter 5

Configuring the JDMK Agent/Behavior Service

The Java Dynamic Management Kit (JDMK) provides a set of Java classes and interfaces that enable you to develop network agents and services in Java. To manage JDMK agents by using Solstice Enterprise Manager (Solstice EM), you have to configure the JDMK agent/behavior service of Solstice EM.

This chapter explains how to configure the JDMK agent/behavior service of Solstice EM. It covers the following topics:

5.1 Overview

Configuring the JDMK agent/behavior service of Solstice EM makes your JDMK agents visible to the Java and C++ Solstice EM APIs.

Configuring the JDMK agent/behavior service involves:

5.1.1 Supported Versions of JDMK

Any JDMK agent that you want to manage by using Solstice EM must have been developed with version 4.0 of JDMK. Earlier versions of JDMK are not compatible with Solstice EM.

5.1.2 Prerequisites for Configuring the JDMK Agent/Behavior Service

Before you configure the JDMK agent/behavior service, ensure that:

5.2 Setting Up the JDMK MPA

The JDMK MPA and its associated event forwarder perform protocol translation between the JDMK information model and the Solstice EM information model. This translation allows MIS client applications to access and receive events from JDMK agents.

5.2.1 Configuring the JDMK MPA

The JDMK MPA is pre-configured for you. To override its configuration options, edit the start-up script /etc/rc2.d/S98jdmkmpa. The following table describes the JDMK MPA configuration options.

TABLE 5-1   JDMK MPA Configuration Options 
Option Description
EM_MIS_DEFAULT_HOST
Preconfigured to the same machine on which the JDMK MPA package is installed
EM_JDMK_MPA_DEFAULT_PORT
Port number to be used by JDMK MPA
Default: 5583
EM_JDMK_MPA_LOG_FILE
Path and name of log file that stores debugging and diagnostic messages
Default: /var/opt/SUNWconn/em/debug/em_mpa_jdmk.log



Note – If you change the JDMK MPA configuration options, you must stop and restart the JDMK MPA for your changes to take effect.

5.2.2 Starting and Stopping the JDMK MPA

If the JDMK component is installed, the JDMK MPA and the JDMK event forwarder start automatically when Solstice EM is started. If you need to start or stop the JDMK MPA and the JDMK event forwarder (for example, because you have changed its configuration), you can do so from the command line.

 

To Start the JDMK MPA and the JDMK Event Forwarder

 

To Stop the JDMK MPA and the JDMK Event Forwarder

5.3 Generating GDMO From Java Classes

Agents developed by using JDMK use the Java information model. For your JDMK agents to be visible to your Solstice EM applications, the class definitions of these agents must be represented in the GDMO information model, which Solstice EM uses internally.

To generate a representation in GDMO of your Java class definitions, use the Java to GDMO compiler (em_java2gdmo).

5.3.1 Class Definition Conversions

 

To Convert Java Interfaces to a GDMO Document

The arguments to em_java2gdmo are defined in the following table.

TABLE 5-2   em_java2gdmo Arguments 
Argument Meaning
-rootoid rootOid
Specifies the root of the object identifier (OID) that all GDMO objects are registered under. See Section 5.3.3 Assignment of Object Identifiers for more information.
-output directory
Specifies the directory where the generated GDMO document file is written.
-verbose
Specifies that the Java to GDMO compiler displays warning messages and error messages during compilation. By default it displays only error messages.
interfaceList
A list specifying one or more compiled Java MBean interfaces that you want to represent in GDMO. Each interface name you specify may include the Java package prefix. Separate each class name in the list with a space. The compiled Java classes must be stored at a location identified by the CLASSPATH environment variable.


5.3.2 Generation of GDMO Documents

The Java to GDMO compiler converts all the Java MBean interfaces in a Java package into one GDMO document file and names the file as follows:

em_jdmk_package.gdmo

Where package is the full name of the Java package containing the Java MBean interfaces with each dot (.) changed to an underscore (_). If the classes are not contained in a Java package, the file is named em_jdmk_unpackaged.gdmo.

For example, the interfaces SimpleMBean, InterfaceMBean and TroutMBean in the Java package com.sun.em.sample would be mapped to a single GDMO file named em_jdmk_com_sun_em_sample.gdmo containing these three object classes. See the following figure.


FIGURE 5-1   Java to GDMO Conversion

5.3.3 Assignment of Object Identifiers

The Java to GDMO compiler assigns all GDMO objects an object identifier (OID) of the form:

{ rootOid 
documentId objectType javaId }

The following table explains each part of this OID.

TABLE 5-3   Parts of an OID Assigned by em_java2gdmo  
Part Description
rootOid
The root of the OID as specified in the command you typed to start the Java to GDMO compiler. If you do not specify this root, it defaults to:
{iso(1) org(3) internet(1) 
private(4) enterprise(1) 
sun(42) products(2) management(2) em(2) jdmk(1)}.
documentId
A hashed, unsigned, 32-bit value based on the document name. Not used if you specified the root of the OID in the command to start the compiler.
objectType
A number based on the type of object being registered as listed below:

  • MANAGED OBJECT CLASS object type OID: 6

  • ATTRIBUTE object type OID: 7

  • ACTION object type OID: 9

  • NOTIFICATION object type OID: 5

  • javaId
    The ASCII values of the characters in the name of the object. Each character is separated from the one that precedes it by a period.
    For example, the class coolClass would translate to 99.111.111.108.67.108.97.115.115.
    < /font>


    5.3.4 Mapping Between Java Constructs and GDMO

    Once a set of Java MBean interfaces have been identified for translation, each interface is examined through introspection to create a set of objects analogous to the GDMO objects that will be generated from the Java MBean interface.

    The following table illustrates the mapping between Java classes, packages, methods, and GDMO objects.

    TABLE 5-4   Mapping Between Java Constructs and GDMO Constructs
    Java Construct GDMO Analog Object
    Package
    Module
    MBean Interface
    ManagedObjectClass
    Class derived from com.sun.em.jdmk.event.EMEvent
    Notification
    Getter, setter, or predicate method
    Attribute
    Other methods
    Action


    The first step in translation is to examine each of the Java MBean interface to be translated and decide if an interface will generate a ManagedObjectClass or Notification.

    If the class extends com.sun.em.jdmk.event.EMEvent, a Notification is generated. Otherwise, a ManagedObjectClass is generated.

    The attributes and actions of a managed object class are generated by examining each method in a Java MBean interface. Based on the method name, return type and parameter types, the Java to GDMO compiler does one of the following:

    5.3.4.1 MODULE Construct

    The GDMO MODULE is generated in the following form:

    MODULE "EM JDMK JavaPackageName"
    
    	 	 	 	
     	 	 	 	 managedObjectClasses
    
    	 	 	 	
     	 	 	 	 notifications
    
    END
    

    The following table describes the keywords in italics.

    TABLE 5-5   MODULE Keywords 
    Keyword Description
    JavaPackageName
    The name of the Java package being translated. If the classes are not contained in a Java package, the document is named unpackaged EM JDMK.
    managedObjectClasses
    The GDMO equivalent for all managed object classes translated from the source Java package.
    notifications
    The GDMO equivalent for all notifications translated from the source Java package.


    5.3.4.2 MANAGED OBJECT CLASS Construct

    The GDMO MANAGED OBJECT CLASS is generated in the following form:

    className MANAGED OBJECT CLASS
    
        DERIVED FROM "Rec. X.721 | ISO/IEC 10165-2 : 1992":top;
    
        CHARACTERIZED BY
    
    	 classNamePackage;
    
    REGISTERED AS { classOid };
    
    classNamePackage PACKAGE
    
        BEHAVIOUR interfaceBehaviour BEHAVIOUR DEFINED AS
    
        !This class represents java bean class className!;;
    
        ATTRIBUTES
    
    	 -- naming attribute
    
    classNameId GET,
    
      -- other attributes
    
    	 	 	 	 	 	 	 	
     attributeList;
    
        ACTIONS
    
    	 	 	 	 	 	 	 	
     actionList;
    
        NOTIFICATIONS
    
    "Rec. X.721 | ISO/IEC 10165-2 : 1992" :
    
                	 	 objectCreation,
    
     "Rec. X.721 | ISO/IEC 10165-2 : 1992" :
    
                	 	 objectDeletion,
    
    "Rec. X.721 | ISO/IEC 10165-2 : 1992" :
    
     attributeValueChange
    
    	 	 	 	 	 	 	 	
     notifications;
    
        ;
    
    className-jdmkAgent NAME BINDING
    
        SUBORDINATE OBJECT CLASS className AND SUBCLASSES;
    
        NAMED BY SUPERIOR OBJECT CLASS "EM JDMK":jdmkAgent;
    
        WITH ATTRIBUTE classNameId;
    
        CREATE;
    
        DELETE;
    
    REGISTERED AS { nameBindingOid };
    
    classNameId ATTRIBUTE
    
        WITH ATTRIBUTE SYNTAX EM-JDMK.JavaString;
    
        MATCHES FOR EQUALITY;
    
    REGISTERED AS { attributeOid};
    

    The following table describes the MANAGED OBJECT CLASS keywords in italics.

    TABLE 5-6   MANAGED OBJECT CLASS Keywords 
    Keyword Description
    className
    The Java MBean interface name with a lowercase first character and MBean string removed. A naming attribute classNameId of type GraphicString and its name binding are generated. The name binding forces Java objects into a flat hierarchy under an instance of jdmkAgent.
    actionList
    The list of actions the managed object class contains. Each action is of the form className-actionName, where className is as defined above, and actionName is the name of the original Java method.
    attributeList
    The list of attributes contained in the class. Each attribute is of the form className-attributeName, where className is as defined above, and attributeName is the Java getter/setter method name, minus the get or set prefix, with the first character in upper case.
    Each attribute is defined as a GET or a GET-SET attribute as follows:

  • GET if only a getter is present in the original Java class. Predicates are always GET attributes.

  • GET-SET if the class contained both getters and setters.

    Attributes have no initial or default values and are not mandatory.
  • notifications
    The list of all the custom notifications that a class supports and objectCreation, objectDeletion, and attributeValueChanged.
    ClassOid
    The OID of the managed object class. See Section 5.3.3 Assignment of Object Identifiers.
    nameBindingOid
    The OID of the generated name binding. See Section 5.3.3 Assignment of Object Identifiers.
    attributeOid
    The OID of the generated naming attribute. See Section 5.3.3 Assignment of Object Identifiers.


    5.3.4.3 ATTRIBUTE Construct

    The GDMO ATTRIBUTE is generated in the following form:

    className-attributeName ATTRIBUTE
    
    WITH ATTRIBUTE SYNTAX EM-JDMK.attributeType;
    
    REGISTERED AS { oid };
    

    The following table describes the keywords in italics.

    TABLE 5-7   ATTRIBUTE Objects Keywords 
    Keyword Description
    className
    The name of the managed object class to which the attribute belongs.
    attributeName
    The Java getter/setter method name, minus the get or set prefix, with the first character in upper case.
    attributeType
    The ASN.1 type based on the java type as described in Section 5.3.6 Mapping JDMK Java Types to ASN.1.
    oid
    The OID of the object. See Section 5.3.3 Assignment of Object Identifiers.


    5.3.4.4 ACTION Construct

    The GDMO ACTION is generated in the following form:

    className-actionName ACTION
    
    	 	BEHAVIOUR resetCountersBehaviour BEHAVIOUR DEFINED AS
    
    	 	!action maps with actionName method!;;
    
    	 	 WITH INFORMATION SYNTAX EM-JDMK.paramType;
    
    	 	 WITH REPLY SYNTAX EM-JDMK.returnType;
    
    REGISTERED AS { oid };
    

    The following table describes the ACTION objects keywords.

    TABLE 5-8   ACTION Objects Keywords 
    Keyword Description
    className
    Name of the managed object class to which the action belongs.
    actionName
    Name of the original Java method.
    attributeType
    The ASN.1 type based on the Java method's attribute type as described in Section 5.3.6 Mapping JDMK Java Types to ASN.1.
    returnType
    The ASN.1 type based on the Java method's return type as described in Section 5.3.6 Mapping JDMK Java Types to ASN.1.
    oid
    The OID of the object. See Section 5.3.3 Assignment of Object Identifiers.


    5.3.4.5 NOTIFICATION Construct

    The GDMO NOTIFICATION is generated in the following form:

    classNameAlarm NOTIFICATION
    
    	 BEHAVIOUR classNameAlarmBehaviour;
    
    	 WITH INFORMATION SYNTAX 
    
    	 Notification-ASN1Module.AlarmInfo
    
    	 AND ATTRIBUTE IDS
    
    	 probableCause	  probableCause,
    
    	 perceivedSeverity perceivedSeverity,
    
    	 additionalText	  additionalText;
    
    REGISTERED AS { oid };
    

    The following table describes the keywords in italics.

    TABLE 5-9   NOTIFICATION Objects Keywords 
    Keyword Description
    className
    The name of the class from which the alarm is generated, with a lower case first character. The attribute values are:

  • probableCause:
    The OID of the class that generated the alarm.

  • perceivedSeverity:
    Indeterminate.

  • additionalText:
    A list of class attributes and their values in the form:
    {attributeName1, value1}
    {
    attributeName2, value2}
    ...

  • oid
    The OID of the object. See Section 5.3.3 Assignment of Object Identifiers.


    5.3.5 Mapping of M-Bean Object Names

    The Java to GDMO compiler translates an m-bean's object name into a distinguished name. A translated distinguished name is in the following format:

    jdmkAgentId="agentTableType=JDMK"/JavaClassNameId="ObjectName"
    

    Where:

    The following table gives examples of the mapping of class names and m-bean names.

    TABLE 5-10   Examples of Mapping Class Names and M-Bean Names 
    M-Bean Name: myDomain:name=le1
    Description: Object of Java class Interface in package em.sample whose name attribute is le1.
    GDMO MOC Name: "EM JDMK em.sample":interface
    Distinguished Name: jdmkAgentId="agentTableType=JDMK"/interfaceId= "name=le1"
    M-Bean Name: myDomain:type=Interface
    Description: Object of Java class Interface in package em.sample. The naming attribute is null. This object is a singleton and is the only allowed instance of its class.
    GDMO MOC Name: "EM JDMK em.sample":interface
    Distinguished Name: jdmkAgentId="agentTableType=JDMK"/interfaceId= "type=Interface"
    M-Bean Name: myDomain:name=le1,desc=fddi
    Description: Object of Java class Interface in the default package (no package) whose name attribute is le1 and desc attribute is fddi.
    GDMO MOC Name: "unpackaged EM JDMK":interface
    Distinguished Name: jdmkAgentId="agentTableType=JDMK"/interfaceId= "name=le1,desc=fddi"


    5.3.6 Mapping JDMK Java Types to ASN.1

    The compiler supports only basic Java types. The following table lists the supported types with their ASN.1 counterparts. These types are legal return and attribute types for getters, setters, and predicate methods from which GDMO Analog objects are generated.

    TABLE 5-11   Java to GDMO Type Translation 
    Java Class ASN.1 Type
    String
    Graphic String
    Float
    Real
    Integer
    INTEGER (-2147483648 .. 2147483647)
    Long
    INTEGER (-9223372036854775808 .. 9223372036854775807)
    Boolean
    BOOLEAN
    Byte
    OCTET (SIZE (1))
    Short
    INTEGER (-32768..32767)
    void
    NULL
    Class that implements
    java.io.Serializable1
    OCTET STRING
    1 Action parameters only.


    5.3.7 Mapping Limitations

    Although mapping is done automatically, there are a few limitations:

    5.4 Compiling and Loading the Generated GDMO Files Into the MDR

    After you have generated a GDMO file representing your Java class definitions, you have to compile it and load it into the MetaData Repository (MDR) of Solstice EM.

    To compile a GDMO file, use the em_gdmo command.

    To load a GDMO file into the MDR, use the em_compose_all command.

    To compile and load a GDMO file in a single operation, use the Load Data Definitions (LDD) tool.

    For information on how to use em_gdmo, em_compose_all, and the LDD tool, refer to Management Information System (MIS) Guide.


    Note – The JDMK MPA must be running when you load generated GDMO files into the MDR.

    5.5 Configuring Persistent jdmkAgent Objects

    To configure jdmkAgent objects that reside persistently in the MIS MIT, use the utility included with MIS em_jdmk_config. The jdmkAgent objects provide the MIS with the necessary information to communicate with configured JDMK agents.

    Each jdmkAgent object contains three attributes. These attributes are described in the following table.

    TABLE 5-12   jdmkAgent Object Attributes 
    Attribute Description
    agentContainerId
    Names the jdmkAgent object. This name may be any string which the user chooses to represent a set of JDMK objects.
    For example, it may be the IP name where the JDMK agent resides in the network or it may be something which only represents a subset of the objects in the agent, such as topology objects. Think of this object as a named container to a set of JDMK objects.
    agentAddr
    A sequence containing the following:

  • agentAddr (default: value of agentContainerId)
    The IP name or IP address in dot format.

  • agentPort (default: 1099)
    Register the JDMK agent on this port. In your JDMK agent, you can specify what port the agent listens on.
    This feature allows you to run multiple agents or run other applications that need to use the default port.

  • agentAdaptor (default: RMI)
    A string containing the JDMK adapter that your agent is using. The only supported protocol is the remote method invocation (RMI) system.

  • agentDomain (default: defaultDomain)
    A string whose value is the Domain part of a JDMK object's name. You can only have one domain per jdmkAgent object. If your agent contains multiple domains, you will need to create a second jdmkAgent object with that domain.

  • supportedClasses
    A list of Java class names including the package name. Note that the package name is the Java "Package.Class" name and not the GDMO class name.


    5.5.1 Starting em_jdmk_config

    The easiest way to configure a jdmkAgent object is to use the command-line: em_jdmk_config -config yyy, where yyy is the IP name or address of the machine on which the JDMK agent is running. This command goes out and interrogates the agent and configures the jdmkAgent object for you.


    Note – The agent must be running and have the objects instantiated in order for this option to configure it. If there is an agent running with no objects, the jdmkAgent object will be configured, but the supportedClasses attribute will be empty.

    The other way to configure an agent is to set the various em_jdmk_config options:

    Usage: em_jdmk_config [-host] [-agent] [-help] [-get] 
    [-delete] 
    [-set] [-create] [-dump] [-classes] [-info]
    

    These options are described in the following table.

    TABLE 5-13   em_jdmk_config Options 
    Option Description
    -host mis
    MIS server name.
    -agent name
    Agent name for operation.
    -help
    Lists Help information.
    -get
    Prints the JDMK agent object specified with the -agent option.
    -delete
    Deletes the JDMK agent object specified with the -agent option.
    -set
    Sets the agent object (specified with the -agent option) with the information specified by the -info and -classes options.
    -create
    Creates the agent object (specified with the -agent option) with the information specified by the -info and -classes options.
    -dump
    Prints all JDMK agent objects.
    -info
    ipaddr port adaptor domain

    < li> ipaddr:
    Hostname or IP address on which the agent is running.

  • port:
    Port number on which the agent is listening for requests.

  • adaptor:
    The JDMK adaptor to be used for communication. Currently supports only RMI.

  • domain:
    The JDMK domain for this agent.

  • -classes
    List of JDMK classes.


    5.5.2 Configuration Examples

    Before running the examples, make sure that the CLASSPATH environment variable identifies the location of the compiled example class files.

    This section contains five configuration examples.

    5.6 Testing Your Agent With the MIS Objects Tool

    This section describes how to test your agents with the MIS Objects tool through an example. This example is based on the following three Java test files included with the JDMK example programs:

    Once you have created your jdmkAgent object, you will be able to see it using the MIS Objects tool.

    All the jdmkAgent objects may be found under the /systemId="host"/agentTableType=JDMK object. All the objects under each jdmkAgent object are the objects on that particular JDMK agent.

    To enable the Solstice EM JDMK MPA to locate your JDMK classes, ensure that the CLASSPATH environment variable identifies where they are located.

    By default, the JDMK MPA searches the following directories and jar files for Java classes:

    To ensure that the JDMK MPA can locate the sample Java classes, you can do one of two things:

     

    To Perform the Sample Test

    Before you perform the sample test, ensure that the CLASSPATH environment variable identifies where the JDMK classes and sample classes are located.

    1. Create a directory /var/tmp/jdmk.

    2. Copy SimpleStandard.java, SimpleStandardMBbean.java and MinimalAgent.java to /var/tmp/jdmk.

    3. Go to the /var/tmp/jdmk directory.

    4. Compile the sample Java classes:

    % javac *.java
    

    5. Convert Java to GDMO.

    % em_java2gdmo 
    SimpleStandardMbean
    

    em_jdmk_unpackaged.gdmo file is generated by this command.

    6. Load the GDMO into the MIS.

      1. As root, start the Load Data Definitions tool.
      2. Go to /var/tmp/jdmk and load the file em_jdmk_unpackaged.gdmo.

    7. Compile MinimalAgent.

    Add the following lines in the MinimalAgent.java file to load the SimpleStandardMBean and compile the MinimalAgent.java file.

    System.out.println("\nCreate 
    SimpleStandard");
    
    ObjectName objName = new 
    ObjectName("DefaultDomain:type=SimpleStandard");
    
    ObjectInstance simple = 
    server.createMBean("SimpleStandard", 
    objName);
    

    % javac MinimalAgent.java
    

    8. Start the JDMK agent.

    % java MinimalAgent
    

    9. Run the following configuration command:

    % em_jdmk_config -create -agent 
    yourhostname 
    -info yourhostname 1099 \ 
    name=RmiConnectorServer DefaultDomain -classes SimpleStandard
    

    10. Run the following configuration commands:

    % em_jdmk_config -dump
    
    % em_jdmk_config -get -agent 
    yourhostname
    

    11. Start up the MIS Objects tools from the Administration panel.

    12. Browse down the agentTableType=JDMK part of the tree and look for your agent object.

    13. Browse down your agent object and you should see the SimpleStandardMBean in the JDMK agent.

    14. Set the SimpleStandard-State attribute of the SimpleStandardMBean object.

    15. Get the SimpleStandard-State attribute of the SimpleStandardMBean object and verify that it has changed.

    16. Select the same SimpleStandardMBean object and execute the SimpleStandard-reset action.

    The action takes a NULL string. The SimpleStandard bean resets the state.

    17. Perform a get action and verify that the counters were reset.

    5.7 Sample Java Files

    This section explains how to convert the sample programs. It also gives you the definition of a sample Java class, SimpleStandard, in CODE EXAMPLE 5-1 and its equivalent GDMO class in CODE EXAMPLE 5-3 as generated by the Java to GDMO compiler.

    5.7.1 Converting Sample Java Classes Into GDMO

    The following example shows you how to convert SimpleStandardMBean.class into GDMO.

     

    To Convert Sample Java Classes

    1. Run the SimpleStandardMBean.class file through the compiler using the following command line:

    % em_java2gdmo 
    SimpleStandardMBean
    

    The compiler generates one file: em_jdmk_unpackaged.gdmo. This file contains the GDMO document unpackaged EM JDMK SimpleStandard which contains the GDMO classes.


    Note – If the SimpleStandardMBean class belongs to a package for example, em.sample then the resulting document is called "EM JDMK em.sample".

    2. Load the converted files into the MIS by using the Load Data Definitions tool or by typing the following command:

    % em_gdmo -host yourhost -file em_jdmk_em_sample.gdmo
    

    5.7.2 Listings of the Sample Java Classes

    The following code example contains a sample JDMK Agent.

    CODE EXAMPLE 5-1   MinimalAgent.java 
    import javax.management.ObjectInstance;
    import javax.management.MBeanServer;
    import javax.management.MBeanServerFactory;


    public class MinimalAgent {


    public static void main(String[] args) {

    // Instantiate the MBean server
    System.out.println("\nCreate the MBean server");
    MBeanServer server = MBeanServerFactory.createMBeanServer();

    // Create and start in the MBean server:
    // - an HTML protocol adaptor
    // - an HTTP connector server
    // - an RMI connector server
    try {
    com.sun.jdmk.Trace.parseTraceProperties();
    System.out.println("\nCreate and start an HTML protocol adaptor");
    ObjectInstance html = server.createMBean("com.sun.jdmk.comm.HtmlAdaptorServer", null);
    server.invoke(html.getObjectName(), "start", new Object[0], new String[0]);


    System.out.println("\nCreate and start an HTTP connector server");
    ObjectInstance http = server.createMBean("com.sun.jdmk.comm.HttpConnectorServer", null);
    server.invoke(http.getObjectName(), "start", new Object[0], new String[0]);


    System.out.println("\nCreate and start an RMI connector server");
    ObjectInstance rmi = server.createMBean("com.sun.jdmk.comm.RmiConnectorServer", null);
    server.invoke(rmi.getObjectName(), "start", new Object[0], new String[0]);



    System.out.println("\nCreate SimpleStandard");
    ObjectName objName = new ObjectName("DefaultDomain:type=SimpleStandard");
    < /font>
    ObjectInstance simple = server.createMBean("SimpleStandard", objName);

    } catch(Exception e) {
    e.printStackTrace();
    return;
    }


    System.out.println("\nNow, you can point your browser to http://localhost:8082/");
    System.out.println("or start your client application to connect to this agent.\n");
    }
    }


    The following code example contains a sample MBean interface.

    CODE EXAMPLE 5-2   SimpleStandardMBean.java 
    * This is the management interface explicitly defined for the "SimpleStandard" standard MBean.
    * The "SimpleStandard" standard MBean implements this interface
    * in order to be manageable through a JMX agent.
    *
    * The "SimpleStandardMBean" interface shows how to expose for management:
    * - a read/write attribute (named "State") through its getter and setter methods,
    * - a read-only attribute (named "NbChanges") through its getter method,
    * - an operation (named "reset").
    */
    public interface SimpleStandardMBean {


    /**
    * Getter: set the "State" attribute of the "SimpleStandard" standard MBean.
    *
    * @return the current value of the "State" attribute.
    */
    public String getState() ;

    /**
    * Setter: set the "State" attribute of the "SimpleStandard" standard MBean.
    *
    * @param <VAR>s</VAR> the new value of the "State" attribute.
    */
    public void setState(String s) ;

    /**
    * Getter: get the "NbChanges" attribute of the "SimpleStandard" standard MBean.
    *
    * @return the current value of the "NbChanges" attribute.
    */
    public Integer getNbChanges() ;

    /**
    * Operation: reset to their initial values the "State" and "NbChanges"
    * attributes of the "SimpleStandard" standard MBean.
    */
    public void reset() ;
    }

    The following code example contains a sample MBean implementation.

    CODE EXAMPLE 5-3   SimpleStandard.java 
    * Simple definition of a standard MBean, named "SimpleStandard".
    *
    * The "SimpleStandard" standard MBean shows how to expose attributes and
    * operations for management by implementing its corresponding
    * "SimpleStandardMBean" management interface.
    *
    * This MBean has two attributes and one operation exposed
    * for management by a JMX agent:
    * - the read/write "State" attribute,
    * - the read only "NbChanges" attribute,
    * - the "reset()" operation.
    *
    * This object also has one property and one method not exposed
    * for management by a JMX agent:
    * - the "NbResets" property,
    * - the "getNbResets()" method.
    */


    public class SimpleStandard implements SimpleStandardMBean {


    /*
    * -----------------------------------------------------
    * CONSTRUCTORS
    * -----------------------------------------------------
    */


    /* "SimpleStandard" does not provide any specific constructors.
    * However, "SimpleStandard" is JMX compliant with regards to
    * contructors because the default contructor SimpleStandard()
    * provided by the Java compiler is public.
    */


    /*
    * -----------------------------------------------------
    * IMPLEMENTATION OF THE SimpleStandardMBean INTERFACE
    * -----------------------------------------------------
    */


    /**
    * Getter: get the "State" attribute of the "SimpleStandard" standard MBean.
    *
    * @return the current value of the "State" attribute.
    */
    public String getState() {
    return state;
    }


    /**
    * Setter: set the "State" attribute of the "SimpleStandard" standard MBean.
    *
    * @param <VAR>s</VAR> the new value of the "State" attribute.
    */
    public void setState(String s) {
    state = s;
    nbChanges++;
    }


    /**
    * Getter: get the "NbChanges" attribute of the "SimpleStandard" standard MBean.
    *
    * @return the current value of the "NbChanges" attribute.
    */
    public Integer getNbChanges() {
    return new Integer(nbChanges);
    }


    /**
    * Operation: reset to their initial values the "State" and "NbChanges"
    * attributes of the "SimpleStandard" standard MBean.
    */
    public void reset() {
    state = "initial state";
    nbChanges = 0;
    nbResets++;
    }


    /*
    * -----------------------------------------------------
    * METHOD NOT EXPOSED FOR MANAGEMENT BY A JMX AGENT
    * -----------------------------------------------------
    */


    /**
    * Return the "NbResets" property.
    * This method is not a Getter in the JMX sense because
    * it is not exposed in the "SimpleStandardMBean" interface.
    *
    * @return the current value of the "NbResets" property.
    */
    public Integer getNbResets() {
    return new Integer(nbResets);
    }


    /*
    * -----------------------------------------------------
    * ATTRIBUTES ACCESSIBLE FOR MANAGEMENT BY A JMX AGENT
    * -----------------------------------------------------
    */


    private String state = "initial state";
    private int nbChanges = 0;


    /*
    * -----------------------------------------------------
    * PROPERTY NOT ACCESSIBLE FOR MANAGEMENT BY A JMX AGENT
    * -----------------------------------------------------
    */


    private int nbResets = 0;
    }

    The following code example contains the em_jdmk_unpackaged.gdmo file.

    CODE EXAMPLE 5-4   em_jdmk_unpackaged.gdmo 


    simpleStandard MANAGED OBJECT CLASS
    DERIVED FROM "Rec. X.721 | ISO/IEC 10165-2 : 1992":top;
    CHARACTERIZED BY
    simpleStandardPackage;
    REGISTERED AS { em-jdmk 162229001 6 115 105 109 112 108 101 83 116 97 110 100 97 114 100 };


    simpleStandardPackage PACKAGE
    BEHAVIOUR simpleStandardBehaviour BEHAVIOUR DEFINED AS
    !This class represents the Java Bean classSimpleStandardMBean !;;
    ATTRIBUTES
    simpleStandardId GET,
    simpleStandard-NbChanges GET,
    simpleStandard-State GET-REPLACE;


    ACTIONS
    simpleStandard-reset;


    NOTIFICATIONS
    "Rec. X.721 | ISO/IEC 10165-2 : 1992" :
    objectCreation,
    "Rec. X.721 | ISO/IEC 10165-2 : 1992" :
    objectDeletion,
    "Rec. X.721 | ISO/IEC 10165-2 : 1992" :
    attributeValueChange;


    ;


    simpleStandard-jdmkAgent NAME BINDING
    SUBORDINATE OBJECT CLASS simpleStandard AND SUBCLASSES;
    NAMED BY SUPERIOR OBJECT CLASS "EM MPA JDMK":jdmkAgent;
    WITH ATTRIBUTE simpleStandardId;
    CREATE;
    DELETE;
    REGISTERED AS { em-jdmk 162229001 1 115 105 109 112 108 101 83 116 97 110 100 97 114 100 45 106 100 109 107 65 103 101 110 116 };


    simpleStandardId ATTRIBUTE
    WITH ATTRIBUTE SYNTAX EM-JDMK.JavaString;
    MATCHES FOR EQUALITY;
    REGISTERED AS { em-jdmk 162229001 7 115 105 109 112 108 101 83 116 97 110 100 97 114 100 73 100 };


    simpleStandard-NbChanges ATTRIBUTE
    WITH ATTRIBUTE SYNTAX EM-JDMK.JavaInteger;
    REGISTERED AS { em-jdmk 162229001 7 115 105 109 112 108 101 83 116 97 110 100 97 114 100 45 78 98 67 104 97 110 103 101 115 };


    simpleStandard-State ATTRIBUTE
    WITH ATTRIBUTE SYNTAX EM-JDMK.JavaString;
    REGISTERED AS { em-jdmk 162229001 7 115 105 109 112 108 101 83 116 97 110 100 97 114 100 45 83 116 97 116 101 };


    simpleStandard-reset ACTION
    BEHAVIOUR simpleStandard-resetBehaviour BEHAVIOUR DEFINED AS
    !action derived from SimpleStandardMBean.reset(...) Java method!;;
    WITH INFORMATION SYNTAX EM-JDMK.JavaVoid;
    WITH REPLY SYNTAX EM-JDMK.JavaVoid;
    REGISTERED AS { em-jdmk 162229001 9 115 105 109 112 108 101 83 116 97 110 100 97 114 100 45 114 101 115 101 116 };


    END



    Sun Microsystems, Inc.
    Copyright information. All rights reserved.
    Doc Set  |   Contents   |   Previous   |   Next   |   Index