Appendix D. Event Adaptor Configuration

This appendix describes how to configure SysMaster Event Adaptor to write user code for seding SMS and e-mails, etc.

Configuration Procedure

The following are the steps for configuring the Event Adaptor.

  1. Write a class by implementing sysmaster.master.event.EventSupport.

    public interface EventSupport {
        public void init() throws Exception;
        public void publish(EventInfo info) throws Exception;
        public void stop() throws Exception;
    }

    Write initialization code in the init() method. The publish(EventInfo info) method is called whenever an event occurs. In the stop() method, write a routine for terminating SysMaster.

  2. Compress the code written in step 1, and save it to the following path.

    MASTER_HOME/jeus/lib/application
  3. Set an Event class name in the sysmaster.properties file.

    • Configuration method

      event.class=class full name
    • Example

      event.class=event.EventTest
  4. Restart Master. If the Event class setting fails to be applied, the following message (info) is recorded in MASTER_HOME/logs/smlog.container1 (or smlog) or an exception occurs.

    [EventAdaptor]EventSupport class is not defined. 

Example Code

EventInfo class methods are referenced when writing code to handle jobs by event level or events related to a specific container.

The following is an example code of event.EventTest.java.

package event;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import sysmaster.Logger;
import sysmaster.master.event.EventInfo;
import sysmaster.master.event.EventSupport;

public class EventTest implements EventSupport {

private BufferedWriter bufferedWritter;
private FileWriter fileWriter;

private File file;
    
@Override
public void init() throws Exception {
  try{
   file = new File("/data1/sysmaster/test/event.txt");
      if(!file.exists()){
       file.createNewFile();
      }
      fileWriter = new FileWriter(file, true); 
      bufferedWritter = new BufferedWriter(fileWriter);
      Logger.info("Event Adaptor is initialized");
     }catch(IOException e){
      Logger.error("Initializtion is failed", e);
     }
}
@Override
public void publish(EventInfo info) throws Exception{
  try{
         bufferedWritter.write(info.getMsgText() + "\n");
         bufferedWritter.flush();
     }catch(IOException e){
      Logger.error("Event publishing is failed", e);
     }
}
@Override
public void stop() throws Exception {
  try{
   bufferedWritter.close();
         fileWriter.close();
         file.delete();
     }catch(IOException e){
      Logger.error("Stopping event adaptor is failed", e);
     }
 }
}