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

📄 cronservice.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                return new STAFResult(rc,                     "Error registering RCs with HELP service.");            fQueueThread = new Thread(this);            fQueueThread.start(); // this calls the run() method        }        catch (STAFException e)        {            return new STAFResult(STAFResult.STAFRegistrationError,                                  e.toString());        }        return new STAFResult(rc);    }    private int registerHelp(String name)    {        try        {            String request = "REGISTER SERVICE " + name + " ERROR " +                PYTHONERROR + " INFO \"" + PYTHONERRORInfo + "\" DESCRIPTION \""                + PYTHONERRORDesc + "\"";            fHandle.submit("LOCAL", "HELP", request);            request = "REGISTER SERVICE " + name + " ERROR " +                REQUESTNOTSUBMITTED + " INFO \"" + REQUESTNOTSUBMITTEDInfo +                "\" DESCRIPTION \"" + REQUESTNOTSUBMITTEDDesc + "\"";            fHandle.submit("LOCAL", "HELP", request);        }        catch(STAFException se)        {            return se.rc;        }        return STAFResult.Ok;    }    private STAFResult handleParms(STAFServiceInterfaceLevel30.InitInfo info)        throws STAFException    {        return new STAFResult(STAFResult.Ok);    }    public STAFResult acceptRequest(STAFServiceInterfaceLevel30.RequestInfo info)    {        String lowerRequest = info.request.toLowerCase();        // call the appropriate method to handle the command        if (lowerRequest.startsWith("register"))        {            return handleRegister(info);        }        else if (lowerRequest.startsWith("unregister"))        {            return handleUnregister(info);        }        else if (lowerRequest.startsWith("list"))        {            return handleList(info);        }        else if (lowerRequest.startsWith("trigger"))        {            return handleTrigger(info);        }        else if (lowerRequest.startsWith("help"))        {            return handleHelp(info);        }        else if (lowerRequest.startsWith("version"))        {            return handleVersion(info);        }        else        {            return new STAFResult(STAFResult.InvalidRequestString,                                  "Unknown Cron Request: " +                                  lowerRequest);        }    }    private STAFResult handleHelp(STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 1        STAFResult trustResult = STAFUtil.validateTrust(            1, fServiceName, "HELP", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Return help text        return new STAFResult(STAFResult.Ok,         "Cron Service Help" + fLineSep         + "REGISTER   [DESCRIPTION <description>]"         + fLineSep +         "           MACHINE <machine> | PYTHONMACHINE <machine>"         + fLineSep +         "           SERVICE <service> | PYTHONSERVICE <machine>"         + fLineSep +         "           REQUEST <request> | PYTHONREQUEST <request>"         + fLineSep + "           [PREPARE <script>]"         + fLineSep + "           [MINUTE <minute>] [HOUR <hour>] "         + fLineSep + "           [DAY <day>] [MONTH <month>] "         + fLineSep + "           [WEEKDAY <weekday>]"         + fLineSep + "           [ONCE]"         + fLineSep + "UNREGISTER ID <registrationID>"         + fLineSep + "LIST       [MACHINE <machine>] [LONG | SHORT]"         + fLineSep + "TRIGGER    ID <registrationID> [SCRIPT <Python code>]..."         + fLineSep + "VERSION    [JYTHON]" + fLineSep + "HELP");    }    private STAFResult handleList(STAFServiceInterfaceLevel30.RequestInfo info)    {        STAFCommandParseResult parsedRequest = fListParser.parse(info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(                STAFResult.InvalidRequestString, parsedRequest.errorBuffer);        }        STAFMarshallingContext mc = new STAFMarshallingContext();        List cronIDList = new ArrayList();        STAFResult sResult = new STAFResult(STAFResult.Ok, "");        STAFResult resolvedResult = null;        STAFResult resolvedValue = null;        String machineParm = "";        String typeParm = "";        try        {            // Verify the requester has at least trust level 2            STAFResult trustResult = STAFUtil.validateTrust(                2, fServiceName, "LIST", fLocalMachineName, info);            if (trustResult.rc != STAFResult.Ok) return trustResult;            // Process the list request            int registrationTableSize = fRegTable.size();            if (registrationTableSize > 0)            {                // Resolve the MACHINE option                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("machine"),                    fHandle, info.requestNumber);                if (resolvedValue.rc != 0) return resolvedValue;                machineParm = resolvedValue.result;                // Check if the LONG or SHORT options are specified                boolean longFormat = false;                boolean shortFormat = false;                if (parsedRequest.optionTimes("LONG") > 0)                {                    longFormat = true;                    mc.setMapClassDefinition(fCronIDLongMapClass);                }                else if (parsedRequest.optionTimes("SHORT") > 0)                {                    shortFormat = true;                    mc.setMapClassDefinition(fCronIDShortMapClass);                }                else                {                    mc.setMapClassDefinition(fCronIDMapClass);                }                CronData1 theData;                boolean match;                int numberOfKeys = fRegTable.size();                Integer[] ids = new Integer[numberOfKeys];                Enumeration idKeys = fRegTable.keys();                for (int i = 0; idKeys.hasMoreElements(); i++)                {                    ids[i] = (Integer)idKeys.nextElement();                }                Arrays.sort(ids);                for (int i = 0; i < numberOfKeys; i++)                {                    Integer id = ids[i];                    match = false;                    theData = (CronData1) fRegTable.get(id);                    String description = "";                    String minutes = "";                    String hours = "";                    String days = "";                    String months = "";                    String weekdays = "";                    if (machineParm.equals("") |                        machineParm.equals(theData.fMachine))                    {                        description = theData.fDescription;                         Enumeration minuteEnum = theData.fMinute.elements();                        while (minuteEnum.hasMoreElements())                        {                            minutes += (minuteEnum.nextElement()).toString();                            if (minuteEnum.hasMoreElements())                                minutes += ",";                        }                        Enumeration hourEnum = theData.fHour.elements();                        while (hourEnum.hasMoreElements())                        {                            hours += (hourEnum.nextElement()).toString();                            if (hourEnum.hasMoreElements())                                hours += ",";                        }                        Enumeration dayEnum = theData.fDay.elements();                        while (dayEnum.hasMoreElements())                        {                            days += (dayEnum.nextElement()).toString();                            if (dayEnum.hasMoreElements())                                days += ",";                        }                        Enumeration monthEnum = theData.fMonth.elements();                        while (monthEnum.hasMoreElements())                        {                            months += (monthEnum.nextElement()).toString();                            if (monthEnum.hasMoreElements())                                months += ",";                        }                        Enumeration weekdayEnum = theData.fWeekday.elements();                        while (weekdayEnum.hasMoreElements())                        {                            weekdays += (weekdayEnum.nextElement()).toString();                            if (weekdayEnum.hasMoreElements())                                weekdays += ",";                        }                        // Create a map representing the matching registration                        // and add it to the list of registrations                        Map cronIDMap;                        if (longFormat)                            cronIDMap = fCronIDLongMapClass.createInstance();                        else if (shortFormat)                            cronIDMap = fCronIDShortMapClass.createInstance();                        else                            cronIDMap = fCronIDMapClass.createInstance();                        cronIDMap.put("cronID", id.toString());                        if (!theData.fDescription.equals(""))                        {                            cronIDMap.put("description", theData.fDescription);                        }                        cronIDMap.put("machine", theData.fMachine);                        cronIDMap.put("service", theData.fService);                        cronIDMap.put("request", STAFUtil.maskPrivateData(                            theData.fRequest));                                                if ((minutes != null) && (!minutes.equals(""))                            && !shortFormat)                        {                            cronIDMap.put("minute", minutes);                        }                        if ((hours != null) && (!hours.equals(""))                            && !shortFormat)                        {                            cronIDMap.put("hour", hours);                        }                        if ((days != null) && (!days.equals(""))                            && !shortFormat)                        {                            cronIDMap.put("dayOfMonth", days);                        }                        if ((months != null) && (!months.equals(""))                            && !shortFormat)                        {                            cronIDMap.put("month", months);                        }                        if ((weekdays != null) && (!weekdays.equals(""))                            && !shortFormat)                        {                            cronIDMap.put("dayOfWeek", weekdays);                        }                        if (!shortFormat)                        {                            cronIDMap.put("once",                                 new Boolean(theData.fOnce).toString());                        }                        if (longFormat)                        {                            if (theData.fPythonMachine)                                cronIDMap.put("machineType", "Python");                            else                                cronIDMap.put("machineType", "Literal");                            if (theData.fPythonService)                                cronIDMap.put("serviceType", "Python");                            else                                cronIDMap.put("serviceType", "Literal");                            if (theData.fPythonRequest)                                cronIDMap.put("requestType", "Python");                            else                                cronIDMap.put("requestType", "Literal");                            if ((theData.fPrepare != null) &&                                (!theData.fPrepare.equals("")))                            {                                cronIDMap.put("prepareScript",                                              theData.fPrepare);                            }                        }                        cronIDList.add(cronIDMap);                    }                }            }        }        catch (Exception e)        {            if (DEBUG)            {                e.printStackTrace();            }            return new STAFResult(STAFResult.JavaError,                                  "Internal Java error.");        }        mc.setRootObject(cronIDList);        return new STAFResult(STAFResult.Ok, mc.marshall());    }    private STAFResult handleTrigger(STAFServiceInterfaceLevel30.RequestInfo                                      info)    {        STAFResult sResult = new STAFResult(STAFResult.Ok, "");        STAFResult resolvedResult = null;        STAFResult resolvedValue = null;

⌨️ 快捷键说明

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