A Web-Based Enterprise Management (WBEM) application is a standard Java program that uses Sun WBEM SDK APIs to manipulate CIM objects. A client application typically uses the CIM API to construct an object (for example, a namespace, class, or instance) and then initialize that object. The application then uses the Client APIs to pass the object to the CIM Object Manager and request a WBEM operation, such as creating a CIM namespace, class, or instance.
Sun WBEM SDK applications typically follow this sequence:
Connect to the CIM Object Manager - (CIMClient).
A client application contacts a CIM Object Manager to establish a connection each time it needs to perform a WBEM operation, such as creating a CIM Class or updating a CIM instance.
Use one or more APIs to perform some programming tasks.
Once a program connects to the CIM Object Manager, it uses the APIs to request operations.
Close the client connection to the CIM Object Manager - (close).
Applications should close the current client session when finished. Use the CIMClient interface to close the current client session and free any resources used by the client session.
Example 6-1 is a simple application that connects to the CIM Object Manager, using all default values. The program gets a class and then enumerates and prints the instances in that class.
import java.rmi.*; import com.sun.wbem.client.CIMClient; import com.sun.wbem.cim.CIMInstance; import com.sun.wbem.cim.CIMValue; import com.sun.wbem.cim.CIMProperty; import com.sun.wbem.cim.CIMNameSpace; import com.sun.wbem.cim.CIMObjectPath; import com.sun.wbem.cim.CIMClass; import com.sun.wbem.cim.CIMException; import java.util.Enumeration; /** * Gets the class specified in the command line (args[1]). Gets the * instances of the class in the namespace specified in the command * line (args[0]). */ 1 public class WBEMsample { 2 public static void main(String args[]) throws CIMException { 3 CIMClient cc = null; 4 try { 5 /* args[0] contains the namespace. We create 6 a namespace object (cns) to store the namespace. */ 7 CIMNameSpace cns = new CIMNameSpace(args[0]); 8 /* Connect to the CIM Object manager and pass it 9 the namespace object containing the namespace. */ 10 cc = new CIMClient(cns); 11 /* args[1] contains the class name. We create a 12 CIM Object Path that references the specified 13 class in the current namespace. */ 14 CIMObjectPath cop = new CIMObjectPath(args[1]); 15 /* Get the class object referenced by the CIM Object 16 Path. */ 17 cc.getClass(cop); 18 //Deep enumeration of the class and all its subclasses 19 Enumeration e = cc.enumInstances(cop, true); 20 while(e.hasMoreElements()) { 21 CIMObjectPath op = (CIMObjectPath)e.nextElement(); 22 System.out.println(op); 23 } 24 catch (Exception e) { 25 System.out.println("Exception: "+e); 26 } 27 if(cc != null) { 28 cc.close(); 29 } 30 } 31 } |
Once a client application connects to the CIM Object Manager, it uses the API to request operations. The program's feature set determines which operations it needs to request. The typical tasks that most programs perform are:
Working with instances - creating, deleting, and updating
In addition, applications may occasionally perform the following tasks: