Client event notification

For implement BTT client event notification, do the following:
  1. Implement the com.ibm.btt.base.Notifier interface. For example, a client application needs to get printer error messages from a printer that is in the same machine with client application. To implement this, create a DSENotifier subclass. This class will also implement a printerError method that will be invoked by any service that is accessing a printer when the printer fails. SampleNotifier will signal a local toolkit event with the following arguments:
    1. The name of the error message passed as a printerError argument
    2. Attributes identifying the printer address in the network
    3. The document to be printed when the failure occurs
      public class SampleNotifier extends DSENotifier { 
        public DSEEventObject printerEvent; 
      } 
      public SampleNotifier () { 
        super(); 
      } 
      public SampleNotifier(String aName) { 
        super(aName); 
      } 
      public void printerError(String aPrt, String aDocName, String message) { 
        Hashtable eventAttributes = new Hashtable(); 
        eventAttributes.put ("printerAddress", aPrt); 
        eventAttributes.put ("document", aDocName); 
        printerEvent = new DSEEventObject("printerEvent",this,eventAttributes); 
        signalEvent(printerEvent); 
      } 

      You can integrate the standard Java™ events within the toolkit's client event management if the JavaBean implements the Notifier interface and it is a handler (listener) of all standard Java events that it fires.

  2. Implement the signalEvent method for each event that the notifier can fire. Note that the standard Java event notification mechanism will call any other local listeners for that event.
  3. Create a handler for the event and implement a dispatchEvent to provide the behavior to process the event. For example, the SampleNotifier uses the PrinterEventsHandler:
    public class PrinterEventsHandler extends DSEHandler { 
    } 
    public Handler dispatchEvent(DSEEventObject anEvent) { 
      // The dispatch method displays a string in the system standard
    output 
      // containing the event information 
      System.out.println("The event"+ anEvent.getName()+ "has been
    signaled. Printer:"+
            anEvent.getParameters().get("printerAddress")+" Document:"
            +anEvent.getParamenters().get("document")); 
      // The handler enables further event propagation by returning
    this
      // return this; 
    } 

    In this case, the dispatchEvent does nothing but output a message to the system standard output. Note that if you do not want to propagate this event to the next registered handler, the dispatchEvent must return null.

  4. Add the handler registration to the client operation that requires event notification as shown in the following example:
    import com.ibm.btt.base.*; 
    import com.ibm.btt.clientserver.*; 
    
    public class myClientOperation extends DSEClientOperation { 
      public PrinterEventsHandler eventsHandler; 
    } 
    
    public void execute() throws Exception() { 
    
    
      
      // Start to handle an local event 
      eventsHandler= new PrinterEventsHandler; 
      eventsHandler.handleEvent("printerEvent", "SampleNotifier", getContext());
    
      // The application can continue its operation flow. The handler 
      // processes the event as soon as it is fired. 
    } 

    When the SampleNotifier instance fires an event, it calls the dispatchEvent method of the PrinterEventsHandler. In the handler displays a message in the system standard output.