Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
Chapter 4, Writing a Provider Program Implementing the Provider Interfaces Writing an Associator Provider   Previous   Contents   Next 
   
 

Writing an Indication Provider

To generate an indication for a CIM event, do the following:

  • Use the methods in the EventProvider interface to detect when to start and stop delivering indications of the CIM event.

  • Create an instance of one or more subclasses of the CIM_Indication class to store information about the CIM event that occurred.

  • Use the deliverEvent method in the ProviderCIMOMHandle interface to deliver indications to the CIM Object Manager.

    How To Generate an Event Indication

  1. Implement the EventProvider interface.

    For example:

    public class sampleEventProvider 
    implements InstanceProvider EventProvider{
    
        // Reference for provider to contact the CIM Object Manager
        private ProviderCIMOMHandle cimom;
       }

  2. Execute each of the methods listed in Table 4-2 for each instance indication that the provider handles.

  3. Create an indication for each create, modify, and delete instance event type.

    For example, in the createInstance method:

    public CIMObjectPath createInstance(CIMObjectPath op, 
            CIMInstance ci)
        throws CIMException {
            CIMObjectpath newop = ip.createInstance(op, ci);
            CIMInstance indication = new CIMInstance();
            indication.setClassName("CIM_InstCreation");
            CIMProperty cp = new CIMProperty();
            cp.setName("SourceInstance");
            cp.setValue(new CIMValue(ci));
            Vector v = new Vector();
            v.addElement(cp);
            indication.setProperties(v);
            ...
        }

  4. Deliver the event indication to the CIM Object Manager:

    cimom.deliverEvent(op.getNameSpace(), indication);

Event Provider Methods

An event provider implements the EventProvider interface. This interface contains methods that the CIM Object Manager uses to notify the provider when a client has subscribed for indications of CIM events, and when a client has cancelled the subscription for CIM events. These methods also allow the provider to indicate whether or not the CIM Object Manager should poll for some event indications and whether or not the provider should authorize the return of an indication to a handler.

The following table lists the methods in the EventProvider interface that must be implemented by an event provider.

Table 4-2 EventProvider Methods

Method

Description

activateFilter

When a client creates a subscription, the CIM Object Manager calls this method to ask the provider to check for CIM events.

authorizeFilter

When a client creates a subscription, the CIM Object Manager calls this method to test if the specified filter expression is allowed.

deActivateFilter

When a client removes a subscription, the CIM Object Manager calls this method to ask the provider to deactivate the specified event filter.

mustPoll

When a client creates a subscription, the CIM Object Manager calls this method to test if the specified filter expression is allowed by the provider, and if it must be polled.

The CIM Object Manager passes values for the following arguments to all methods:

  • filter - SelectExp that specifies the CIM events for which indications must be generated.

  • eventType - String that specifies the type of CIM event, which can also be extracted from the FROM clause of the select expression.

  • classPath - CIMObjectPath that specifies the name of the class for which the event is required.

In addition, the activateFilter method takes the boolean firstActivation, indicating that this is the first filter for this event type. The deActivateFilter method takes the boolean lastActivation, indicating that this is the last filter for this event type.

Creating and Delivering Indications

When a client application subscribes for indications of CIM events by creating an instance of the CIM_IndicationSubscription class, the CIM Object Manager forwards the request to the appropriate provider. If the provider implements the EventProvider interface, the CIM Object Manager notifies the provider when to start sending indications for the specified events by calling the provider's activateFilter method. In addition, the CIM Object Manager notifies the provider when to stop sending indications for the specified events by calling the provider's deActivateFilter method.

The provider responds to the CIM Object Manager's requests by creating and delivering an indication each time the provider creates, modifies, or deletes an instance. A provider typically defines a flag variable that is set when the CIM Object Manager calls the activateFilter method that is cleared when the CIM Object Manager calls the deActivateFilter method. Then in each method that creates, modifies, or deletes an instance, the provider checks the status of the activate filter flag. If the flag is set, the provider creates an indication containing the created CIM instance object and uses the deliverEvent method to return the indication to the CIM Object Manager. If the flag is not set, the provider does not create and deliver an indication of the event.

A provider starts delivering indications when the activateFilter method is called. The provider creates instances of concrete subclasses of CIM_Indication and invokes the ProviderCIMOMHandled.deliverIndication method. The CIM Object Manager receives the indication and delivers the indication to the appropriate indication handlers. A provider can handle multiple event types. For example, in the case of life cycle indications, a provider can handle CIM_InstCreation, CIM_InstDeletion, and CIM_InstModification.

To keep track of types that have subscriber interest, the provider can use the firstActivation and lastActivation flags passed in the activateFilter and deActivateFilter calls, respectively. The firstActivation flag is true when the subscription is the first one for the particular event type. Similarly, lastActivation is true when the last subscription for the particular event type is removed. By checking these flags, the provider can easily allocate or deallocate resources to monitor the specified event types.

About Authorizations

A provider that handles sensitive data can check authorizations for requests for indications. The provider must implement the Authorizable interface to indicate that it handles authorization checking. The provider also implements the authorizeFilter method. The CIM Object Manager calls this method to test if the owner (UID) of an event handler is authorized to receive the indications that result from evaluating a filter expression. The UID for the owner of the event destination (event handler) can be different than the owner of the client application requesting the filter activation.

Writing a Native Provider

Providers get information from and set information on managed devices. A native provider is a program specifically written for a particular managed device. For example, a provider that accesses data on a Solaris system usually includes C functions to query the system.

The common reasons for writing a native provider are as follows:

  • Efficiency - You may want to implement a small portion of time-critical code in a lower-level programming language, such as Assembly, and then have your Java application call these functions.

  • Need to access platform-specific features - The standard Java class library might not support the platform-dependent features required by your application.

  • Legacy code - You want to continue to use your legacy code with a Java provider.

The Java Native Interface is part of the JDK software. By writing programs using the Java Native Interface, you ensure that your code is completey portable across all platforms.The Java Native Interface enables Java code that runs within a Java virtual machine to operate with applications and libraries written in other languages, such as C, C++, and assembly.

For more information on writing and integrating Java programs with native methods, visit the Java Web site at http://java.sun.com.

 
 
 
  Previous   Contents   Next