📄 cronservice.java
字号:
int numericWeekday = getNumericWeekday(element); if (numericWeekday == -1) { result.add(element); } else { result.add(new String( new Integer(numericWeekday).toString())); } } else { result.add(element); } } else { // Range was specified if (element.indexOf("-", firstDashIndex + 1) > -1) { // Invalid. Can only contain one dash. return null; } StringTokenizer items = new StringTokenizer(element, "-"); String start = null; String end = null; while (items.hasMoreElements()) { if (start == null) start = ((String)items.nextElement()).trim(); else end = ((String)items.nextElement()).trim(); } // Verify that the values specified for the range are valid if (!isValidValue(start, type)) return null; if (!isValidValue(end, type)) return null; // Types other than weekday will always contain numeric values // A Weekday type can contain a numeric value or a string value if (!type.equals(kWeekday)) { // Type is kMonth, kDay, kHour, or kMinute // Iterate through the numeric range int startNum = new Integer(start).intValue(); int endNum = new Integer(end).intValue(); for (int i = startNum; i <= endNum; i++) { result.add(new String(new Integer(i).toString())); } } else { // Type is kWeekday // Check if using string or numeric values for weekday. boolean startIsNumeric = true; boolean endIsNumeric = true; if (equalsWeekday(start)) startIsNumeric = false; if (equalsWeekday(end)) endIsNumeric = false; int startNum = 0; int endNum = 0; // Get the corresponding numeric value for weekday if // specified as a string, e.g. 0 for "Sunday". if (startIsNumeric) startNum = new Integer(start).intValue(); else startNum = getNumericWeekday(start); if (endIsNumeric) endNum = new Integer(end).intValue(); else endNum = getNumericWeekday(end); // Iterate throught the range, using the String or numeric // representation based on the start value. for (int i = startNum; i <= endNum; i++) { result.add(new String(new Integer(i).toString())); } } } } return result; } boolean isValidValue(String value, String type) { if (value == null) return false; int valueNum = 0; if (type.equals(kWeekday)) { if (equalsWeekday(value)) return true; } try { valueNum = new Integer(value).intValue(); } catch (NumberFormatException ex) { return false; } if (type.equals(kMinute)) { if (valueNum >= 0 && valueNum <= 59) return true; else return false; } else if (type.equals(kHour)) { if (valueNum >= 0 && valueNum <= 23) return true; else return false; } else if (type.equals(kDay)) { if (valueNum >= 1 && valueNum <= 31) return true; else return false; } else if (type.equals(kMonth)) { if (valueNum >= 1 && valueNum <= 12) return true; else return false; } else if (type.equals(kWeekday)) { if (valueNum >= 0 && valueNum <= 6) return true; else return false; } else { return false; } } private boolean equalsWeekday(String msg) { if ((msg.equalsIgnoreCase("Sunday")) || (msg.equalsIgnoreCase("Monday")) || (msg.equalsIgnoreCase("Tuesday")) || (msg.equalsIgnoreCase("Wednesday")) || (msg.equalsIgnoreCase("Thursday")) || (msg.equalsIgnoreCase("Friday")) || (msg.equalsIgnoreCase("Saturday"))) { return true; } else { return false; } } private int getNumericWeekday(String weekday) { if (weekday.equalsIgnoreCase("Sunday")) return 0; else if (weekday.equalsIgnoreCase("Monday")) return 1; else if (weekday.equalsIgnoreCase("Tuesday")) return 2; else if (weekday.equalsIgnoreCase("Wednesday")) return 3; else if (weekday.equalsIgnoreCase("Thursday")) return 4; else if (weekday.equalsIgnoreCase("Friday")) return 5; else if (weekday.equalsIgnoreCase("Saturday")) return 6; else return -1; } private String getStringWeekday(int weekday) { if (weekday == 0) return "Sunday"; else if (weekday == 1) return "Monday"; else if (weekday == 2) return "Tuesday"; else if (weekday == 3) return "Wednesday"; else if (weekday == 4) return "Thursday"; else if (weekday == 5) return "Friday"; else if (weekday == 6) return "Saturday"; else return ""; } public void run() { Calendar initialTimestamp = Calendar.getInstance(); int lastMinute = initialTimestamp.get(Calendar.MINUTE); int lastHour = initialTimestamp.get(Calendar.HOUR_OF_DAY); int lastDay = initialTimestamp.get(Calendar.DAY_OF_MONTH); // MONTH is 0-based, so add 1 int lastMonth = initialTimestamp.get(Calendar.MONTH) + 1; int lastWeekday = initialTimestamp.get(Calendar.DAY_OF_WEEK); int currentMinute; int currentHour; int currentDay; int currentMonth; int currentWeekday; boolean minuteChanged = false; boolean hourChanged = false; boolean dayChanged = false; boolean monthChanged = false; boolean weekdayChanged = false; STAFResult queueGetResult; for (;;) { queueGetResult = fHandle.submit2( "local", "QUEUE", "GET WAIT 10000"); if (queueGetResult.rc == 0) { STAFQueueMessage queueMessage = new STAFQueueMessage( queueGetResult.result); String queueType = queueMessage.type; String queueMachine = queueMessage.machine; if (queueType.equalsIgnoreCase(sQueueTypeEnd)) { // This type of queued message indicates that the service // is terminating try { fHandle.unRegister(); } catch (STAFException ex) { if (DEBUG) { ex.printStackTrace(); } } return; } else if (queueType.equalsIgnoreCase("STAF/RequestComplete")) { // A STAF/RequestComplete message is a map containing keys: // requestNumber, rc, result Map messageMap = (Map)queueMessage.message; String queueMachineName = ""; String reqNum = (String)messageMap.get("requestNumber"); String rc = (String)messageMap.get("rc"); Object result = (Object)messageMap.get("result"); // Log a message about the completed request String level = ""; if (rc.equals("0")) level = "Pass"; else level = "Fail"; String request = (String)fSubmittedRequests.get(reqNum); STAFResult varRequest = fHandle.submit2(queueMachine, "VAR", "RESOLVE STRING {STAF/Config/Machine}"); queueMachineName = varRequest.result; String id = (String)(fRequestsAndIDs.get(queueMachineName + ":" + reqNum)); fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL " + level + " MESSAGE " + STAFUtil.wrapData("[ID=" + id + "] [" + queueMachineName + ":" + reqNum + "] Completed a STAF command. RC=" + rc + ", Result=" + result.toString())); // handle process service start requests String lowerRequest = request.toLowerCase(); if ((lowerRequest.indexOf("service=process") > -1) && (lowerRequest.indexOf("request=start") > -1) && (lowerRequest.indexOf("wait") == -1)) { String machine = queueMessage.machine; String handle = result.toString(); STAFResult notifyRegResult; STAFResult machineRequest = fHandle.submit2(machine, "VAR", "RESOLVE STRING {STAF/Config/Machine}"); String machineName = machineRequest.result; fProcessHandlesAndRequests.put(machineName + ":" + handle, machineName + ":" + reqNum); notifyRegResult = fHandle.submit2(machine, "process", "notify register onendofhandle " + handle); if (notifyRegResult.rc != 0) { fHandle.submit2( "local", "log", "log machine logname " + fServiceName + " level error message " + STAFUtil.wrapData("[ID=" + id + "] [" + queueMachine + ":" + reqNum + "] Process completion notification to " + " machine " + machine + "failed for" +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -