Solstice Enterprise Manager 4.1 Developing Java Applications Doc Set ContentsPreviousNextIndex


Chapter 2

Using the Java Management Interface API

The JMI API provides a set of classes and methods that allow effective access to the Solstice Enterprise Manager (Solstice EM) Management Information Server (MIS) without requiring detailed specification of the underlying MIS or mechanism. For most applications, the high-level usage of the JMI API is sufficient for all interaction with the Solstice EM MIS.

This chapter describes the following topics:

These topics are arranged, as far as possible, to reflect the order which you need to follow when creating Java management applications. For example, before handling events, you should have defined a Platform object, instantiated handlers, and registered event types. This sequence will become clear as you go through this chapter.

Also note, the code samples used in this chapter are based on the sample JMI application that is provided in Section 2.7 Sample JMI Application.

2.1 Overview

The JMI API enables you to develop client applications that perform the following operations:

For example:

Because of its generic nature, the JMI API could be used to provide the same functionality that other specialized Java APIs provide, such as the Java Alarm API and the Java Topology API.

2.1.1 Java Management Tasks

The JMI API allows you to perform the following tasks:

These tasks could be performed using the following main classes of the JMI API:

The interaction between JMI API classes and the MIS is illustrated in the following figure.


FIGURE 2-1   Interaction Between JMI API Classes and the MIS

The MOHandle, MOHCollectionByRule, and MOHCollectionEnum classes provide the necessary functionality for managing objects over the network, whether individually (MOHandle) or as a collection (MOHCollectionByRule and MOHCollectionEnum).

The EventReportListener interface allows you to define event handler classes and their handler methods that will be invoked upon event delivery.

2.1.2 Java Management Task Flow

When creating Java management applications, keep in mind the task flow as illustrated in the following figure.


FIGURE 2-2   Task Flow in a Java Management Application

2.2 Instantiating the Platform Class

An instance of the Platform class represents an actual or potential connection to a Solstice EM MIS, along with all the implied semantics of the particular MIS. You use a Platform object to gain access to an MIS.

The first step in creating a JMI application is to define the server instance that allows your application to talk to the MIS. You can do this by creating an instance of the Platform class. See FIGURE 2-3.


Note – You can instantiate multiple Platform objects in your application so that it can connect to multiple MIS environments.


FIGURE 2-3   Platform Objects

The Platform object you create becomes the key that the MOHandle and MOHCollection classes you instantiate later will use to access management information.

In addition, the Platform object allows you to register Callbacks (see Section 2.4 Registering Event Listeners) and allows you to perform access control.

For more information about the Platform class, refer to Chapter 2 in Java API Reference.

To create a Platform object, you need to provide the following four parameters:

Following is a code segment that creates a Platform object:

plat = new Platform(host, mis, user, passwd);

2.3 Defining Local Representation of Managed Objects

When you create a JMI application, you must define a local representation of the network's Managed Object Instances (MOI) that your application will manage. You can perform this task by instantiating the following JMI API classes:

2.3.1 Instantiating the MOHandle Class

An instance of the MOHandle class is the local representation of an actual or potential MOI. Typically, an MOI is a managed object that represents a physical resource: a host, server, router, subnet (that is, the representation of a physical device), or a conceptual entity (a line, a queue, or some other aspect of network operation that can be represented as a managed object). See the following figure.


FIGURE 2-4   MOHandle Object

Think of the MOHandle object as the object itself, even though the actual object is across the network, or in the MIS. MOHandle objects give you access to the object's methods and attributes.

To instantiate the MOHandle class, you need to provide the following three parameters:

The following code example creates an MOHandle instance:

CODE EXAMPLE 2-1   Instantiating the MOHandle Class
 String dn = new String("topoTypeDBId=NULL/topoTypeId=\"Host\""); 
 System.out.print("This ex. retrieves the attributes of: " + dn);
 System.out.println("and prints them on the screen.");
 String className = new String("topoType");
 // instantiate a MOHandle with the object name and class 
 // call an MGet to retrieve all the information about the MOHandle 
 // from the mis into the MOHandle.
 moh = new MOHandle(dn, className, plat); 
 moh.MGet(TIMEOUT);  

This code segment creates the MOHandle object moh, and uses its MGet method to retrieve all the attribute values of the MOIs it represents from the network.

For more information about the MOHandle class, refer to Chapter 2 in Java API Reference.

2.3.2 Instantiating MOHCollectionByRule and MOHCollectionEnum Classes

When creating JMI applications, it is often more efficient to treat a set of MOIs as one collection. In addition, it is sometimes necessary to maintain information about a set of MOIs in an MIS and be able to manage the set as a whole.

For example, your application may contain a GUI element that displays the MOIs in a particular subtree of the management information tree (MIT) in an MIS. The GUI element will have to refresh the screen whenever a change occurs in the subtree it represents. In addition, your application may allow network operators to delete or change the attributes of a particular subtree in the MIT. See the following figure.


FIGURE 2-5   Example of MOHCollectionByRule Usage

Although you can use MOHandle objects to perform these operations, the burden is on you to provide the necessary mechanism for creating and maintaining sets of these objects.

For this reason, the JMI API provides the MOHCollectionByRule and the MOHCollectionEnum classes. These are similar classes that allow you to represent a group of MOHandle objects. The following table compares the two classes.

TABLE 2-1   MOHCollectionByRule versus MOHCollectionEnum
Class Description
MOHCollectionByRule

  • Member MOHandle objects satisfy a particular rule

  • Member MOHandle objects cannot be user-manipulated

  • Tracks all the MOHandles within the collection, based on changes in the network for these MOHandles

  • MOHCollectionEnum

  • Member MOHandle objects are added with no constraints

  • Member MOHandle objects can be user-manipulated


  •  

    To Instantiate the MOHCollectionByRule Class

    Following is an example of a code segment that creates an MOHCollectionByRule object.

    CODE EXAMPLE 2-2   Creating an MOHCollectionByRule Object
    MOHCollectionByRule app_instances = null;
    
    	String base = new String("subsystemId=\"EM-MIS\"");
    
    	System.out.println("Base object is " + base);
    
    	String scope = new String("LV(1)");
    
    	System.out.println("Scope is " + scope);
    
    	String filter = new String("CMISFilter(item:equality: 
    {objectClass, emApplicationInstance})");
    	 	 	 
    
    	System.out.println("Filter used " + filter);
    
    	// get all app instance objects
    
    	try {
    
    	app_instances =  new MOHCollectionByRule(base, scope, filter, plat);
    
    	System.out.println("constructed album");
    
    	app_instances.populate(TIMEOUT);
    
    	System.out.println("populated the MOHCollectionByRule ");
    

    This code segment creates the MOHCollectionByRule object app_instances using the base, scope, filter, and plat objects as parameters and populates it using the populate method.

     

    To Instantiate the MOHCollectionEnum Class

    2.4 Registering Event Listeners

    The most important aspect of a JMI application is the ability to be able to update information about the MOIs the application is managing. This is done by registering event listeners and defining the handlers (discussed in Section 2.5 Handling Events) that will be invoked when an event indicating a change in the network occurs.

    The JMI API allows you to register six types of events as shown in the following table:

    TABLE 2-2   Event Types
    Event Description
    AttributeValueChange
    Gets generated when one or more attribute values change for an MOI
    ObjectCreation
    Gets generated when an MOI object is created
    ObjectDeletion
    Gets generated when an MOI object is deleted
    RawEvent
    Any event
    MOHandleIncluded
    Gets generated when an object is added to a collection
    MOHandleExcluded
    Gets generated when an object is deleted from a collection


    These events can be registered against Platform, MOHandle, MOHCollectionByRule, and MOHCollectionEnum objects as shown in the following table.

    TABLE 2-3   Event Type Mapping 
    Event Level Description
    Platform
    You can register Callbacks for the following events that affect any object in the network defined by a Platform object:

  • Attribute value change events

  • Object deletion events

  • Object creation events

  • Raw events

  • MOHandle
    Registers Callbacks for the following events that affect the MOI represented by an MOHandle object:

  • Attribute value change events

  • Object deletion events

  • Object creation events

  • Raw events

  • MOHCollectionByRule
    Registers Callbacks for the following events that affect any MOHandle object in an MOHCollectionByRule object's collection:

  • Attribute value change events

  • Object deletion events

  • Object creation events

  • Raw events

  • MOHandle included events

  • MOHandle excluded events

  • MOHCollectionEnum
    Registers Callbacks for the following events that affect any MOHandle object in an MOHCollectionEnum object's collection:

  • Attribute value change events

  • Object deletion events

  • Object creation events

  • Raw events


  •  

    To Register an Event Listener

    1. Define a class that implements the EventReportListener interface of the JMI API.

    Part of defining this class is to define the interface's handler method that will be invoked when the corresponding event arrives (see Section 2.5 Handling Events).

    2. Register for Callbacks for the events that you're interested in using the appropriate methods of the Platform, MOHandle, MOHCollectionByRule, or MOHCollectionEnum objects.

    For example:

    Following is an example of a code segment that registers AttributeValueChange, ObjectCreation, and ObjectDeletion event listeners.

    CODE EXAMPLE 2-3   Registering Event Listeners 
    public class MOHandleEvent implements EventReportListener {
    
        public static final double TIMEOUT = 3600.0;
    
        static Platform plat = null;
    
    ..................
    
    ..................
    
    ..................
    
    // register for Callbacks for AVC, ObjectCreation and
    
    // ObjectDeletion
    
    System.out.println("MOHandle is logId=\"AlarmLog\"");
    
    System.out.println("Registering for events for MOHandle  ");
    
    moh.addAttributeValueChangeListener(gt);
    
    moh.addObjectCreationListener(gt);
    
    moh.addObjectDeletionListener(gt);
    
    System.out.println("Waiting for events ...");
    
    // wait here as the events arrive from mis.
    
    // user can modify an attribute here for AlarmLog to
    
    // verify the event delivery.
    
    ..................
    
    ..................
    
    ..................
    

    For more information about registering event listeners, refer to the method descriptions of the Platform, MOHandle, MOHCollectionByRule, and MOHCollectionEnum classes in Chapter 2 "Java PMI API" in Java API Reference.

    2.5 Handling Events

    In addition to registering event listeners, you need to define the handlers that will be invoked in response to an event. For each listener object you create, you must define the body of its handler method.

    CODE EXAMPLE 2-4 defines an event listener's handler method.

    The following code prints the event type, the name of the object that generated the event, the name of the class of the object that generated the event, and, in the case of a raw event, information about the event.

    CODE EXAMPLE 2-4   Defining a handler
    public void handler(EventReport ind) {
     
    String type = ind.getName();
    
    System.out.println("Event Type = " + type);
    
    System.out.println("Object Name = " + ind.getMOName());
    
    System.out.println("Object Class = " + ind.getMOClass());
    
                    try {
    
    System.out.println("Event Info = " + ind.getInfo());
    
    AbstractData abs = ind.getInfoRaw();
    
    System.out.println("Event Info Raw = " + abs.getStr());
    
    } catch (JmiException ex) { ex.printStackTrace(); }
    
    }
    

    2.6 C++ Equivalents for the JMI API Classes

    The following table shows the C++ PMI classes that are equivalent to the JMI API classes.

    TABLE 2-4   C++ Equivalents for JMI API Classes
    JMI API Class Equivalent C++ PMI Class
    Platform
    Platform
    MOHandle
    Image
    MOHCollectionByRule
    Album
    MOHCollectionEnum
    Album
    AbstractData
    Morf
    EventReport
    CurrentEvent


    2.7 Sample JMI Application

    This section lists the code of the following five sample applications that use the JMI API:

    2.7.1 PlatformEvent.java

    The following code example shows you how to:

    • Instantiate the Platform class.
    • Register Callbacks for attribute value change, object creation, and object deletion.
    • Verify event delivery

      CODE EXAMPLE 2-5   PlatformEvent.java 
      /*
      
       * Copyright (c) 12/08/97 Sun Microsystems, Inc.
      
       * All Rights Reserved.
      
       */
      
      import com.sun.em.api.pmi.*;
      
      import java.net.*;
      
      import java.util.*;
      
      public class PlatformEvent implements EventReportListener {
      
          public static final double TIMEOUT = 3600.0;
      
          static void usage() {
      
      	 	 System.err.println("Usage:");
      
      	 	 System.err.println("java PlatformEvent <servername> <mis-name> <user-name> <password>");
      
      	 	 System.err.println("\t-Run the example with <servername> as the remote server and <misname> where EM mis is running.");
      
      	 	 System.exit(-1);
      
          }
      
      	 public static void main(String args[]) {
      
      	 
      
      	 	 if (args.length < 4)
      
      	 	 	 usage();
      
      	 	 PlatformEvent gt0, gt1, gt2;
      
      	 	 MOHandle moh = null;
      
      	 	 try { 
      
      	 	 	 gt0 = new PlatformEvent(args[0], args[1], args[2], args[3]); 
      
      	 	  }
      
      	 	 catch (JmiException ex) {System.out.println(ex); }
      
      	 }
      
      	 public void handler(EventReport ind) {
      
      	 	 	 String type = ind.getName();
      
      	 	 	 System.out.println("Event Type = " + 
      type);
      
      	 	 	 System.out.println("Object Name = " + ind.getMOName());
      
      	 	 	 System.out.println("Object Class = " + ind.getMOClass());
      
                      try {
      
                          System.out.println("Event Info = " + ind.getInfo());
      
                          AbstractData abs = ind.getInfoRaw();
      
                          System.out.println("Event Info Raw = " + abs.getStr());
      
                      } catch (JmiException ex) { ex.printStackTrace(); }
      
      	 }
      
      	 public PlatformEvent(String host, String mis, String user, String passwd) throws JmiException {
      
      	 try {
      
      	 	 // instantiate Platform
      
      	 	 plat = new Platform(host, mis, user, passwd);
      
      	 	 // register for events
      
      	 	 System.out.println("Registering for events for Platform  ...");
      
      	 	 plat.addAttributeValueChangeListener(this);
      
      	 	 plat.addObjectCreationListener(this);
      
      	 	 plat.addObjectDeletionListener(this);
      
      	 	 System.out.println("Callbacks registered");
      
      	 	 System.out.println("Waiting for events ...");
      
      	 }
      
      	 catch (JmiException ex) { throw ex; } 
      
      	 }
      
      	 Platform plat = null;
      
      	 private static final String sccsID =
      "@(#)PlatformEvent.java 1.4 97/12/08 Sun Microsystems, Inc.";
      }
      

      .

    2.7.2 MOHandleTest.java

    The following code example shows you how to:

    • Get attributes of an MOHandle.
    • Create an MOHandle (logId="testLog") after setting attributes.

      CODE EXAMPLE 2-6   MOHandleTest.java 
      /*
      
       * Copyright (c) 01/27/98 Sun Microsystems, Inc. All Rights Reserved.
      
       */
      
      import com.sun.em.api.pmi.*;
      
      import java.net.*;
      
      import java.util.*;
      
      public class MOHandleTest {
      
          public static final double TIMEOUT = 3600.0;
      
          static Platform plat = null;
      
          static void usage() {
      
      	 System.err.println("Usage:");
      
      	 System.err.println("java MOHandleTest <servername> <mis-name> <username> <password>");
      
      	 System.err.println("\t-Run the example with <servername> as the remote server and <misname> where EM mis is running.");
      
      	 System.exit(-1);
      
          }
      
      	 public static void main(String args[]) {
      
      	 
      
      	 	 MOHandleTest gt = null;
      
      	 	 MOHandle moh = null;
      
      	 	 if (args.length < 4) usage();
      
      	 	 try { gt = new MOHandleTest();  
      
      	 	 // instantiate Platform with the supplied server name and
      
      	 	 // mis name.
      
      	 	 plat = new Platform(args[0],args[1], args[2],args[3]);
      
              String [] attrNames = null;
      
      	 	 String dn = new String("topoTypeDBId=NULL/topoTypeId=\"Host\""); 
      
      	 	 System.out.print("This example retrieves the attributes of: " + dn);
      
      	 	 System.out.println("and prints them on the screen.");
      
      	 	 String className = new String("topoType");
      
      	 	 // instantiate a MOHandle with the object name and class 
      
      	 	 // call a MGet to retrieve all the information about the MOHandle 
      
      	 	 // from the mis into the MOHandle.
      
      	 	 moh = new MOHandle(dn, className, plat); 
      
      	 	 moh.MGet(TIMEOUT);  
      
      	 	 // verify that the object exists in the network.
      
      	 	 if (moh.exists() == false)
      
      	 	 	 System.out.println(dn + "does not exist");
      
      	 	 // Get the attribute names of the MOHandle
      
              attrNames = moh.getAttrNames(); 
      
      	 	 System.out.println("The attributes for the object are ..");
      
              for (int i=0; i <attrNames.length; i++)
      
                  System.out.println("Attribute: " + attrNames[i]);
      
      	 	 // second part of the example. Create a object in the mis.
      
      	 	 String testdn = new String("logId=\"testLog\""); 
      
      	 	 String testclass = new String("log");
      
      	 	 System.out.println("Create a object " + testdn + "in mis");
      
      	 	 // instantiate the MOHandle and retrieve the attribute info.
      
      	 	 MOHandle mo = new MOHandle(testdn, testclass, plat); 
      
      	 	 mo.MGet(TIMEOUT);  
      
      	 	 if (mo.exists()) {
      
      	 	 	 System.out.println("object exists! quitting ...");
      
      	 	 	 System.exit(11);
      
      	 	 }
      
      	 	 
      
      	 	 mo.setStr("logFullAction", "wrap");
      
      	 	 System.out.println("set logFullAction");
      
      	 	 mo.setStr("administrativeState", "unlocked");
      
      	 	 System.out.println("set administrativeState");
      
      	 	 mo.setStr("maxLogSize", "1000000");
      
      	 	 System.out.println("set maxLogSize");
      
      	 	 mo.setStr("discriminatorConstruct", "or: {}");
      
      	 	 System.out.println("set discriminatorConstruct");
      
      	 	 mo.MCreate(TIMEOUT);  
      
      	 	 }
      
      	 	 catch (JmiException ex) {System.out.println(ex); }
      
      	 	 System.exit(2);
      
      	 }
      
      	 public MOHandleTest() throws JmiException { }
      
         private static final String sccsID =
      "@(#)MOHandleTest.java 1.4 98/01/27 Sun Microsystems, Inc.";
      }
      

    2.7.3 MOHandleEvent.java

    The following code example shows you how to:

    • Register Callbacks for an AttributeValueChange, ObjectCreation, and ObjectDeletion events or an MOHandle object.
    • Verify event delivery.

      CODE EXAMPLE 2-7   MOHandleEvent.java 
      /*
      
       *  Copyright (c) 05/05/98 Sun Microsystems, Inc. All Rights Reserved.
      
       */
      
      import com.sun.em.api.pmi.*;
      
      import java.rmi.*;
      
      import java.rmi.server.UnicastRemoteObject;
      
      import java.net.*;
      
      import java.util.*;
      
      public class MOHandleEvent implements EventReportListener {
      
          public static final double TIMEOUT = 3600.0;
      
          static Platform plat = null;
      
          static void usage() {
      
      	 System.err.println("Usage:");
      
      	 System.err.println("java MOHandleEvent <servername> <mis-name> <username> <password>");
      
      	 System.err.println("\t-Run the example with <servername> as the remote server and <misname> 
               where EM mis is running.");
      
      	 System.exit(-1);
      
          }
      
      	 public static void main(String args[]) {
      
      	 	 if (args.length < 4) 
      
      	 	 	 usage();
      
      	 
      
      	 	 MOHandleEvent gt = null;
      
      	 	 MOHandle moh = null;
      
      	 	 String dn = new String("logId=\"AlarmLog\""); 
      
      	 	 String className = new String("log");
      
      	 	 try { gt = new MOHandleEvent();
      
      	 	 	 // instantiate the platform.
      
      	 	 	 plat = new Platform(args[0], args[1], args[2], args[3]);
      
      	 	 	 // nstantiate the MOHandle and retrieve the attribute info
      
      	 	 	 moh = new MOHandle(dn, className, plat); 
      
      	 	 	 moh.MGet(TIMEOUT);  
      
      	 	 	 // register for Callbacks for AVC, ObjectCreation and
      
      	 	 	 // ObjectDeletion
      
      	 	 	 System.out.println("MOHandle is logId=\"AlarmLog\"");
      
      	 	 	 System.out.println("Registering for events for MOHandle  ");
      
      	 	 	 moh.addAttributeValueChangeListener(gt);
      
      	 	 	 moh.addObjectCreationListener(gt);
      
      	 	 	 moh.addObjectDeletionListener(gt);
      
      	 	 	 System.out.println("Waiting for events ...");
      
      	 	 	 
      
      	 	 	 // wait here as the events arrive from mis.
      
      	 	 	 // user can modify an attribute here for AlarmLog to
      
      	 	 	 // verify the event delivery.
      
      	 	 }
      
      	 	 catch (JmiException ex) {System.out.println(ex); }
      
      	 	 catch (Exception ex) {System.out.println(ex); }	 
      
      	 }
      
      	 public void handler(EventReport ind) {
      
      	 	 String type = ind.getName();
      
      	 	 System.out.println("Event Type = " + type);
      
      	 	 System.out.println("Object Name = " + ind.getMOName());
      
      	 	 System.out.println("Object Class = " + ind.getMOClass());
      
      	 }
      
      	 public MOHandleEvent() throws JmiException { }
      
         private static final String sccsID =
      "@(#)MOHandleEvent.java 1.7 98/05/05 Sun Microsystems, Inc.";
      }
      

    2.7.4 EmWho.java

    The following code example shows you how to:

    • Create a collection and populate it.
    • Print out the members of the collection, which are the application instances connected to MIS.

      CODE EXAMPLE 2-8   EmWho.java 
      /*
      
       * Copyright (c) 05/05/98 Sun Microsystems, Inc. All Rights Reserved.
      
       */
      
      import com.sun.em.api.pmi.*;
      
      import java.net.*;
      
      import java.util.*;
      
      public class EmWho {
      
      	 
      
          public static final double TIMEOUT = 3600.0;
      
      	 static Platform plat = null;
      
          static void usage() {
      
      	 System.err.println("Usage:");
      
      	 System.err.println("java EmWho <servername> <mis-name> 
      <username> <password>");
      	 System.err.println("\t-Run the example with <servername> as the remote server and <misname> 
               where EM mis is running.");
      
      	 System.exit(-1);
      
          }
      
      	 
      
      	 public static void main(String args[]) {
      
      	   EmWho ew = null;
      
      	   if (args.length < 4) 
      
      	 	 usage();
      
      	   try {
      
      	     ew = new EmWho();
      
      	 	 System.out.println("Instantiating platform");
      
      	     plat = new Platform(args[0],args[1] , args[2],args[3]);
      
      	 
      
      	     ew.get_users();
      
      	   }
      
      	   catch (JmiException ex) {System.out.println(ex); }
      
      	   
      
      	 }
      
        
      
              public void get_users() {
      
      	 	   System.out.println("Findout the applications connected to mis");
      
      	 	   MOHCollectionByRule app_instances = null;
      
      	 	   String base = new String("subsystemId=\"EM-MIS\"");
      
      	 	   System.out.println("Base object is " + base);
      
      	 	   String scope = new String("LV(1)");
      
      	 	   System.out.println("Scope is " + scope);
      
      	 	   String filter = new String("CMISFilter(item:equality: {objectClass, emApplicationInstance})");
      
      	 	 	 
      
      	 	   System.out.println("Filter used " + filter);
      
      	 	   // get all app instance objects
      
      	 	   try {
      
      	 	 	 app_instances = new MOHCollectionByRule(base, scope, filter, plat);
      
      	 	   System.out.println("constructed album");
      
      	 	 	 app_instances.populate(TIMEOUT);
      
      	 	   System.out.println("populated the MOHCollectionByRule ");
      
      	 	 	 MOHandle[] mohs = null;
      
      	 	 	 mohs = app_instances.getMOHandles();
      
      	 	 	 System.out.println("# of app instance objects = " + mohs.length);
      
      	 	 	 // 
      
      	 	 	 // snarf user name out of emUserID attribute
      
      	 	 	 //
      
      	 	 	 
      
      	 	 	 for (int i=0; i < mohs.length; i++) {
      
      	 	 	 	 mohs[i].MGet(TIMEOUT);
      
      	 	 	 	 System.out.println(mohs[i].getObjectName());
      
      	 	 	 	 System.out.println(mohs[i].getStr("emApplicationType"));
      
      	 	 	 }
      
      	 	   } 
      
      	 	   catch (JmiException ex) {
      
      	 	 	 System.out.println(ex);
      
      	 	 	 System.exit(1);
      
      	 	   }
      
              }
      
         private static final String sccsID = 
      "@(#)EmWho.java 1.5 98/05/05 Sun Microsystems, Inc.";
      }
      

    2.7.5 CollectionEvent.java

    The following code example shows you how to:

    • Register Callbacks for AttributeValueChange, ObjectCreation, and ObjectDeletion events for a collection.
    • Verify event delivery.

      CODE EXAMPLE 2-9   CollectionEvent.java 
      /*
      
       * Copyright (c) 05/05/98 Sun Microsystems, Inc. All Rights Reserved.
      
      */
      
      import com.sun.em.api.pmi.*;
      
      import java.net.*;
      
      import java.util.*;
      
      public class CollectionEvent implements EventReportListener {
      
          public static final double TIMEOUT = 3600.0;
      
          static Platform plat = null;
      
          static void usage() {
      
      	 System.err.println("Usage:");
      
      	 System.err.println("java CollectionEvent <servername> <mis-name> <username> <password>");
      
      	 System.err.println("\t-Run the example with <servername> as the remote server and <misname> 
               where EM mis is running.");
      
      	 System.exit(-1);
      
          }
      
      	 public static void main(String args[]) {
      
      	 	 if (args.length < 4)
      
      	 	 	 usage();
      
      	 	 CollectionEvent gt = null;
      
      	 	 MOHCollectionByRule mcl = null;
      
      	 	 String base = new String("/systemId=name:\""+ args[1] + "\""); 
      
      //	 	 String base = null;
      
      	 	 String scope = new String("LV(1)"); 
      
      	 	 String filter = new String(""); 
      
      	 	 System.out.println("Populate the MOHandles for: ");
      
      	 	 System.out.println(base);
      
      	 	 try { gt = new CollectionEvent(); 
      
      	 	 plat = new Platform(args[0], args[1], args[2], args[3]);;
      
      	 	 System.out.println("Platform instantiated");
      
      	 	 }
      
      	 	 catch (JmiException ex) { System.out.println(ex); }
      
      	 	 try { mcl = new MOHCollectionByRule(base, scope, filter, plat); }
      
      	 	 catch (JmiException ex) {
      
      	 	 	 System.out.println(ex); 
      
      	 	 	 System.exit (1); 
      
      	 	 }
      
      	 	 System.out.println("Collection created");
      
      	 	 try { mcl.populate(TIMEOUT); } 
      
      	 	 catch (JmiException ex) { System.out.println(ex); }
      
      	 	 System.out.println("Collection populated");
      
      	 	 try {
      
      	 	 System.out.println("Scope: " + mcl.getScope());
      
      	 	 System.out.println("Filter: " + mcl.getFilter());
      
      	 	 System.out.println("Base Object: " + mcl.getBaseManagedObject());
      
      	 	 }
      
      	 	 catch (JmiException ex) {}
      
      	 	 
      
      	 	 MOHandle[] mohs = null;
      
              try { mohs = mcl.getMOHandles(); }
      
              catch (JmiException ex) { System.out.println(ex); }
      
      	 	 System.out.println("The # of MOHandles are .." + mohs.length);
      
      	 	 System.out.println("The MOHandles for the Collection are ..");
      
      	 	 try {	 
      
              	 for (int i=0; i <mohs.length; i++) {
      
              	 System.out.println("Object Name: " + mohs[i].getObjectName()); }
      
      	 	 }
      
      	 	 catch (JmiException ex) {System.out.println(ex); }
      
              System.out.println("Got all the MOHandles"); 
      
              try {  
      
      	 	 
      
      	 	 mcl.MGet(TIMEOUT); 
      
      	 	 // set the collection in tracking mode
      
      	 	 mcl.setTracking(true);	 
      
      	 	 // register for events
      
      	 	 // MOHandleIncluded and MOHandleExcluded
      
              mcl.addMOHandleIncludedListener(gt);
      
              mcl.addMOHandleExcludedListener(gt);
      
      	 	 System.out.println("Wait for events ..");
      
      	 	 }
      
              catch (JmiException ex) {System.out.println(ex); }
      
      	 }
      
      	 public CollectionEvent() throws JmiException {
      
      	 }
      
      	 public void handler(EventReport ind) {
      
              String type = ind.getName();
      
              System.out.println("Event Type = " + type);
      
              System.out.println("Object Name = " + ind.getMOName());
      
              System.out.println("Object Class = " + ind.getMOClass());
      
              try {
      
                  System.out.println("Object Raw info = " +
      
                                     ind.getInfoRaw().getStr());
      
              } catch (JmiException ex) { ex.printStackTrace(); }
      
      	 }
      
        private static final String sccsID = 
      "@(#)CollectionEvent.java 1.7 98/05/05 Sun Microsystems, Inc.";
      }
      


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