📄 eventmanagerservice.java
字号:
"eventServiceName", "Event Service Name"); // Construct map class for a TRIGGER request fTriggerMapClass = new STAFMapClassDefinition( "STAF/Service/EventManager/Trigger"); fTriggerMapClass.addKey("machine", "Machine"); fTriggerMapClass.addKey("requestNumber", "Request Number"); // Resolve the file separator variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Sep/File}", fHandle); if (res.rc != STAFResult.Ok) return res; String fileSep = res.result; // Store data for the eventmanager service in directory: // <STAF writeLocation>/service/<em service name (lower-case)> fHashtableFileDirectory = info.writeLocation; if (!fHashtableFileDirectory.endsWith(fileSep)) { fHashtableFileDirectory += fileSep; } fHashtableFileDirectory = fHashtableFileDirectory + "service" + fileSep + fServiceName.toLowerCase(); File dir = new File(fHashtableFileDirectory); if (!dir.exists()) { dir.mkdirs(); } fHashtableFileName = fHashtableFileDirectory + fileSep + "eventman.ser"; loadHashtable(); /* Register RCs with the HELP service */ rc = this.registerHelp(info.name); if (rc != STAFResult.Ok) return new STAFResult(rc, "Error registering RCs with HELP service."); fQueueThread = new Thread(this); fQueueThread.start(); // this calls the run() method } catch (STAFException e) { rc = STAFResult.STAFRegistrationError; return new STAFResult(rc, 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 { STAFCommandParseResult parseResult= fParmsParser.parse(info.parms); if (parseResult.rc != STAFResult.Ok) { return new STAFResult( STAFResult.InvalidRequestString, parseResult.errorBuffer); } if (parseResult.optionTimes("EVENTSERVICEMACHINE") > 0) { STAFResult res = STAFUtil.resolveInitVar( parseResult.optionValue("EVENTSERVICEMACHINE"), fHandle); if (res.rc != STAFResult.Ok) return res; fEventServiceMachine = res.result; } if (parseResult.optionTimes("EVENTSERVICENAME") > 0) { STAFResult res = STAFUtil.resolveInitVar( parseResult.optionValue("EVENTSERVICENAME"), fHandle); if (res.rc != STAFResult.Ok) return res; fEventServiceName = res.result; } 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 EventManager 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 the help text for the service return new STAFResult(STAFResult.Ok, "EventManager Service Help" + fLineSep + fLineSep + "REGISTER [DESCRIPTION <description>]" + fLineSep + " MACHINE <machine> | PYTHONMACHINE <machine>" + fLineSep + " SERVICE <service> | PYTHONSERVICE <machine>" + fLineSep + " REQUEST <request> | PYTHONREQUEST <request>" + fLineSep + " TYPE <eventType> [SUBTYPE <eventSubType>]" + fLineSep + " [PREPARE <script>]" + fLineSep + "UNREGISTER ID <registrationID>" + fLineSep + "LIST <[MACHINE <machine>] [TYPE <eventType>] " + "[LONG | SHORT]> | SETTINGS" + 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 emIDList = 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; if (parsedRequest.optionTimes("SETTINGS") > 0) { // LIST SETTINGS mc.setMapClassDefinition(fSettingsMapClass); Map outputMap = fSettingsMapClass.createInstance(); outputMap.put( "eventServiceMachine", fEventServiceMachine); outputMap.put( "eventServiceName", fEventServiceName); mc.setRootObject(outputMap); return new STAFResult(STAFResult.Ok, mc.marshall()); } // Process the LIST registrationss 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; // Resolve the TYPE option resolvedValue = STAFUtil.resolveRequestVar( parsedRequest.optionValue("type"), fHandle, info.requestNumber); if (resolvedValue.rc != 0) return resolvedValue; typeParm = resolvedValue.result; // Check if the LONG or SHORT options is specified boolean longFormat = false; boolean shortFormat = false; if (parsedRequest.optionTimes("LONG") > 0) { longFormat = true; mc.setMapClassDefinition(fEventManagerIDMapClass); } else if (parsedRequest.optionTimes("SHORT") > 0) { shortFormat = true; mc.setMapClassDefinition(fEMIDShortMapClass); } else { mc.setMapClassDefinition(fEMIDMapClass); } EventManagerData1 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 = (EventManagerData1) fRegTable.get(id); if (machineParm.equals("") || machineParm.equalsIgnoreCase(theData.fMachine)) { if (typeParm.equals("") || typeParm.equalsIgnoreCase(theData.fType)) { match = true; } } if (match) { // Create a map representing the matching registration // and add it to the list of registrations Map emIDMap; if (longFormat) emIDMap = fEventManagerIDMapClass.createInstance(); else if (shortFormat) emIDMap = fEMIDShortMapClass.createInstance(); else emIDMap = fEMIDMapClass.createInstance(); emIDMap.put("eventManagerID", id.toString()); if (!theData.fDescription.equals("")) { emIDMap.put("description", theData.fDescription); } emIDMap.put("machine", theData.fMachine); emIDMap.put("service", theData.fService); emIDMap.put("request", STAFUtil.maskPrivateData( theData.fRequest)); if (!shortFormat) { emIDMap.put("type", theData.fType); } if ((theData.fSubtype != null) && (!theData.fSubtype.equals("")) & !shortFormat) { emIDMap.put("subtype", theData.fSubtype); } if (longFormat) { if (theData.fPythonMachine) emIDMap.put("machineType", "Python"); else emIDMap.put("machineType", "Literal"); if (theData.fPythonService)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -