任务触发逻辑代码重构

v1.9.2
xuxueli 6 years ago
parent 1e1d9e85e6
commit a75d82f983

@ -14,12 +14,11 @@ public abstract class ExecutorRouter {
protected static Logger logger = LoggerFactory.getLogger(ExecutorRouter.class);
/**
* route run executor
* route address
*
* @param triggerParam
* @param addressList
* @return ReturnT.content: final address
* @return ReturnT.content=address
*/
public abstract ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList);
public abstract ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList);
}

@ -15,13 +15,8 @@ import java.util.ArrayList;
*/
public class ExecutorRouteBusyover extends ExecutorRouter {
public String route(int jobId, ArrayList<String> addressList) {
return addressList.get(0);
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
StringBuffer idleBeatResultSB = new StringBuffer();
for (String address : addressList) {
// beat
@ -41,17 +36,13 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
// beat success
if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
idleBeatResultSB.append("<br><br>").append(runResult.getMsg());
// result
runResult.setMsg(idleBeatResultSB.toString());
runResult.setContent(address);
return runResult;
idleBeatResult.setMsg(idleBeatResultSB.toString());
idleBeatResult.setContent(address);
return idleBeatResult;
}
}
return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
}
}

@ -57,7 +57,7 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
return truncateHashCode;
}
public String route(int jobId, ArrayList<String> addressList) {
public String hashJob(int jobId, ArrayList<String> addressList) {
// ------A1------A2-------A3------
// -----------J1------------------
@ -78,13 +78,9 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
String address = hashJob(triggerParam.getJobId(), addressList);
return new ReturnT<String>(address);
}
}

@ -15,12 +15,8 @@ import java.util.ArrayList;
*/
public class ExecutorRouteFailover extends ExecutorRouter {
public String route(int jobId, ArrayList<String> addressList) {
return addressList.get(0);
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
StringBuffer beatResultSB = new StringBuffer();
for (String address : addressList) {
@ -42,13 +38,9 @@ public class ExecutorRouteFailover extends ExecutorRouter {
// beat success
if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
beatResultSB.append("<br><br>").append(runResult.getMsg());
// result
runResult.setMsg(beatResultSB.toString());
runResult.setContent(address);
return runResult;
beatResult.setMsg(beatResultSB.toString());
beatResult.setContent(address);
return beatResult;
}
}
return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());

@ -12,19 +12,9 @@ import java.util.ArrayList;
*/
public class ExecutorRouteFirst extends ExecutorRouter {
public String route(int jobId, ArrayList<String> addressList) {
return addressList.get(0);
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList){
return new ReturnT<String>(addressList.get(0));
}
}

@ -57,15 +57,9 @@ public class ExecutorRouteLFU extends ExecutorRouter {
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
return new ReturnT<String>(address);
}
}

@ -54,17 +54,10 @@ public class ExecutorRouteLRU extends ExecutorRouter {
return eldestValue;
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
return new ReturnT<String>(address);
}
}

@ -12,18 +12,9 @@ import java.util.ArrayList;
*/
public class ExecutorRouteLast extends ExecutorRouter {
public String route(int jobId, ArrayList<String> addressList) {
return addressList.get(addressList.size()-1);
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
return new ReturnT<String>(addressList.get(addressList.size()-1));
}
}

@ -15,20 +15,10 @@ public class ExecutorRouteRandom extends ExecutorRouter {
private static Random localRandom = new Random();
public String route(int jobId, ArrayList<String> addressList) {
// Collections.shuffle(addressList);
return addressList.get(localRandom.nextInt(addressList.size()));
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
String address = addressList.get(localRandom.nextInt(addressList.size()));
return new ReturnT<String>(address);
}
}

@ -30,20 +30,10 @@ public class ExecutorRouteRound extends ExecutorRouter {
return count;
}
public String route(int jobId, ArrayList<String> addressList) {
return addressList.get(count(jobId)%addressList.size());
}
@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address
String address = route(triggerParam.getJobId(), addressList);
// run executor
ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult;
public ReturnT<String> route(TriggerParam triggerParam, ArrayList<String> addressList) {
String address = addressList.get(count(triggerParam.getJobId())%addressList.size());
return new ReturnT<String>(address);
}
}

@ -145,6 +145,7 @@ public class XxlJobTrigger {
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append("").append(finalFailRetryCount);
// 3.0、trigger-valid
String address = null;
if (CollectionUtils.isEmpty(addressList)) {
triggerResult.setCode(ReturnT.FAIL_CODE);
triggerMsgSb.append("<br>----------------------<br>").append(I18nUtil.getString("jobconf_trigger_address_empty"));
@ -165,14 +166,19 @@ public class XxlJobTrigger {
triggerParam.setBroadcastTotal(1);
// 3.2、trigger-run (route run / trigger remote executor)
triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList);
triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
//triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList);
ReturnT<String> routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, addressList);
if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) {
address = routeAddressResult.getContent();
triggerResult = runExecutor(triggerParam, address);
}
triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>")
.append(routeAddressResult.getMsg()!=null?routeAddressResult.getMsg()+"<br><br>":"").append(triggerResult.getMsg()!=null?triggerResult.getMsg():"");
}
// 4、save trigger-info
jobLog.setExecutorAddress(triggerResult.getContent());
jobLog.setExecutorAddress(address);
jobLog.setTriggerCode(triggerResult.getCode());
jobLog.setTriggerMsg(triggerMsgSb.toString());
XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);

Loading…
Cancel
Save