📄 eventmanagerservice.java
字号:
emIDMap.put("serviceType", "Python"); else emIDMap.put("serviceType", "Literal"); if (theData.fPythonRequest) emIDMap.put("requestType", "Python"); else emIDMap.put("requestType", "Literal"); if ((theData.fPrepare != null) && (!theData.fPrepare.equals(""))) { emIDMap.put("prepareScript", theData.fPrepare); } } emIDList.add(emIDMap); } } } } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } return new STAFResult(STAFResult.JavaError, "Internal Java error."); } mc.setRootObject(emIDList); 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; Integer id; STAFCommandParseResult parsedRequest = fTriggerParser.parse(info.request); if (parsedRequest.rc != STAFResult.Ok) { return new STAFResult( STAFResult.InvalidRequestString, parsedRequest.errorBuffer); } try { // Verify the requester has at least trust level 5 STAFResult trustResult = STAFUtil.validateTrust( 5, fServiceName, "TRIGGER", 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 { // Create a marshalling context and set any map classes (if any) STAFMarshallingContext mc = new STAFMarshallingContext(); mc.setMapClassDefinition(fTriggerMapClass); // Create an empty result map to contain the result Map resultMap = fTriggerMapClass.createInstance(); // Handle any SCRIPT options int scriptCount = parsedRequest.optionTimes("script"); LinkedList scripts = new LinkedList(); if (scriptCount > 0) { for (int i = 1; i <= scriptCount; i++) { resolvedValue = STAFUtil.resolveRequestVar( parsedRequest.optionValue("script", i), fHandle, info.requestNumber); scripts.add(resolvedValue.result); } } String triggerMsg = "[ID=" + id + "] [" + info.endpoint + ", " + info.handleName + "] Triggering a STAF command.\n" + info.request; fHandle.submit2("local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL info MESSAGE " + STAFUtil.wrapData(triggerMsg)); EventManagerData1 theData = (EventManagerData1)fRegTable.get(id); String machine = theData.fMachine; String service = theData.fService; String request = theData.fRequest; String prepare = theData.fPrepare; boolean pythonMachine = theData.fPythonMachine; boolean pythonService = theData.fPythonService; boolean pythonRequest = theData.fPythonRequest; STAFResult varRequest = fHandle.submit2(machine, "VAR", "RESOLVE STRING {STAF/Config/Machine}"); String machineName = varRequest.result; // Used in the log records // Check if any Python data was provided in the registration if ((prepare != null && !prepare.equals("")) || pythonMachine || pythonService || pythonRequest || scripts.size() > 0) { String regInfoMsg = " ID: " + id.toString() + "\n machine: " + machine + "\n service: " + service + "\n request: " + request + "\n prepare: " + prepare; // Create a new Python Interpreter for each registration fPythonInterpreter = new PythonInterpreter(); // First execute any SCRIPT options for (int j = 0; j < scripts.size(); j++) { String script = (String)scripts.get(j); try { pyExec(script); } catch (PyException e) { String pythonError = "Python error in the " + "SCRIPT value.\n\nSCRIPT:\n" + script + "\n\nPyException:\n" + e + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } // Evaluate any Python data provided in the registration if (prepare != null && !prepare.equals("")) { pySetVar("STAFEventManagerSubmit", "true"); try { pyExec(prepare); } catch (PyException e) { String pythonError = "Python error in the " + "PREPARE value.\n\nPREPARE:\n" + prepare + "\n\nPyException:\n" + e + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } Object submit = pyGetVar("STAFEventManagerSubmit"); if ((submit == null) || (!submit.toString().equals("true"))) { // Do not submit the request for this registration return new STAFResult(REQUESTNOTSUBMITTED, "STAFEventManagerSubmit=" + submit.toString()); } } if (pythonMachine) { try { machine = pyStringEval(theData.fMachine); } catch (PyException e) { String pythonError = "Python error in the " + "PYTHONMACHINE value.\n\nPYTHONMACHINE: " + theData.fMachine + "\n\nPyException:\n" + e + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } if (pythonService) { try { service = pyStringEval(theData.fService); } catch (PyException e) { String pythonError = "Python error in the " + "PYTHONSERVICE value.\n\nPYTHONSERVICE: " + theData.fService + "\n\nPyException:\n" + e + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } if (pythonRequest) { try { request = pyStringEval(theData.fRequest); } catch (PyException e) { String pythonError = "Python error in the " + "PYTHONREQUEST value.\n\nPYTHONREQUEST: " + theData.fRequest + "\n\nPyException:\n" + e + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } } STAFResult matchResult = fHandle.submit2( STAFHandle.ReqQueue, machine, service, request); sResult.result = matchResult.result; fSubmittedRequests.put( matchResult.result, "machine=" + machine + " service=" + service + " request=" + request); fRequestsAndIDs.put(machineName + ":" + matchResult.result, id.toString()); String message = "[ID=" + id.toString() + "] " + "[" + machineName + ":" + matchResult.result + "] " + "Submitted a STAF command.\nEvent information: N/A" + "\nSubmitted STAF command: STAF " + machine + " " + service + " " + request; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL info MESSAGE " + STAFUtil.wrapData(message)); resultMap.put("machine", machineName); resultMap.put("requestNumber", matchResult.result); // Set the result map as the root object for the marshalling // context and return the marshalled result mc.setRootObject(resultMap); return new STAFResult(STAFResult.Ok, mc.marshall()); } } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } return new STAFResult(STAFResult.JavaError, "Internal Java error."); } } private STAFResult handleRegister(STAFServiceInterfaceLevel30.RequestInfo info) { STAFResult sResult = new STAFResult(STAFResult.Ok, ""); String description = ""; String originMachine = info.endpoint; String machine = ""; boolean pythonMachine = true; String service = ""; boolean pythonService = true; String request = ""; boolean pythonRequest = true; String type = ""; String subtype = ""; String prepare = ""; STAFResult resolvedResult = null; STAFResult resolvedValue = null; STAFCommandParseResult parsedRequest = fRegisterParser.parse(info.request); if (parsedRequest.rc != STAFResult.Ok)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -