next up previous contents index
Next: SNMP-MIB-Browser/SNMP-Manager Up: Management-Möglichkeiten Previous: HTML-Browser

Manager-Applikationen

Eine weitere Methode, auf JDMK-Agenten zuzugreifen ist, eine Client- oder Managerapplikation zu entwickeln. Diese Applikation kann entweder in Java oder C++ geschrieben sein. Im zweiten Fall ist jedoch der Zugriff auf JDMK-Agenten über das Java Native Interface durchzuführen. Eine einfache Client-Java-Applikation kann folgende Gestalt besitzen:

package trial;

import java.net.*;
import java.util.*;

// jaw import
import com.sun.jaw.reference.common.*;
import com.sun.jaw.impl.adaptor.rmi.*;
import com.sun.jaw.impl.agent.services.monitor.*;
import trial.monitor.ClientListener;

public class Client implements Runnable {

  // CONSTRUCTOR
  //------------
  public Client() {
  }
  
  /**
   * It is possible to specify on the command line the implementation to use
   * for the adaptor function. 
   */
  public static void main(String argv[]) {
    System.exit( new Client().execute(argv) ) ; 
  }
  
  /**
   * When an object implementing interface Runnable is used to create a thread, 
   * starting the thread causes the object's run method to be called in that
   * separately executing thread.
   */
  public void run() {
    String[] s = new String[0];
    execute(s);
  }
    
  // PRIVATE METHODS
  //----------------
  private int execute(String argv[]) {
    try {
      // Set the host name of the remote agent.
      //                     
      String agentHost = InetAddress.getLocalHost().getHostName();
      if (argv.length >= 1) {
         agentHost = argv[0];
      }
      // Set the port number of the remote host.
      //
      int agentPort = 1096;
      if (argv.length >= 2) {
         agentPort = Integer.decode(argv[1]).intValue();
      }
      // Create an adaptor client to enable the client to manage the remote agent
      // and initializes the communications with the remote agent.
      //
      trace(">>> CREATE and INITIALIZE communication with the remote agent,");
      trace("HOST     = " + agentHost);
      trace("PORT     = " + agentPort);
      trace("PROTOCOL = RMI");
      trace("SERVER   = " + ServiceName.APT_RMI);
      AdaptorClient adaptor = new AdaptorClient();
      adaptor.connect(null, agentHost, agentPort, ServiceName.APT_RMI);
      trace("Communication ok");
      // Get the domain name from the remote agent.
      //
      String domain = "SBCS-TIS2-MIB-Impl";
      // Get an instance of the GkStatistics m-bean in the 
      // remote agent.
      //
      String NetworkParmsImplClass = "NetworkParmsImpl";
      ObjectName NetworkParmsImplName 
        = new ObjectName(domain + ":tis20.impl.NetworkParmsImpl");
      System.out.println("Get an instance of NetworkParmsImpl in the remote object server");
      System.out.println("with the object name -> " + NetworkParmsImplName.toString());
      tis20.impl.NetworkParmsImplMO NetworkParmsImpl 
        = (tis20.impl.NetworkParmsImplMO) 
          ((Vector)adaptor.getObject(NetworkParmsImplName, null)).firstElement();
      System.out.println("ok");
          
      String[] test = NetworkParmsImpl.performStringTableValues("DomainSuffixTable",1,1);
 
      // Terminate communication with the remote agent.
      //
      adaptor.disconnect();
      return 0;
    } catch(Exception e) {
      trace("Got an exception !");
      e.printStackTrace();
      return 1;
    }
  }

  /**
   * Display trace messages.
   */
  private void trace(String msg) {
     System.out.println(msg);
  }
}

next up previous contents index
Next: SNMP-MIB-Browser/SNMP-Manager Up: Management-Möglichkeiten Previous: HTML-Browser

Beispielbenutzer SuSE Linux 6.0
Sun May 9 21:16:36 MEST 1999