Merge remote-tracking branch 'origin/fix-bug-202303' into fix-bug-202303
This commit is contained in:
+73
-61
@@ -17,18 +17,11 @@
|
||||
|
||||
package com.xxl.job.admin.core.cron;
|
||||
|
||||
import lombok.val;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Provides a parser and evaluator for unix-like cron expressions. Cron
|
||||
@@ -191,13 +184,11 @@ import java.util.TreeSet;
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Sharada Jambula, James House
|
||||
* @author Contributions from Mads Henderson
|
||||
* @author Refactoring from CronTrigger to CronExpression by Aaron Craven
|
||||
*
|
||||
* <p>
|
||||
* Borrowed from quartz v2.3.1
|
||||
*
|
||||
*/
|
||||
public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
@@ -215,8 +206,9 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
protected static final Integer ALL_SPEC = ALL_SPEC_INT;
|
||||
protected static final Integer NO_SPEC = NO_SPEC_INT;
|
||||
|
||||
protected static final Map<String, Integer> monthMap = new HashMap<String, Integer>(20);
|
||||
protected static final Map<String, Integer> dayMap = new HashMap<String, Integer>(60);
|
||||
protected static final Map<String, Integer> monthMap = new HashMap<>(20);
|
||||
protected static final Map<String, Integer> dayMap = new HashMap<>(60);
|
||||
|
||||
static {
|
||||
monthMap.put("JAN", 0);
|
||||
monthMap.put("FEB", 1);
|
||||
@@ -265,8 +257,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
*
|
||||
* @param cronExpression String representation of the cron expression the
|
||||
* new object should represent
|
||||
* @throws java.text.ParseException
|
||||
* if the string expression cannot be parsed into a valid
|
||||
* @throws java.text.ParseException if the string expression cannot be parsed into a valid
|
||||
* <CODE>CronExpression</CODE>
|
||||
*/
|
||||
public CronExpression(String cronExpression) throws ParseException {
|
||||
@@ -283,8 +274,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
* Constructs a new {@code CronExpression} as a copy of an existing
|
||||
* instance.
|
||||
*
|
||||
* @param expression
|
||||
* The existing cron expression to be copied
|
||||
* @param expression The existing cron expression to be copied
|
||||
*/
|
||||
public CronExpression(CronExpression expression) {
|
||||
/*
|
||||
@@ -363,8 +353,9 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
// the second immediately following it.
|
||||
while (difference == 1000) {
|
||||
newDate = getTimeAfter(lastDate);
|
||||
if(newDate == null)
|
||||
if (newDate == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
difference = newDate.getTime() - lastDate.getTime();
|
||||
|
||||
@@ -443,25 +434,25 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
try {
|
||||
|
||||
if (seconds == null) {
|
||||
seconds = new TreeSet<Integer>();
|
||||
seconds = new TreeSet<>();
|
||||
}
|
||||
if (minutes == null) {
|
||||
minutes = new TreeSet<Integer>();
|
||||
minutes = new TreeSet<>();
|
||||
}
|
||||
if (hours == null) {
|
||||
hours = new TreeSet<Integer>();
|
||||
hours = new TreeSet<>();
|
||||
}
|
||||
if (daysOfMonth == null) {
|
||||
daysOfMonth = new TreeSet<Integer>();
|
||||
daysOfMonth = new TreeSet<>();
|
||||
}
|
||||
if (months == null) {
|
||||
months = new TreeSet<Integer>();
|
||||
months = new TreeSet<>();
|
||||
}
|
||||
if (daysOfWeek == null) {
|
||||
daysOfWeek = new TreeSet<Integer>();
|
||||
daysOfWeek = new TreeSet<>();
|
||||
}
|
||||
if (years == null) {
|
||||
years = new TreeSet<Integer>();
|
||||
years = new TreeSet<>();
|
||||
}
|
||||
|
||||
int exprOn = SECOND;
|
||||
@@ -506,15 +497,13 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
TreeSet<Integer> dom = getSet(DAY_OF_MONTH);
|
||||
|
||||
// Copying the logic from the UnsupportedOperationException below
|
||||
assert dom != null;
|
||||
boolean dayOfMSpec = !dom.contains(NO_SPEC);
|
||||
boolean dayOfWSpec = !dow.contains(NO_SPEC);
|
||||
|
||||
if (!dayOfMSpec || dayOfWSpec) {
|
||||
if (!dayOfWSpec || dayOfMSpec) {
|
||||
if ((!dayOfMSpec || dayOfWSpec) && (!dayOfWSpec || dayOfMSpec)) {
|
||||
throw new ParseException(
|
||||
"Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 0);
|
||||
}
|
||||
}
|
||||
} catch (ParseException pe) {
|
||||
throw pe;
|
||||
} catch (Exception e) {
|
||||
@@ -532,7 +521,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
return i;
|
||||
}
|
||||
char c = s.charAt(i);
|
||||
if ((c >= 'A') && (c <= 'Z') && (!s.equals("L")) && (!s.equals("LW")) && (!s.matches("^L-[0-9]*[W]?"))) {
|
||||
if ((c >= 'A') && (c <= 'Z') && (!s.equals("L")) && (!s.equals("LW")) && (!s.matches("^L-\\d*W?"))) {
|
||||
String sub = s.substring(i, i + 3);
|
||||
int sval = -1;
|
||||
int eval = -1;
|
||||
@@ -668,8 +657,9 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
if (c == '-') {
|
||||
ValueSet vs = getValue(0, s, i + 1);
|
||||
lastdayOffset = vs.value;
|
||||
if(lastdayOffset > 30)
|
||||
if (lastdayOffset > 30) {
|
||||
throw new ParseException("Offset from last day must be <= 30", i + 1);
|
||||
}
|
||||
i = vs.pos;
|
||||
}
|
||||
if (s.length() > i) {
|
||||
@@ -732,8 +722,9 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
if (c == 'L') {
|
||||
if (type == DAY_OF_WEEK) {
|
||||
if(val < 1 || val > 7)
|
||||
if (val < 1 || val > 7) {
|
||||
throw new ParseException("Day-of-Week values must be between 1 and 7", -1);
|
||||
}
|
||||
lastdayOfWeek = true;
|
||||
} else {
|
||||
throw new ParseException("'L' option is not valid here. (pos=" + i + ")", i);
|
||||
@@ -750,8 +741,9 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
} else {
|
||||
throw new ParseException("'W' option is not valid here. (pos=" + i + ")", i);
|
||||
}
|
||||
if(val > 31)
|
||||
if (val > 31) {
|
||||
throw new ParseException("The 'W' option does not make sense with values larger than 31 (max number of days in a month)", i);
|
||||
}
|
||||
TreeSet<Integer> set = getSet(type);
|
||||
set.add(val);
|
||||
i++;
|
||||
@@ -796,7 +788,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
end = vs.value;
|
||||
i = vs.pos;
|
||||
}
|
||||
if (i < s.length() && ((c = s.charAt(i)) == '/')) {
|
||||
if (i < s.length() && ((s.charAt(i)) == '/')) {
|
||||
i++;
|
||||
c = s.charAt(i);
|
||||
int v2 = Integer.parseInt(String.valueOf(c));
|
||||
@@ -951,14 +943,19 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
}
|
||||
|
||||
protected int skipWhiteSpace(int i, String s) {
|
||||
for (; i < s.length() && (s.charAt(i) == ' ' || s.charAt(i) == '\t'); i++) {
|
||||
/*for (; i < s.length() && (s.charAt(i) == ' ' || s.charAt(i) == '\t'); i++) {
|
||||
}*/
|
||||
while (i < s.length() && (s.charAt(i) == ' ' || s.charAt(i) == '\t')){
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
protected int findNextWhiteSpace(int i, String s) {
|
||||
for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++) {
|
||||
/*for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++) {
|
||||
}*/
|
||||
while (i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t')){
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
@@ -991,13 +988,10 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
throw new ParseException(
|
||||
"Month values must be between 1 and 12", -1);
|
||||
}
|
||||
} else if (type == DAY_OF_WEEK) {
|
||||
if ((val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT)
|
||||
&& (val != NO_SPEC_INT)) {
|
||||
} else if ((type == DAY_OF_WEEK) && (val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT) && (val != NO_SPEC_INT)) {
|
||||
throw new ParseException(
|
||||
"Day-of-Week values must be between 1 and 7", -1);
|
||||
}
|
||||
}
|
||||
|
||||
if ((incr == 0 || incr == -1) && val != ALL_SPEC_INT) {
|
||||
if (val != -1) {
|
||||
@@ -1067,14 +1061,28 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
int max = -1;
|
||||
if (stopAt < startAt) {
|
||||
switch (type) {
|
||||
case SECOND : max = 60; break;
|
||||
case MINUTE : max = 60; break;
|
||||
case HOUR : max = 24; break;
|
||||
case MONTH : max = 12; break;
|
||||
case DAY_OF_WEEK : max = 7; break;
|
||||
case DAY_OF_MONTH : max = 31; break;
|
||||
case YEAR : throw new IllegalArgumentException("Start year must be less than stop year");
|
||||
default : throw new IllegalArgumentException("Unexpected type encountered");
|
||||
case SECOND:
|
||||
max = 60;
|
||||
break;
|
||||
case MINUTE:
|
||||
max = 60;
|
||||
break;
|
||||
case HOUR:
|
||||
max = 24;
|
||||
break;
|
||||
case MONTH:
|
||||
max = 12;
|
||||
break;
|
||||
case DAY_OF_WEEK:
|
||||
max = 7;
|
||||
break;
|
||||
case DAY_OF_MONTH:
|
||||
max = 31;
|
||||
break;
|
||||
case YEAR:
|
||||
throw new IllegalArgumentException("Start year must be less than stop year");
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected type encountered");
|
||||
}
|
||||
stopAt += max;
|
||||
}
|
||||
@@ -1114,7 +1122,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
case YEAR:
|
||||
return years;
|
||||
default:
|
||||
return null;
|
||||
return new TreeSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1197,7 +1205,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
// get second.................................................
|
||||
st = seconds.tailSet(sec);
|
||||
if (st != null && st.size() != 0) {
|
||||
if (st != null && !st.isEmpty()) {
|
||||
sec = st.first();
|
||||
} else {
|
||||
sec = seconds.first();
|
||||
@@ -1212,7 +1220,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
// get minute.................................................
|
||||
st = minutes.tailSet(min);
|
||||
if (st != null && st.size() != 0) {
|
||||
if (st != null && !st.isEmpty()) {
|
||||
t = min;
|
||||
min = st.first();
|
||||
} else {
|
||||
@@ -1233,7 +1241,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
// get hour...................................................
|
||||
st = hours.tailSet(hr);
|
||||
if (st != null && st.size() != 0) {
|
||||
if (st != null && !st.isEmpty()) {
|
||||
t = hr;
|
||||
hr = st.first();
|
||||
} else {
|
||||
@@ -1348,7 +1356,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
day = daysOfMonth.first();
|
||||
mon++;
|
||||
}
|
||||
} else if (st != null && st.size() != 0) {
|
||||
} else if (st != null && !st.isEmpty()) {
|
||||
t = day;
|
||||
day = st.first();
|
||||
// make sure we don't over-run a short month, such as february
|
||||
@@ -1465,7 +1473,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
int dow = daysOfWeek.first(); // desired
|
||||
// d-o-w
|
||||
st = daysOfWeek.tailSet(cDow);
|
||||
if (st != null && st.size() > 0) {
|
||||
if (st != null && !st.isEmpty()) {
|
||||
dow = st.first();
|
||||
}
|
||||
|
||||
@@ -1519,7 +1527,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
// get month...................................................
|
||||
st = months.tailSet(mon);
|
||||
if (st != null && st.size() != 0) {
|
||||
if (st != null && !st.isEmpty()) {
|
||||
t = mon;
|
||||
mon = st.first();
|
||||
} else {
|
||||
@@ -1546,7 +1554,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
|
||||
// get year...................................................
|
||||
st = years.tailSet(year);
|
||||
if (st != null && st.size() != 0) {
|
||||
if (st != null && !st.isEmpty()) {
|
||||
t = year;
|
||||
year = st.first();
|
||||
} else {
|
||||
@@ -1652,6 +1660,10 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
} // never happens
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object clone() {
|
||||
@@ -1660,7 +1672,7 @@ public final class CronExpression implements Serializable, Cloneable {
|
||||
}
|
||||
|
||||
class ValueSet {
|
||||
public int value;
|
||||
int value;
|
||||
|
||||
public int pos;
|
||||
int pos;
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ public class XxlJobGroup {
|
||||
private List<String> registryList; // 执行器地址列表(系统注册)
|
||||
public List<String> getRegistryList() {
|
||||
if (addressList!=null && addressList.trim().length()>0) {
|
||||
registryList = new ArrayList<String>(Arrays.asList(addressList.split(",")));
|
||||
registryList = new ArrayList<>(Arrays.asList(addressList.split(",")));
|
||||
}
|
||||
return registryList;
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
|
||||
|
||||
@Override
|
||||
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
|
||||
StringBuffer idleBeatResultSB = new StringBuffer();
|
||||
StringBuilder idleBeatResultSB = new StringBuilder();
|
||||
for (String address : addressList) {
|
||||
// beat
|
||||
ReturnT<String> idleBeatResult = null;
|
||||
@@ -26,7 +26,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
|
||||
idleBeatResult = executorBiz.idleBeat(new IdleBeatParam(triggerParam.getJobId()));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
idleBeatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
|
||||
idleBeatResult = new ReturnT<>(ReturnT.FAIL_CODE, ""+e );
|
||||
}
|
||||
idleBeatResultSB.append( (idleBeatResultSB.length()>0)?"<br><br>":"")
|
||||
.append(I18nUtil.getString("jobconf_idleBeat") + ":")
|
||||
@@ -42,7 +42,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
|
||||
}
|
||||
}
|
||||
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-12
@@ -4,7 +4,7 @@ import com.xxl.job.admin.core.route.ExecutorRouter;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.biz.model.TriggerParam;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
@@ -19,7 +19,7 @@ import java.util.TreeMap;
|
||||
*/
|
||||
public class ExecutorRouteConsistentHash extends ExecutorRouter {
|
||||
|
||||
private static int VIRTUAL_NODE_NUM = 100;
|
||||
private static final int VIRTUAL_NODE_NUM = 100;
|
||||
|
||||
/**
|
||||
* get hash code on 2^32 ring (md5散列的方式计算hash值)
|
||||
@@ -37,12 +37,7 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
|
||||
}
|
||||
md5.reset();
|
||||
byte[] keyBytes = null;
|
||||
try {
|
||||
keyBytes = key.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("Unknown string :" + key, e);
|
||||
}
|
||||
|
||||
keyBytes = key.getBytes(StandardCharsets.UTF_8);
|
||||
md5.update(keyBytes);
|
||||
byte[] digest = md5.digest();
|
||||
|
||||
@@ -52,15 +47,14 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
|
||||
| ((long) (digest[1] & 0xFF) << 8)
|
||||
| (digest[0] & 0xFF);
|
||||
|
||||
long truncateHashCode = hashCode & 0xffffffffL;
|
||||
return truncateHashCode;
|
||||
return hashCode & 0xffffffffL;
|
||||
}
|
||||
|
||||
public String hashJob(int jobId, List<String> addressList) {
|
||||
|
||||
// ------A1------A2-------A3------
|
||||
// -----------J1------------------
|
||||
TreeMap<Long, String> addressRing = new TreeMap<Long, String>();
|
||||
TreeMap<Long, String> addressRing = new TreeMap<>();
|
||||
for (String address: addressList) {
|
||||
for (int i = 0; i < VIRTUAL_NODE_NUM; i++) {
|
||||
long addressHash = hash("SHARD-" + address + "-NODE-" + i);
|
||||
@@ -79,7 +73,7 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
|
||||
@Override
|
||||
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
|
||||
String address = hashJob(triggerParam.getJobId(), addressList);
|
||||
return new ReturnT<String>(address);
|
||||
return new ReturnT<>(address);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
|
||||
@Override
|
||||
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
|
||||
|
||||
StringBuffer beatResultSB = new StringBuffer();
|
||||
StringBuilder beatResultSB = new StringBuilder();
|
||||
for (String address : addressList) {
|
||||
// beat
|
||||
ReturnT<String> beatResult = null;
|
||||
@@ -26,7 +26,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
|
||||
beatResult = executorBiz.beat();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
beatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
|
||||
beatResult = new ReturnT<>(ReturnT.FAIL_CODE, ""+e );
|
||||
}
|
||||
beatResultSB.append( (beatResultSB.length()>0)?"<br><br>":"")
|
||||
.append(I18nUtil.getString("jobconf_beat") + ":")
|
||||
@@ -42,7 +42,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
|
||||
return beatResult;
|
||||
}
|
||||
}
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, beatResultSB.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public class ExecutorRouteFirst extends ExecutorRouter {
|
||||
|
||||
@Override
|
||||
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList){
|
||||
return new ReturnT<String>(addressList.get(0));
|
||||
return new ReturnT<>(addressList.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public class ExecutorRouteLast extends ExecutorRouter {
|
||||
|
||||
@Override
|
||||
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
|
||||
return new ReturnT<String>(addressList.get(addressList.size()-1));
|
||||
return new ReturnT<>(addressList.get(addressList.size()-1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user