📄 stafsxe.java
字号:
case START: logMap.put("loopNum", String.valueOf(loopNum)); logMap.put("timestamp", getTime(startTime)); mc.setRootObject(logMap); logMessage = mc.marshall(); request = "LOG MACHINE LOGNAME " + logName + " LEVEL start MESSAGE " + STAFUtil.wrapData(logMessage); handle.submit2(where, service, request); break; case STOPPASS: level = "PASS"; case STOPFAIL: if (level == null) { level = "FAIL"; } /* Log Stop */ logMap.put("loopNum", String.valueOf(loopNum)); logMap.put("timestamp", getTime(stopTime)); mc.setRootObject(logMap); logMessage = mc.marshall(); request = "LOG MACHINE LOGNAME " + logName + " LEVEL stop MESSAGE " + STAFUtil.wrapData(logMessage); handle.submit2(where, service, request); /* Log Pass/Fail */ // Create a map containing the pass or fail information to log Map logMap2 = fLogPassFailMapClass.createInstance(); logMap2.put("loopNum", String.valueOf(loopNum)); logMap2.put("elapsedTime", getElapsedTime(startTime, stopTime)); logMap2.put("elapsedTarget", elapsedTargetString); logMap2.put("elapsedTolerance", String.valueOf(elapsedTolerance)); STAFMarshallingContext mc2 = new STAFMarshallingContext(); mc2.setRootObject(logMap2); mc2.setMapClassDefinition(fLogPassFailMapClass); logMessage = mc2.marshall(); request = "LOG MACHINE LOGNAME " + logName + " LEVEL " + level + " MESSAGE " + STAFUtil.wrapData(logMessage); handle.submit2(where, service, request); break; } }}/** * Resolves command parameters and prepares to execute the specified file. * Controls number of times file is executed. */private STAFResult handleExecute( STAFServiceInterfaceLevel30.RequestInfo reqInfo){ // Verify the requester has at least trust level 3 STAFResult trustResult = STAFUtil.validateTrust( 3, fServiceName, "EXECUTE", fLocalMachineName, reqInfo); if (trustResult.rc != STAFResult.Ok) return trustResult; /* Parse command */ STAFCommandParseResult pResult = sxeParser.parse(reqInfo.request); if (pResult.rc != STAFResult.Ok) { return new STAFResult(STAFResult.InvalidRequestString, pResult.errorBuffer); } /* get filename to process */ STAFResult res = STAFUtil.resolveRequestVar( pResult.optionValue(FILE), sHandle, reqInfo.requestNumber); if (res.rc != 0) return res; String filename = res.result; /* Get number of times to loop through file */ int numLoops = 1; //default of 1 boolean forever = false; if (pResult.optionTimes(LOOP) == 1) { try { res = STAFUtil.resolveRequestVar( pResult.optionValue(LOOP), sHandle, reqInfo.requestNumber); if (res.rc != 0) return res; numLoops = Integer.parseInt(res.result); if (numLoops <= 0) { return new STAFResult( STAFResult.InvalidValue, "Invalid LOOP value. Must be > 0 or FOREVER. LOOP=" + pResult.optionValue(LOOP)); } } catch (NumberFormatException nfe) { if (res.result.equalsIgnoreCase(FOREVER)) { // see if forever specified forever = true; } else { return new STAFResult( STAFResult.InvalidValue, "Invalid LOOP value. Must be > 0 or FOREVER. LOOP=" + pResult.optionValue(LOOP)); } } } /* Get minRuntime */ boolean useMinRuntime = false; long minRuntime = 0; if (pResult.optionTimes(MINRUNTIME) == 1) { res = STAFUtil.resolveRequestVar( pResult.optionValue(MINRUNTIME), sHandle, reqInfo.requestNumber); if (res.rc != 0) return res; String minRuntimeString = res.result; try { minRuntime = getTimeInMillis(minRuntimeString + ":0.0"); useMinRuntime = true; } catch (NumberFormatException nfe) { return new STAFResult( STAFResult.InvalidValue, "Invalid MINRUNTIME value. Format is HH:MM. MINRUNTIME=" + pResult.optionValue(MINRUNTIME)); } } /* Create a new STAFHandle for each file passed to SXE */ STAFHandle fHandle; try { fHandle = new STAFHandle(filename); } catch(STAFException se) { return new STAFResult(STAFResult.STAFRegistrationError, se.toString()); } STAFResult result = null; int loop; if (forever) { loop = 1; while(true) { //loop forever setSXELoopVar(loop, fHandle); result = execute(fHandle, filename, logName, loop); if (result.rc != STAFResult.Ok) { break; } loop++; } } else if (useMinRuntime) { //use the minRuntime parameter rather than loop loop = 1; long tcStartTime = new Date().getTime(); while(true) { result = execute(fHandle, filename, logName, loop); long tcStopTime = new Date().getTime(); if (result.rc != STAFResult.Ok) { break; } if (tcStopTime - tcStartTime >= minRuntime) { break; }//do checking for minruntime elapsed loop++; } } else { for (loop = 1; loop <= numLoops; loop++) { //loop set number of times setSXELoopVar(loop, fHandle); result = execute(fHandle, filename, logName, loop); if (result.rc != STAFResult.Ok) { break; } } } try { fHandle.unRegister(); } catch(STAFException se) { se.printStackTrace(); } return result;}/* * Handles a LIST SETTINGS request */private STAFResult handleList(STAFServiceInterfaceLevel30.RequestInfo info){ STAFMarshallingContext mc = new STAFMarshallingContext(); try { // Verify that the requesting machine/user has at least trust level 2 STAFResult trustResult = STAFUtil.validateTrust( 2, fServiceName, "LIST", fLocalMachineName, info); if (trustResult.rc != STAFResult.Ok) return trustResult; // Parse the request STAFCommandParseResult parsedRequest = fListParser.parse( info.request); if (parsedRequest.rc != STAFResult.Ok) { return new STAFResult(STAFResult.InvalidRequestString, parsedRequest.errorBuffer); } mc.setMapClassDefinition(fSettingsMapClass); Map outputMap = fSettingsMapClass.createInstance(); outputMap.put("logName", logName); mc.setRootObject(outputMap); return new STAFResult(STAFResult.Ok, mc.marshall()); } catch(Exception e) { return new STAFResult(STAFResult.JavaError, "Internal Java error."); }}/** * Registers return code information with the help service */private int registerHelp(String name){ try { String request = "REGISTER SERVICE " + name + " ERROR " + EXECUTIONERROR + " INFO \"" + EXECUTIONERRORInfo + "\" DESCRIPTION \""+ EXECUTIONERRORDesc + "\""; sHandle.submit("LOCAL", "HELP", request); request = "REGISTER SERVICE " + name + " ERROR " + ELAPSEDTIMEFAIL + " INFO \"" + ELAPSEDTIMEFAILInfo + "\" DESCRIPTION \"" + ELAPSEDTIMEFAILDesc+"\""; sHandle.submit("LOCAL", "HELP", request); request = "REGISTER SERVICE " + name + " ERROR " + ELAPSEDTIMEERROR + " INFO \"" + ELAPSEDTIMEERRORInfo + "\" DESCRIPTION \"" + ELAPSEDTIMEERRORDesc + "\""; sHandle.submit("LOCAL", "HELP", request); } catch(STAFException se) { return se.rc; } return STAFResult.Ok;}/** * Un-registers return code information with the help service */private int unregisterHelp(String name){ try { String request = "UNREGISTER SERVICE " + name + " ERROR " + EXECUTIONERROR; sHandle.submit("LOCAL", "HELP", request); request = "UNREGISTER SERVICE " + name + " ERROR " + ELAPSEDTIMEFAIL; sHandle.submit("LOCAL", "HELP", request); request = "UNREGISTER SERVICE " + name + " ERROR " + ELAPSEDTIMEERROR; sHandle.submit("LOCAL", "HELP", request); } catch(STAFException se) { return se.rc; } return STAFResult.Ok;}/** * Executes a staf command using the given handle. */private STAFResult sendSTAFCommand(STAFHandle handle, String command){ STAFResult result; String where = command.substring(0, command.indexOf(" ")); String service = command.substring( command.indexOf(" ")+1, command.indexOf(" ", command.indexOf(" ")+1)); String request = command.substring( command.indexOf(" ", command.indexOf(" ")+1)+1); return handle.submit2(where, service, request);}/** * Sets a handle variable "sxeloop" to the specified integer. */private void setSXELoopVar(int loopNum, STAFHandle fHandle){ String request = "SET VAR sxeloop=" + String.valueOf(loopNum); fHandle.submit2("LOCAL", "VAR", request);}/** * Required by implemented STAF interface. * This method is called when shutting the service down. */public STAFResult term(){ // Un-register Help data int rc = unregisterHelp(fServiceName); if (rc != STAFResult.Ok) return new STAFResult(rc, "Error unregistering HELP data."); // Un-register the service handle try { sHandle.unRegister(); } catch (STAFException ex) { if (rc == STAFResult.Ok) { rc = STAFResult.STAFRegistrationError; } return new STAFResult(rc, ex.toString()); } return new STAFResult(rc);}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -