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

📄 eventmanagerservice.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        {            return new STAFResult(                STAFResult.InvalidRequestString, parsedRequest.errorBuffer);        }        // For each option, if the user has specified a value, set the        // corresponding local variable to the user-specified value.        try        {            // Verify the requester has at least trust level 5            STAFResult trustResult = STAFUtil.validateTrust(                5, fServiceName, "REGISTER", fLocalMachineName, info);            if (trustResult.rc != STAFResult.Ok) return trustResult;            // Process the request            if (parsedRequest.optionTimes("description") > 0)            {                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("description"),                    fHandle, info.requestNumber);                                    description = resolvedValue.result;            }            if (parsedRequest.optionTimes("machine") > 0)            {                // Resolve the MACHINE option                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("machine"),                    fHandle, info.requestNumber);                                if (resolvedValue.rc != 0) return resolvedValue;                machine = resolvedValue.result;                pythonMachine = false;            }            else if (parsedRequest.optionTimes("pythonmachine") > 0)            {                machine = parsedRequest.optionValue("pythonmachine");                pythonMachine = true;            }            if (parsedRequest.optionTimes("service") > 0)            {                // Resolve the SERVICE option                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("service"),                    fHandle, info.requestNumber);                                if (resolvedValue.rc != 0) return resolvedValue;                service = resolvedValue.result;                pythonService = false;            }            else if (parsedRequest.optionTimes("pythonservice") > 0)            {                service = parsedRequest.optionValue("pythonservice");                pythonService = true;            }            if (parsedRequest.optionTimes("request") > 0)            {                // Resolve the REQUEST option                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("request"),                    fHandle, info.requestNumber);                if (resolvedValue.rc != 0) return resolvedValue;                request = resolvedValue.result;                pythonRequest = false;            }            else if (parsedRequest.optionTimes("pythonrequest") > 0)            {                request = parsedRequest.optionValue("pythonrequest");                pythonRequest = true;            }            // Resolve the TYPE option            resolvedValue = STAFUtil.resolveRequestVar(                parsedRequest.optionValue("type"), fHandle, info.requestNumber);            if (resolvedValue.rc != 0) return resolvedValue;            type = resolvedValue.result;            if (parsedRequest.optionTimes("subtype") > 0)            {                // Resolve the SUBTYPE option                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("subtype"),                    fHandle, info.requestNumber);                if (resolvedValue.rc != 0) return resolvedValue;                                subtype = resolvedValue.result;            }            if (parsedRequest.optionTimes("prepare") > 0)            {                prepare = parsedRequest.optionValue("prepare");            }            String registerRequest = "REGISTER TYPE " + type;            if (!(subtype.equals("")))            {                registerRequest += " SUBTYPE " + subtype;            }            if (!(prepare.equals("")) || pythonMachine || pythonService ||                pythonRequest)            {                // validate Python code                fPythonInterpreter = new PythonInterpreter();                                if (!(prepare.equals("")))                {                    try                    {                        compileForPython(prepare);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "PREPARE value:\n" + prepare +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }                if (pythonMachine)                {                    try                    {                        compileForPython(machine);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "MACHINE value:\n" + machine +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }                if (pythonService)                {                    try                    {                        compileForPython(service);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "SERVICE value:\n" + service +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }                if (pythonRequest)                {                    try                    {                        compileForPython(request);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "REQUEST value:\n" + request +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }            }            // Register with the Event service            STAFResult registerResult = fHandle.submit2(                fEventServiceMachine, fEventServiceName, registerRequest);            if (registerResult.rc != 0)            {                return registerResult;            }            else            {                Integer index = new Integer(fEventManagerID++);                fRegTable.put(                    index, (Object) new EventManagerData1(description,                        originMachine, machine, pythonMachine, service,                        pythonService, request, pythonRequest,                        type, subtype, prepare));                sResult = new STAFResult(STAFResult.Ok, index.toString());                saveHashtable();                String message = "[ID=" + index + "] [" + info.endpoint +                    ", " + info.handleName +                    "] Registered a STAF command.\nRegister request: " +                    info.request;                fHandle.submit2(                    "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName +                    " LEVEL info MESSAGE " + STAFUtil.wrapData(message));            }        }        catch (Exception e)        {            if (DEBUG)            {                e.printStackTrace();            }            return new STAFResult(STAFResult.JavaError,                                  "Internal Java error.");        }        return sResult;    }    private STAFResult handleUnregister(STAFServiceInterfaceLevel30.RequestInfo                                        info)    {        STAFResult sResult = new STAFResult(STAFResult.Ok, "");        String service;        String request;        Integer id;        STAFResult resolvedResult = null;        STAFResult resolvedValue = null;        STAFCommandParseResult parsedRequest = fUnregisterParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(                STAFResult.InvalidRequestString, parsedRequest.errorBuffer);        }        // For each option, if the user has specified a value, set the        // corresponding local variable to the user-specified value.        try        {            // Verify the requester has at least trust level 4            STAFResult trustResult = STAFUtil.validateTrust(                4, fServiceName, "UNREGISTER", fLocalMachineName, info);            if (trustResult.rc != STAFResult.Ok) return trustResult;            // Resolve the ID option            resolvedValue = STAFUtil.resolveRequestVarAndCheckInt(                "id", parsedRequest.optionValue("id"),                fHandle, info.requestNumber);            if (resolvedValue.rc != 0) return resolvedValue;                        id = new Integer(resolvedValue.result);                        // Check if registration table contains the ID            if (!fRegTable.containsKey(id))            {                return new STAFResult(                    STAFResult.DoesNotExist, "ID " + id + " not found");            }            else            {                EventManagerData1 data = (EventManagerData1)fRegTable.get(id);                fRegTable.remove(id);                if (fRegTable.isEmpty())                {                    fEventManagerID = 1;                }                saveHashtable();                String message = "[ID=" + id + "] [" + info.endpoint + ", " +                    info.handleName + "] Unregistered a STAF command.";                fHandle.submit2(                    "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName +                    " LEVEL info MESSAGE " + STAFUtil.wrapData(message));                String unregType = data.fType;                String unregSubtype = data.fSubtype;                boolean unregWithEventService = true;                // Only unregister with the Event Service if there are no                // other fRegTable entries with this type and subtype                for (Enumeration e = fRegTable.elements();                    e.hasMoreElements();)                {                     EventManagerData1 theData =                        (EventManagerData1) e.nextElement();                    if (unregType.equalsIgnoreCase(theData.fType) &&                        theData.fSubtype.equalsIgnoreCase(unregSubtype))                    {                        unregWithEventService = false;                    }                }                if (unregWithEventService)                {                    String unRegisterRequest = "UNREGISTER TYPE " + unregType;                    if (!(data.fSubtype.equals("")))                    {                        unRegisterRequest += " SUBTYPE " + unregSubtype;                    }                        // Unregister with the Event service                    STAFResult unRegisterResult = fHandle.submit2(                        fEventServiceMachine, fEventServiceName,                        unRegisterRequest);                    if (unRegisterResult.rc != 0)                    {                        return unRegisterResult;                    }                }            }        }        catch (Exception e)        {            if (DEBUG)            {                e.printStackTrace();            }

⌨️ 快捷键说明

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