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

📄 staxprocessaction.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (result.rc == 0)        {            boolean processComplete = false;            try            {                // XXX: Why do we store the handle in "int" form instead of                //      just storing the handle in "string" form                fProcessHandle = Integer.parseInt(result.result);                fState = WAIT_PROCESS;                // Register for Process Completion                String key = new String();                String machine = fLocation;                                if (fUsingProcessKeyOption)                {                    key = fProcessKey;                }                else                {                    key = machine + "/" + fProcessHandle;                }                HashMap processMap =                        (HashMap)fThread.getJob().getData("processMap");                synchronized (processMap)                {                    // If we have a race condition, we may have already                    // received the "process end" message                                                if (processMap.containsKey(key))                    {                        if (debug)                        {                            System.out.println(                                "STAXProcessAction::requestComplete(): " +                                 "Race condition - remove from processMap");                        }                        STAXSTAFMessage completionMessage =                             (STAXSTAFMessage)processMap.get(key);                                                        processMap.remove(key);                                                    processComplete(machine, fProcessHandle,                            completionMessage.getProcessRC(),                             completionMessage.getProcessResultAsList(),                            completionMessage.getProcessTimestamp());                        processComplete = true;                    }                    else                    {                        if (debug)                        {                            System.out.println(                                "STAXProcessAction::requestComplete(): " +                                "Not race condition: add to processMap");                        }                        processMap.put(key.toLowerCase(), this);                    }                }            }            catch (NumberFormatException e)            {                // XXX: Do something.  Maybe set fState = ERROR?            }            if (!processComplete)            {                // Add the process to the processRequestMap                 String key = fLocation + ":" + fProcessHandle;                TreeMap processes = (TreeMap)fThread.getJob().                                    getData("processRequestMap");                synchronized (processes)                {                    if (debug)                    {                        System.out.println(                            "STAXProcessAction::requestComplete(): " +                            "Add to processRequestMap");                    }                    processes.put(key.toLowerCase(), this);                }                // Generate a process start event                generateProcessStartEvent();            }                    synchronized (fThreadMap)            {                if ((fProcessAction != null) && fProcessActionFlag)                {                    fThread.pySetVar("STAXProcessHandle",                         String.valueOf(fProcessHandle));                                          STAXThread childThread = fThread.createChildThread();                                         fThreadMap.put(new                         Integer(childThread.getThreadNumber()),                         childThread);                                        STAXAction childThreadAction = fProcessAction;                                       childThread.addCompletionNotifiee(this);                    childThread.pushAction(                        childThreadAction.cloneAction());                    childThread.schedule();                }            }        }        else        {            if ((result.rc == STAFResult.InvalidRequestString) &&                fUsingProcessKeyOption)            {                // The target machine may not support the KEY option,                // so re-submit the request without the KEY option.                // If the second submit fails, then the InvalidRequestString                // is not due to the KEY option not being supported.                fUsingProcessKeyOption = false;                                // Submit PROCESS START STAF Command                STAFResult submitResult = fThread.getJob().submitAsync(                    fLocation, "process", "start notify onend " +                    fRequest, this);                                    if (submitResult.rc == 0 )                {                    fRequestNumber = (new Integer(submitResult.result)).                                                  intValue();                }                                if (fRequestNumber == 0)                {                    // Request failed - Raise a STAXProcessStartError signal                    fState = COMPLETE;                    fThread.popAction();                                        String msg = "<process>\n" +                        "\n  Name      : " + fName +                        "\n  Location  : " + fLocation +                        "\n  Service   : " + "PROCESS" +                        "\n  Request   : " + "START " + fRequest +                        "\n  RC        : " + submitResult.rc +                        "\n  STAFResult: " + submitResult.result;                    fThread.setSignalMsgVar("STAXProcessStartErrorMsg", msg);                    fThread.raiseSignal("STAXProcessStartError");                    return;                        }            }            else            {                fThread.pySetVar("STAFResult", result.result);                            fRequestRC = result.rc;                fRequestResult = result.result;                if (debug)                {                    System.out.println(                        "STAXProcessAction::requestComplete(): " +                        "set fState=REQUEST_ERROR and remove holdCondition " +                        "and schedule thread");                }                fState = REQUEST_ERROR;                fThread.removeCondition(fHoldCondition);                fThread.schedule();            }        }    }    public synchronized void processComplete(String machine, int handle,         long rc, List fileList, String timestamp)    {        if (debug)        {            System.out.println("STAXProcessAction::processComplete(): " +                               "fState=" + getStateAsString());        }        fThread.getJob().submitAsyncForget(fLocation, "process",            "free handle " + fProcessHandle);        if (fState == COMPLETE) return;               // We only generate the stop event if we aren't COMPLETE.  If we        // were terminated before the process finished, then we generated        // the stop event at that time.        generateProcessStopEvent();        // Remove the process from the processRequestMap         String key = fLocation + ":" + fProcessHandle;        TreeMap processes = (TreeMap)fThread.getJob().getData(            "processRequestMap");        synchronized (processes)        {            if (debug)            {                System.out.println("STAXProcessAction::processComplete(): " +                                   "Remove from processRequestMap");            }            processes.remove(key.toLowerCase());        }        fThread.pySetVar("RC", new Long(rc));        fProcessRC = rc;        PyList resultList = getResultList(fileList);        if (resultList != null)        {                      try            {                fThread.pySetVar("STAXResult", resultList);            }            catch (Exception ex)            {                // This should never happen                ex.printStackTrace();                String msg = "<process>\n" +                    "\n  Details : " + this.getDetails() +                    "\n  fileList: " + fileList +                    "\n\n  Error setting STAXResult to resultList." +                    "\n\n" + ex.toString();                fThread.setSignalMsgVar("STAXPythonEvalMsg", msg);                fThread.raiseSignal("STAXPythonEvaluationError");            }        }                   fProcessTimestamp = timestamp;        if (fThreadMap.isEmpty())        {            if (debug)            {                System.out.println("STAXProcessAction::processComplete(): " +                                   "remove condition and schedule thread");            }            fState = PROCESS_COMPLETE;            fThread.removeCondition(fHoldCondition);            fThread.schedule();        }        else        {            fState = PROCESS_COMPLETE_WAIT_ACTION;        }    }    public synchronized void threadComplete(STAXThread thread, int endCode)    {        synchronized(fThreadMap)        {            fThreadMap.remove(new Integer(thread.getThreadNumber()));            if (fThreadMap.isEmpty() &&                 (fState == PROCESS_COMPLETE_WAIT_ACTION))            {                if (debug)                {                    System.out.println(                        "STAXProcessAction::threadComplete(): " +                        "remove condition and schedule thread");                }                fState = PROCESS_COMPLETE;                fThread.removeCondition(fHoldCondition);                fThread.schedule();            }        }    }        public PyList getResultList(List fileList)    {        if (fileList == null || fileList.size() == 0) return null;        // Create a Python List to contain a list of returned file info:        //   [ [ File1 RC, File1 Data ], [ File2 RC, File2 Data ], ... ]         PyList resultList = new PyList();        Iterator iter = fileList.iterator();        try        {            while (iter.hasNext())            {                Map fileInfoMap = (Map)iter.next();                // Create a Python List to contain file information (RC & data)                PyList fileInfoList = new PyList();                // Assign file RC                fileInfoList.append(Py.java2py(                    new Integer((String)fileInfoMap.get("rc"))));                fileInfoList.append(Py.java2py(                    (String)fileInfoMap.get("data")));                // Add file information List to result List                resultList.append(fileInfoList);            }        }        catch (Exception ex)        {            // This should never happen            ex.printStackTrace();            String msg = "<process>\n" +                "\n  Details  : " + this.getDetails() +                "\n  File List: " + fileList.toString() +                "\n\n  Error getting STAXResult from result. " +                "Report to STAX Developers." +                "\n\n" + ex.toString();            fThread.setSignalMsgVar("STAXPythonEvalMsg", msg);            fThread.raiseSignal("STAXPythonEvaluationError");        }                return resultList;    }    // This method evaluates the process element/sub-elements and attribute    // values and generates a process start request and assigns it to fRequest.    // If an error occurs, it raises the appropriate signal and returns a     //non-zero value.    private int generateProcessStartRequest()    {        StringBuffer request = new StringBuffer("");        String evalElem = "";        String evalAttr = "";        try        {            // Set RC initially so if an error occurs (that does not            // terminate the job) before a process request is            // submitted, <if expr="RC != 0"> won't fail.            fThread.pySetVar("RC", new Integer(-1));            // Set initial values for other variables set by process            fThread.pySetVar("STAFResult", Py.None);            fThread.pySetVar("STAXResult", Py.None);            fThread.pySetVar("STAXProcessHandle", new Integer(0));            evalElem = "location";            fLocation = fThread.pyStringEval(fUnevalLocation);            if (!fName.equals(""))             {                evalElem = "process";                evalAttr = "name";                fName = fThread.pyStringEval(fUnevalName);            }            else            {

⌨️ 快捷键说明

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