⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventmanagerservice.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004, 2005                                  *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service.eventmanager;import com.ibm.staf.*;import com.ibm.staf.service.*;import java.util.*;import java.io.*;import org.python.util.PythonInterpreter;import org.python.core.*;import java.util.Properties;public class EventManagerService implements STAFServiceInterfaceLevel30, Runnable{    private STAFHandle fHandle;    private final String kVersion = "3.2.1";    // Version of STAF (or later) required for this service    // STAF Version 3.1.0 or later is required so that the privacy methods    // in STAFUtil are available.    private final String kRequiredSTAFVersion = "3.1.0";    private STAFCommandParser fParmsParser = new STAFCommandParser();    private STAFCommandParser fRegisterParser;    private STAFCommandParser fListParser;    private STAFCommandParser fTriggerParser;    private STAFCommandParser fVersionParser;    private STAFMapClassDefinition fEventManagerIDMapClass;    private STAFMapClassDefinition fEMIDShortMapClass;    private STAFMapClassDefinition fEMIDMapClass;    private STAFMapClassDefinition fSettingsMapClass;    private STAFMapClassDefinition fTriggerMapClass;    private Hashtable fRegTable;    private static boolean DEBUG = true;    private Thread fQueueThread;    private STAFCommandParser fUnregisterParser;    private int fEventManagerID = 1;    private String fLineSep;    private String fEventServiceMachine = "";    private String fEventServiceName = "";    private String fLocalMachineName = "";    private String fServiceName = "eventmanager";    private String fJythonVersion = "";    private PythonInterpreter fPythonInterpreter;    private String fHashtableFileDirectory;    private String fHashtableFileName;    private HashMap fSubmittedRequests = new HashMap();    private HashMap fRequestsAndIDs = new HashMap();      // key=<machine>:<reqNum>, value=ID    private HashMap fProcessHandlesAndRequests = new HashMap();      // key=<machine>:<handle>, value=<machine>:<reqNum>    static final String sQueueTypeEnd = "STAF/Service/EventManager/End";    public static final int PYTHONERROR = 4001;    private static final String PYTHONERRORInfo = "Python error";    private static final String PYTHONERRORDesc =        "A Python error occurred while evaluating the request to be submitted.";    public static final int REQUESTNOTSUBMITTED = 4002;    private static final String REQUESTNOTSUBMITTEDInfo =        "Request not submitted";    private static final String REQUESTNOTSUBMITTEDDesc =        "The request was not submitted because the value of " +        "STAFEventManagerSubmit was not set to true.";    public EventManagerService()    {    }    public STAFResult init(STAFServiceInterfaceLevel30.InitInfo info)    {        int rc = STAFResult.Ok;        try        {            fHandle = new STAFHandle("STAF/SERVICE/" + info.name);        }        catch (STAFException e)        {            return new STAFResult(STAFResult.STAFRegistrationError,                                  e.toString());        }        try        {            STAFResult res = new STAFResult();            // Resolve the machine name variable for the local machine            res = STAFUtil.resolveInitVar("{STAF/Config/Machine}", fHandle);            if (res.rc != STAFResult.Ok) return res;            fLocalMachineName = res.result;                        fServiceName = info.name;            fEventServiceMachine = "local";            fEventServiceName = "event";                        // Resolve the line separator variable for the local machine            res = STAFUtil.resolveInitVar("{STAF/Config/Sep/Line}", fHandle);            if (res.rc != STAFResult.Ok) return res;            fLineSep = res.result;            // Verify that the required version of STAF is running on the            // local service machine.              // Note:  Method compareSTAFVersion was added in STAF V3.1.0            try            {                res = STAFUtil.compareSTAFVersion(                    "local", fHandle, kRequiredSTAFVersion);                if (res.rc != STAFResult.Ok)                {                    if (res.rc == STAFResult.InvalidSTAFVersion)                    {                        return new STAFResult(                            STAFResult.ServiceConfigurationError,                            "Minimum required STAF version for this service " +                            "is not running." + fLineSep + res.result);                    }                    else                    {                        return new STAFResult(                            STAFResult.ServiceConfigurationError,                            "Error verifying the STAF version. RC: " + res.rc +                            ", Additional info: " + res.result);                    }                }            }            catch (Error err)            {                return new STAFResult(                    STAFResult.ServiceConfigurationError,                    "This service requires STAF Version " +                    kRequiredSTAFVersion + " or later.");             }            if (info.serviceJar != null)            {                // Create the Jython Library directory if it doesn't exist yet                // from the jython library data in the service's jarfile.                // Set the classpath to point to the service's jar file and to                // the jython.jar.                res = STAFServiceSharedJython.setupJython(                    info.serviceJar, fHandle, info.writeLocation);                if (res.rc != 0)                {                    System.out.println(res.result);                    return res;                }                // Get the version of Jython distributed with the service                                    fJythonVersion = STAFServiceSharedJython.getJythonVersion();                // Initialize the PythonInterpreter's python.home to point to                // the shared jython installation.                Properties p = new Properties();                p.setProperty("python.home",                              STAFServiceSharedJython.getJythonDirName());                PythonInterpreter.initialize(System.getProperties(), p, null);                // IMPORTANT: First creation of a PythonInterpreter needs to                // occur after it's been initialized in order for this                // property to be assigned to it.            }            // Parse PARMS if provided in the STAX configuration line            if (info.parms != null)            {                fParmsParser.addOption("EVENTSERVICEMACHINE", 1,                                       STAFCommandParser.VALUEREQUIRED);                fParmsParser.addOption("EVENTSERVICENAME", 1,                                       STAFCommandParser.VALUEREQUIRED);                res = handleParms(info);                if (res.rc != STAFResult.Ok)                {                    return new STAFResult(                        STAFResult.ServiceConfigurationError,                        "Error validating parameters: RC=" + res.rc +                        ", Result=" + res.result);                }            }            // instantiate parsers as not case sensitive            fRegisterParser = new STAFCommandParser(0, false);            fListParser = new STAFCommandParser(0, false);            fTriggerParser = new STAFCommandParser(0, false);            fUnregisterParser = new STAFCommandParser(0, false);            fVersionParser = new STAFCommandParser(0, false);            fRegisterParser.addOption("REGISTER", 1,                                      STAFCommandParser.VALUENOTALLOWED);            fRegisterParser.addOption("DESCRIPTION", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOption("MACHINE", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOption("PYTHONMACHINE", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOptionGroup("MACHINE PYTHONMACHINE", 1, 1);            fRegisterParser.addOption("SERVICE", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOption("PYTHONSERVICE", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOptionGroup("SERVICE PYTHONSERVICE", 1, 1);            fRegisterParser.addOption("REQUEST", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOption("PYTHONREQUEST", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOptionGroup("REQUEST PYTHONREQUEST", 1, 1);            fRegisterParser.addOption("TYPE", 1,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOption("SUBTYPE", 0,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOption("PREPARE", 0,                                      STAFCommandParser.VALUEREQUIRED);            fRegisterParser.addOptionNeed("REGISTER", "MACHINE PYTHONMACHINE");            fRegisterParser.addOptionNeed("MACHINE PYTHONMACHINE", "REGISTER");            fUnregisterParser.addOption("UNREGISTER", 1,                                        STAFCommandParser.VALUENOTALLOWED);            fUnregisterParser.addOption("ID", 1,                                        STAFCommandParser.VALUEREQUIRED);            fUnregisterParser.addOptionNeed("UNREGISTER", "ID");            fListParser.addOption("LIST", 1,                                  STAFCommandParser.VALUENOTALLOWED);            fListParser.addOption("MACHINE", 1,                                  STAFCommandParser.VALUEREQUIRED);            fListParser.addOption("TYPE", 1,                                  STAFCommandParser.VALUEREQUIRED);            fListParser.addOption("LONG", 1,                                  STAFCommandParser.VALUENOTALLOWED);            fListParser.addOption("SETTINGS", 1,                                   STAFCommandParser.VALUENOTALLOWED);            fListParser.addOption("SHORT", 1,                                  STAFCommandParser.VALUENOTALLOWED);            fListParser.addOptionGroup("MACHINE SETTINGS", 0, 1);            fListParser.addOptionGroup("TYPE SETTINGS", 0, 1);            fListParser.addOptionGroup("LONG SETTINGS", 0, 1);            fListParser.addOptionGroup("LONG SHORT", 0, 1);            fTriggerParser.addOption("TRIGGER", 1,                                     STAFCommandParser.VALUENOTALLOWED);            fTriggerParser.addOption("ID", 1,                                     STAFCommandParser.VALUEREQUIRED);            fTriggerParser.addOption("SCRIPT", 0,                                     STAFCommandParser.VALUEREQUIRED);            fTriggerParser.addOptionNeed("TRIGGER", "ID");            fVersionParser.addOption("VERSION", 1,                                     STAFCommandParser.VALUENOTALLOWED);            fVersionParser.addOption("JYTHON", 1,                                     STAFCommandParser.VALUENOTALLOWED);            fVersionParser.addOptionGroup("VERSION", 1, 1);            fVersionParser.addOptionNeed("JYTHON", "VERSION");            // Construct map class for a LIST request.            fEMIDMapClass = new STAFMapClassDefinition(                "STAF/Service/EventManager/EventManagerID");            fEMIDMapClass.addKey("eventManagerID", "ID");            fEMIDMapClass.addKey("description", "Description");            fEMIDMapClass.setKeyProperty("description", "display-short-name",                                         "Desc");            fEMIDMapClass.addKey("machine", "Machine");            fEMIDMapClass.addKey("service", "Service");            fEMIDMapClass.addKey("request", "Request");            fEMIDMapClass.addKey("type", "Event Type");            fEMIDMapClass.addKey("subtype", "Event Subtype");            // Construct map class for a LIST SHORT request.            fEMIDShortMapClass = new STAFMapClassDefinition(                "STAF/Service/EventManager/EventManagerIDShort");            fEMIDShortMapClass.addKey("eventManagerID", "ID");            fEMIDShortMapClass.addKey("description", "Description");            fEMIDShortMapClass.setKeyProperty("description",                                              "display-short-name",                                              "Desc");            fEMIDShortMapClass.addKey("machine", "Machine");            fEMIDShortMapClass.addKey("service", "Service");            fEMIDShortMapClass.addKey("request", "Request");            // Construct map class for a LIST LONG request.            fEventManagerIDMapClass = new STAFMapClassDefinition(                "STAF/Service/EventManager/EventManagerID");            fEventManagerIDMapClass.addKey("eventManagerID", "ID");            fEventManagerIDMapClass.addKey("description", "Description");            fEventManagerIDMapClass.addKey("machine", "Machine");            fEventManagerIDMapClass.addKey("machineType", "Machine Type");            fEventManagerIDMapClass.addKey("service", "Service");            fEventManagerIDMapClass.addKey("serviceType", "Service Type");            fEventManagerIDMapClass.addKey("request", "Request");            fEventManagerIDMapClass.addKey("requestType", "Request Type");            fEventManagerIDMapClass.addKey("type", "Event Type");            fEventManagerIDMapClass.addKey("subtype", "Event Subtype");            fEventManagerIDMapClass.addKey("prepareScript", "Prepare Script");            // Construct map-class for list settings information            fSettingsMapClass = new STAFMapClassDefinition(                "STAF/Service/EventManager/Settings");            fSettingsMapClass.addKey(                "eventServiceMachine", "Event Service Machine");            fSettingsMapClass.addKey(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -