From eeb2bfdfb3b2f202b12c1c905c9832639f375606 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Fri, 16 Oct 2020 17:38:08 +0800 Subject: [PATCH] upgrade --- xxl-job-executor-samples/pom.xml | 2 - .../xxl-job-executor-sample-jboot/pom.xml | 55 -------- .../executor/sample/jboot/JbootApp.java | 12 -- .../sample/jboot/config/JbootConfig.java | 65 ---------- .../jboot/controller/IndexController.java | 14 -- .../jboot/jobhandler/CommandJobHandler.java | 54 -------- .../jboot/jobhandler/DemoJobHandler.java | 32 ----- .../jboot/jobhandler/HttpJobHandler.java | 121 ------------------ .../jboot/jobhandler/ShardingJobHandler.java | 36 ------ .../src/main/resources/jboot.properties | 17 --- .../src/main/resources/logback.xml | 29 ----- .../src/test/java/com/xuxueli/AppTest.java | 18 --- .../xxl-job-executor-sample-nutz/pom.xml | 38 ------ .../executor/sample/nutz/MainModule.java | 23 ---- .../sample/nutz/config/NutzSetup.java | 62 --------- .../nutz/jobhandler/CommandJobHandler.java | 54 -------- .../nutz/jobhandler/DemoJobHandler.java | 34 ----- .../nutz/jobhandler/HttpJobHandler.java | 121 ------------------ .../nutz/jobhandler/ShardingJobHandler.java | 36 ------ .../sample/nutz/module/IndexModule.java | 16 --- .../src/main/resources/log4j.xml | 27 ---- .../resources/xxl-job-executor.properties | 17 --- .../src/main/webapp/WEB-INF/web.xml | 32 ----- .../src/main/webapp/index.html | 1 - 24 files changed, 916 deletions(-) delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/pom.xml delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/JbootApp.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/config/JbootConfig.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/controller/IndexController.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/CommandJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/DemoJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/ShardingJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/jboot.properties delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/logback.xml delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/test/java/com/xuxueli/AppTest.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/pom.xml delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/MainModule.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/config/NutzSetup.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/CommandJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/DemoJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/ShardingJobHandler.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/module/IndexModule.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/log4j.xml delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/xxl-job-executor.properties delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/WEB-INF/web.xml delete mode 100644 xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/index.html diff --git a/xxl-job-executor-samples/pom.xml b/xxl-job-executor-samples/pom.xml index e7d86458..989aa5cb 100644 --- a/xxl-job-executor-samples/pom.xml +++ b/xxl-job-executor-samples/pom.xml @@ -15,8 +15,6 @@ xxl-job-executor-sample-springboot xxl-job-executor-sample-spring xxl-job-executor-sample-jfinal - xxl-job-executor-sample-nutz - xxl-job-executor-sample-jboot \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/pom.xml b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/pom.xml deleted file mode 100644 index b1e7967b..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - com.xuxueli - xxl-job-executor-samples - 2.2.1-SNAPSHOT - - 4.0.0 - xxl-job-executor-sample-jboot - jar - - - 1.8 - 1.8 - - - - - - io.jboot - jboot - 2.0.9 - - - - - com.xuxueli - xxl-job-core - ${project.parent.version} - - - - junit - junit - 4.11 - test - - - - ch.qos.logback - logback-core - 1.1.11 - - - - ch.qos.logback - logback-classic - 1.1.11 - - - - - diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/JbootApp.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/JbootApp.java deleted file mode 100644 index 79e2b7ac..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/JbootApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xuxueli.executor.sample.jboot; - -import io.jboot.app.JbootApplication; - -/** - * Jboot app - */ -public class JbootApp { - public static void main(String[] args) { - JbootApplication.run(args); - } -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/config/JbootConfig.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/config/JbootConfig.java deleted file mode 100644 index 136f8306..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/config/JbootConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.xuxueli.executor.sample.jboot.config; - -import com.xuxueli.executor.sample.jboot.jobhandler.CommandJobHandler; -import com.xuxueli.executor.sample.jboot.jobhandler.DemoJobHandler; -import com.xuxueli.executor.sample.jboot.jobhandler.HttpJobHandler; -import com.xuxueli.executor.sample.jboot.jobhandler.ShardingJobHandler; -import com.xxl.job.core.executor.XxlJobExecutor; -import io.jboot.Jboot; -import io.jboot.core.listener.JbootAppListenerBase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class JbootConfig extends JbootAppListenerBase { - private Logger logger = LoggerFactory.getLogger(JbootConfig.class); - - // ---------------------- xxl-job executor ---------------------- - private XxlJobExecutor xxlJobExecutor = null; - - private void initXxlJobExecutor() { - - // registry jobhandler - XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler()); - XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler()); - XxlJobExecutor.registJobHandler("httpJobHandler", new HttpJobHandler()); - XxlJobExecutor.registJobHandler("commandJobHandler", new CommandJobHandler()); - - // init executor - xxlJobExecutor = new XxlJobExecutor(); - xxlJobExecutor.setAdminAddresses(Jboot.configValue("xxl.job.admin.addresses")); - xxlJobExecutor.setAccessToken(Jboot.configValue("xxl.job.accessToken")); - xxlJobExecutor.setAddress(Jboot.configValue("xxl.job.executor.address")); - xxlJobExecutor.setAppname(Jboot.configValue("xxl.job.executor.appname")); - xxlJobExecutor.setIp(Jboot.configValue("xxl.job.executor.ip")); - xxlJobExecutor.setPort(Integer.valueOf(Jboot.configValue("xxl.job.executor.port"))); - xxlJobExecutor.setLogPath(Jboot.configValue("xxl.job.executor.logpath")); - xxlJobExecutor.setLogRetentionDays(Integer.valueOf(Jboot.configValue("xxl.job.executor.logretentiondays"))); - - // start executor - try { - xxlJobExecutor.start(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - // ---------------------- jboot ---------------------- - - private void destoryXxlJobExecutor() { - if (xxlJobExecutor != null) { - xxlJobExecutor.destroy(); - } - } - - @Override - public void onStart() { - initXxlJobExecutor(); - super.onStart(); - } - - @Override - public void onStop() { - destoryXxlJobExecutor(); - super.onStop(); - } -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/controller/IndexController.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/controller/IndexController.java deleted file mode 100644 index f7a85976..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/controller/IndexController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.xuxueli.executor.sample.jboot.controller; - -import io.jboot.web.controller.JbootController; -import io.jboot.web.controller.annotation.RequestMapping; - - -@RequestMapping("/") -public class IndexController extends JbootController { - - public void index() { - renderText("xxl job executor running."); - } - -} \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/CommandJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/CommandJobHandler.java deleted file mode 100644 index a73e19ab..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/CommandJobHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.xuxueli.executor.sample.jboot.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.InputStreamReader; - -/** - * 命令行任务 - * - * @author xuxueli 2018-09-16 03:48:34 - */ -public class CommandJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - String command = param; - int exitValue = -1; - - BufferedReader bufferedReader = null; - try { - // command process - Process process = Runtime.getRuntime().exec(command); - BufferedInputStream bufferedInputStream = new BufferedInputStream(process.getInputStream()); - bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream)); - - // command log - String line; - while ((line = bufferedReader.readLine()) != null) { - XxlJobLogger.log(line); - } - - // command exit - process.waitFor(); - exitValue = process.exitValue(); - } catch (Exception e) { - XxlJobLogger.log(e); - } finally { - if (bufferedReader != null) { - bufferedReader.close(); - } - } - - if (exitValue == 0) { - return IJobHandler.SUCCESS; - } else { - return new ReturnT(IJobHandler.FAIL.getCode(), "command exit value("+exitValue+") is failed"); - } - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/DemoJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/DemoJobHandler.java deleted file mode 100644 index baf7e885..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/DemoJobHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.xuxueli.executor.sample.jboot.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -import java.util.concurrent.TimeUnit; - -/** - * 任务Handler示例(Bean模式) - * - * 开发步骤: - * 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”; - * 2、注册到执行器工厂:在 "JFinalCoreConfig.initXxlJobExecutor" 中手动注册,注解key值对应的是调度中心新建任务的JobHandler属性的值。 - * 3、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志; - * - * @author xuxueli 2015-12-19 19:43:36 - */ -public class DemoJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - XxlJobLogger.log("XXL-JOB, Hello World."); - - for (int i = 0; i < 5; i++) { - XxlJobLogger.log("beat at:" + i); - TimeUnit.SECONDS.sleep(2); - } - return SUCCESS; - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java deleted file mode 100644 index 68a27b39..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.xuxueli.executor.sample.jboot.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Arrays; - -/** - * 跨平台Http任务 - * - * @author xuxueli 2018-09-16 03:48:34 - */ -public class HttpJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - - // param parse - if (param==null || param.trim().length()==0) { - XxlJobLogger.log("param["+ param +"] invalid."); - return ReturnT.FAIL; - } - String[] httpParams = param.split("\n"); - String url = null; - String method = null; - String data = null; - for (String httpParam: httpParams) { - if (httpParam.startsWith("url:")) { - url = httpParam.substring(httpParam.indexOf("url:") + 4).trim(); - } - if (httpParam.startsWith("method:")) { - method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase(); - } - if (httpParam.startsWith("data:")) { - data = httpParam.substring(httpParam.indexOf("data:") + 5).trim(); - } - } - - // param valid - if (url==null || url.trim().length()==0) { - XxlJobLogger.log("url["+ url +"] invalid."); - return ReturnT.FAIL; - } - if (method==null || !Arrays.asList("GET", "POST").contains(method)) { - XxlJobLogger.log("method["+ method +"] invalid."); - return ReturnT.FAIL; - } - boolean isPostMethod = method.equals("POST"); - - // request - HttpURLConnection connection = null; - BufferedReader bufferedReader = null; - try { - // connection - URL realUrl = new URL(url); - connection = (HttpURLConnection) realUrl.openConnection(); - - // connection setting - connection.setRequestMethod(method); - connection.setDoOutput(isPostMethod); - connection.setDoInput(true); - connection.setUseCaches(false); - connection.setReadTimeout(5 * 1000); - connection.setConnectTimeout(3 * 1000); - connection.setRequestProperty("connection", "Keep-Alive"); - connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); - connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8"); - - // do connection - connection.connect(); - - // data - if (isPostMethod && data!=null && data.trim().length()>0) { - DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); - dataOutputStream.write(data.getBytes("UTF-8")); - dataOutputStream.flush(); - dataOutputStream.close(); - } - - // valid StatusCode - int statusCode = connection.getResponseCode(); - if (statusCode != 200) { - throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid."); - } - - // result - bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - StringBuilder result = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - result.append(line); - } - String responseMsg = result.toString(); - - XxlJobLogger.log(responseMsg); - return ReturnT.SUCCESS; - } catch (Exception e) { - XxlJobLogger.log(e); - return ReturnT.FAIL; - } finally { - try { - if (bufferedReader != null) { - bufferedReader.close(); - } - if (connection != null) { - connection.disconnect(); - } - } catch (Exception e2) { - XxlJobLogger.log(e2); - } - } - - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/ShardingJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/ShardingJobHandler.java deleted file mode 100644 index 4914e68a..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/ShardingJobHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.xuxueli.executor.sample.jboot.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.context.XxlJobContext; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -/** - * 分片广播任务 - * - * @author xuxueli 2017-07-25 20:56:50 - */ -public class ShardingJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - - // 分片参数 - int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex(); - int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal(); - - XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal); - - // 业务逻辑 - for (int i = 0; i < shardTotal; i++) { - if (i == shardIndex) { - XxlJobLogger.log("第 {} 片, 命中分片开始处理", i); - } else { - XxlJobLogger.log("第 {} 片, 忽略", i); - } - } - - return SUCCESS; - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/jboot.properties b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/jboot.properties deleted file mode 100644 index ea7589af..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/jboot.properties +++ /dev/null @@ -1,17 +0,0 @@ -### xxl-job admin address list, such as "http://address" or "http://address01,http://address02" -xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin - -### xxl-job, access token -xxl.job.accessToken= - -### xxl-job executor appname -xxl.job.executor.appname=xxl-job-executor-sample -### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null -xxl.job.executor.address= -### xxl-job executor server-info -xxl.job.executor.ip= -xxl.job.executor.port=9999 -### xxl-job executor log-path -xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler -### xxl-job executor log-retention-days -xxl.job.executor.logretentiondays=30 \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/logback.xml b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/logback.xml deleted file mode 100644 index e5606050..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/logback.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - logback - - - - - %d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n - - - - - ${log.path} - - ${log.path}.%d{yyyy-MM-dd}.zip - - - %date %level [%thread] %logger{36} [%file : %line] %msg%n - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/test/java/com/xuxueli/AppTest.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/test/java/com/xuxueli/AppTest.java deleted file mode 100644 index 470feac7..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/test/java/com/xuxueli/AppTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.xuxueli; - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -/** - * Unit test for simple App. - */ -public class AppTest { - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() { - assertTrue(true); - } -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/pom.xml b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/pom.xml deleted file mode 100644 index 8b8e2b75..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - com.xuxueli - xxl-job-executor-samples - 2.2.1-SNAPSHOT - - 4.0.0 - xxl-job-executor-sample-nutz - war - - - - - org.nutz - nutz - 1.r.62 - - - - - org.slf4j - slf4j-log4j12 - ${slf4j-api.version} - - - - - com.xuxueli - xxl-job-core - ${project.parent.version} - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/MainModule.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/MainModule.java deleted file mode 100644 index a8163ff9..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/MainModule.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.xuxueli.executor.sample.nutz; - -import com.xuxueli.executor.sample.nutz.config.NutzSetup; -import org.nutz.mvc.annotation.*; -import org.nutz.mvc.ioc.provider.ComboIocProvider; - -/** - * nutz module - * - * @author xuxueli 2017-12-25 17:58:43 - */ -@IocBy(type = ComboIocProvider.class, - args = {"*org.nutz.ioc.loader.annotation.AnnotationIocLoader", - "com.xuxueli.executor.sample.nutz"}) -@Encoding(input = "utf-8", output = "utf-8") -@Modules(scanPackage = true) -@Localization("msg") -@Ok("json") -@Fail("json") -@SetupBy(NutzSetup.class) -public class MainModule { - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/config/NutzSetup.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/config/NutzSetup.java deleted file mode 100644 index a1d92493..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/config/NutzSetup.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.xuxueli.executor.sample.nutz.config; - -import com.xuxueli.executor.sample.nutz.jobhandler.CommandJobHandler; -import com.xuxueli.executor.sample.nutz.jobhandler.DemoJobHandler; -import com.xuxueli.executor.sample.nutz.jobhandler.HttpJobHandler; -import com.xuxueli.executor.sample.nutz.jobhandler.ShardingJobHandler; -import com.xxl.job.core.executor.XxlJobExecutor; -import org.nutz.ioc.impl.PropertiesProxy; -import org.nutz.mvc.NutConfig; -import org.nutz.mvc.Setup; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * nutz setup - * - * @author xuxueli 2017-12-25 17:58:43 - */ -public class NutzSetup implements Setup { - private Logger logger = LoggerFactory.getLogger(NutzSetup.class); - - private XxlJobExecutor xxlJobExecutor = null; - - @Override - public void init(NutConfig cfg) { - - // registry jobhandler - XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler()); - XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler()); - XxlJobExecutor.registJobHandler("httpJobHandler", new HttpJobHandler()); - XxlJobExecutor.registJobHandler("commandJobHandler", new CommandJobHandler()); - - // load executor prop - PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties"); - - // init executor - xxlJobExecutor = new XxlJobExecutor(); - xxlJobExecutor.setAdminAddresses(xxlJobProp.get("xxl.job.admin.addresses")); - xxlJobExecutor.setAccessToken(xxlJobProp.get("xxl.job.accessToken")); - xxlJobExecutor.setAppname(xxlJobProp.get("xxl.job.executor.appname")); - xxlJobExecutor.setAddress(xxlJobProp.get("xxl.job.executor.address")); - xxlJobExecutor.setIp(xxlJobProp.get("xxl.job.executor.ip")); - xxlJobExecutor.setPort(xxlJobProp.getInt("xxl.job.executor.port")); - xxlJobExecutor.setLogPath(xxlJobProp.get("xxl.job.executor.logpath")); - xxlJobExecutor.setLogRetentionDays(xxlJobProp.getInt("xxl.job.executor.logretentiondays")); - - // start executor - try { - xxlJobExecutor.start(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - @Override - public void destroy(NutConfig cfg) { - if (xxlJobExecutor != null) { - xxlJobExecutor.destroy(); - } - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/CommandJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/CommandJobHandler.java deleted file mode 100644 index 120180aa..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/CommandJobHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.xuxueli.executor.sample.nutz.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.InputStreamReader; - -/** - * 命令行任务 - * - * @author xuxueli 2018-09-16 03:48:34 - */ -public class CommandJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - String command = param; - int exitValue = -1; - - BufferedReader bufferedReader = null; - try { - // command process - Process process = Runtime.getRuntime().exec(command); - BufferedInputStream bufferedInputStream = new BufferedInputStream(process.getInputStream()); - bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream)); - - // command log - String line; - while ((line = bufferedReader.readLine()) != null) { - XxlJobLogger.log(line); - } - - // command exit - process.waitFor(); - exitValue = process.exitValue(); - } catch (Exception e) { - XxlJobLogger.log(e); - } finally { - if (bufferedReader != null) { - bufferedReader.close(); - } - } - - if (exitValue == 0) { - return IJobHandler.SUCCESS; - } else { - return new ReturnT(IJobHandler.FAIL.getCode(), "command exit value("+exitValue+") is failed"); - } - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/DemoJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/DemoJobHandler.java deleted file mode 100644 index 420c0030..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/DemoJobHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.xuxueli.executor.sample.nutz.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -import java.util.concurrent.TimeUnit; - -/** - * 任务Handler示例(Bean模式) - * - * 开发步骤: - * 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”; - * 2、注册到Nutz容器:添加“@IocBean”注解,被Nutz容器扫描为Bean实例; - * 3、注册到执行器工厂:添加“@JobHandler(value="自定义jobhandler名称")”注解,注解value值对应的是调度中心新建任务的JobHandler属性的值。 - * 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志; - * - * @author xuxueli 2015-12-19 19:43:36 - */ -public class DemoJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - XxlJobLogger.log("XXL-JOB, Hello World."); - - for (int i = 0; i < 5; i++) { - XxlJobLogger.log("beat at:" + i); - TimeUnit.SECONDS.sleep(2); - } - return SUCCESS; - } - -} - diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java deleted file mode 100644 index 837000be..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.xuxueli.executor.sample.nutz.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Arrays; - -/** - * 跨平台Http任务 - * - * @author xuxueli 2018-09-16 03:48:34 - */ -public class HttpJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - - // param parse - if (param==null || param.trim().length()==0) { - XxlJobLogger.log("param["+ param +"] invalid."); - return ReturnT.FAIL; - } - String[] httpParams = param.split("\n"); - String url = null; - String method = null; - String data = null; - for (String httpParam: httpParams) { - if (httpParam.startsWith("url:")) { - url = httpParam.substring(httpParam.indexOf("url:") + 4).trim(); - } - if (httpParam.startsWith("method:")) { - method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase(); - } - if (httpParam.startsWith("data:")) { - data = httpParam.substring(httpParam.indexOf("data:") + 5).trim(); - } - } - - // param valid - if (url==null || url.trim().length()==0) { - XxlJobLogger.log("url["+ url +"] invalid."); - return ReturnT.FAIL; - } - if (method==null || !Arrays.asList("GET", "POST").contains(method)) { - XxlJobLogger.log("method["+ method +"] invalid."); - return ReturnT.FAIL; - } - boolean isPostMethod = method.equals("POST"); - - // request - HttpURLConnection connection = null; - BufferedReader bufferedReader = null; - try { - // connection - URL realUrl = new URL(url); - connection = (HttpURLConnection) realUrl.openConnection(); - - // connection setting - connection.setRequestMethod(method); - connection.setDoOutput(isPostMethod); - connection.setDoInput(true); - connection.setUseCaches(false); - connection.setReadTimeout(5 * 1000); - connection.setConnectTimeout(3 * 1000); - connection.setRequestProperty("connection", "Keep-Alive"); - connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); - connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8"); - - // do connection - connection.connect(); - - // data - if (isPostMethod && data!=null && data.trim().length()>0) { - DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); - dataOutputStream.write(data.getBytes("UTF-8")); - dataOutputStream.flush(); - dataOutputStream.close(); - } - - // valid StatusCode - int statusCode = connection.getResponseCode(); - if (statusCode != 200) { - throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid."); - } - - // result - bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - StringBuilder result = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - result.append(line); - } - String responseMsg = result.toString(); - - XxlJobLogger.log(responseMsg); - return ReturnT.SUCCESS; - } catch (Exception e) { - XxlJobLogger.log(e); - return ReturnT.FAIL; - } finally { - try { - if (bufferedReader != null) { - bufferedReader.close(); - } - if (connection != null) { - connection.disconnect(); - } - } catch (Exception e2) { - XxlJobLogger.log(e2); - } - } - - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/ShardingJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/ShardingJobHandler.java deleted file mode 100644 index 5a03b211..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/ShardingJobHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.xuxueli.executor.sample.nutz.jobhandler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.context.XxlJobContext; -import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.log.XxlJobLogger; - -/** - * 分片广播任务 - * - * @author xuxueli 2017-07-25 20:56:50 - */ -public class ShardingJobHandler extends IJobHandler { - - @Override - public ReturnT execute(String param) throws Exception { - - // 分片参数 - int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex(); - int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal(); - - XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal); - - // 业务逻辑 - for (int i = 0; i < shardTotal; i++) { - if (i == shardIndex) { - XxlJobLogger.log("第 {} 片, 命中分片开始处理", i); - } else { - XxlJobLogger.log("第 {} 片, 忽略", i); - } - } - - return SUCCESS; - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/module/IndexModule.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/module/IndexModule.java deleted file mode 100644 index 0cd0233d..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/module/IndexModule.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xuxueli.executor.sample.nutz.module; - -import org.nutz.ioc.loader.annotation.IocBean; -import org.nutz.mvc.annotation.At; -import org.nutz.mvc.annotation.Ok; - -@IocBean -public class IndexModule { - - @At("/") - @Ok("json") - public String index() { - return "xxl job executor running."; - } - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/log4j.xml b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/log4j.xml deleted file mode 100644 index b9ba6cef..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/log4j.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/xxl-job-executor.properties b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/xxl-job-executor.properties deleted file mode 100644 index ea7589af..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/xxl-job-executor.properties +++ /dev/null @@ -1,17 +0,0 @@ -### xxl-job admin address list, such as "http://address" or "http://address01,http://address02" -xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin - -### xxl-job, access token -xxl.job.accessToken= - -### xxl-job executor appname -xxl.job.executor.appname=xxl-job-executor-sample -### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null -xxl.job.executor.address= -### xxl-job executor server-info -xxl.job.executor.ip= -xxl.job.executor.port=9999 -### xxl-job executor log-path -xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler -### xxl-job executor log-retention-days -xxl.job.executor.logretentiondays=30 \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/WEB-INF/web.xml b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 19f2817f..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - xxl-job-executor-sample-nutz - - webAppRootKey - xxl-job-executor-sample-nutz - - - - - nutz - org.nutz.mvc.NutFilter - - modules - com.xuxueli.executor.sample.nutz.MainModule - - - - nutz - /* - - - - - index.html - - - diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/index.html b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/index.html deleted file mode 100644 index 7085239b..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/index.html +++ /dev/null @@ -1 +0,0 @@ -i am alive. \ No newline at end of file