forked from xuxueli/xxl-job
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
273 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
xxl-job-executor-samples/xxl-job-executor-sample-jfinal/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>xxl-job-executor-samples</artifactId> | ||
<groupId>com.xuxueli</groupId> | ||
<version>1.8.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>xxl-job-executor-sample-jfinal</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<dependencies> | ||
<!-- jfinal --> | ||
<dependency> | ||
<groupId>com.jfinal</groupId> | ||
<artifactId>jfinal</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
|
||
<!-- xxl-job --> | ||
<dependency> | ||
<groupId>com.xuxueli</groupId> | ||
<artifactId>xxl-job-core</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>${slf4j-api.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
84 changes: 84 additions & 0 deletions
84
...mple-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/config/JFinalCoreConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.xuxueli.executor.sample.jfinal.config; | ||
|
||
import com.jfinal.config.*; | ||
import com.jfinal.kit.Prop; | ||
import com.jfinal.kit.PropKit; | ||
import com.xuxueli.executor.sample.jfinal.controller.IndexController; | ||
import com.xuxueli.executor.sample.jfinal.jobhandler.DemoJobHandler; | ||
import com.xuxueli.executor.sample.jfinal.jobhandler.ShardingJobHandler; | ||
import com.xxl.job.core.executor.XxlJobExecutor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author xuxueli 2017-08-11 14:17:41 | ||
*/ | ||
public class JFinalCoreConfig extends JFinalConfig { | ||
private Logger logger = LoggerFactory.getLogger(JFinalCoreConfig.class); | ||
|
||
// ---------------------- xxl-job executor ---------------------- | ||
XxlJobExecutor xxlJobExecutor = null; | ||
private void initXxlJobExecutor() { | ||
// registry jobhandler | ||
XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler()); | ||
XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler()); | ||
|
||
// load executor prop | ||
Prop xxlJobProp = PropKit.use("xxl-job-executor.properties"); | ||
|
||
// init executor | ||
xxlJobExecutor = new XxlJobExecutor(); | ||
xxlJobExecutor.setIp(xxlJobProp.get("xxl.job.executor.ip")); | ||
xxlJobExecutor.setPort(xxlJobProp.getInt("xxl.job.executor.port")); | ||
xxlJobExecutor.setAppName(xxlJobProp.get("xxl.job.executor.appname")); | ||
xxlJobExecutor.setAdminAddresses(xxlJobProp.get("xxl.job.admin.addresses")); | ||
xxlJobExecutor.setLogPath(xxlJobProp.get("xxl.job.executor.logpath")); | ||
xxlJobExecutor.setAccessToken(xxlJobProp.get("xxl.job.accessToken")); | ||
|
||
// start executor | ||
try { | ||
xxlJobExecutor.start(); | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
} | ||
private void destoryXxlJobExecutor() { | ||
if (xxlJobExecutor != null) { | ||
xxlJobExecutor.destroy(); | ||
} | ||
} | ||
|
||
// ---------------------- jfinal ---------------------- | ||
|
||
public void configRoute(Routes route) { | ||
route.add("/", IndexController.class); | ||
} | ||
|
||
@Override | ||
public void afterJFinalStart() { | ||
initXxlJobExecutor(); | ||
} | ||
|
||
@Override | ||
public void beforeJFinalStop() { | ||
destoryXxlJobExecutor(); | ||
} | ||
|
||
public void configConstant(Constants constants) { | ||
|
||
} | ||
|
||
public void configPlugin(Plugins plugins) { | ||
|
||
} | ||
|
||
public void configInterceptor(Interceptors interceptors) { | ||
|
||
} | ||
|
||
public void configHandler(Handlers handlers) { | ||
|
||
} | ||
|
||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...e-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/controller/IndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.xuxueli.executor.sample.jfinal.controller; | ||
|
||
import com.jfinal.core.Controller; | ||
|
||
public class IndexController extends Controller { | ||
|
||
public void index(){ | ||
renderText("xxl job executor running."); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...le-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/DemoJobHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.xuxueli.executor.sample.jfinal.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的一个Demo(Bean模式) | ||
* | ||
* 开发步骤: | ||
* 1、继承 “IJobHandler” ; | ||
* 2、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志; | ||
* 3、在 "JFinalCoreConfig" 中注册,执行Jobhandler名称; | ||
* | ||
* @author xuxueli 2015-12-19 19:43:36 | ||
*/ | ||
public class DemoJobHandler extends IJobHandler { | ||
|
||
@Override | ||
public ReturnT<String> execute(String... params) 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 ReturnT.SUCCESS; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...final/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/ShardingJobHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.xuxueli.executor.sample.jfinal.jobhandler; | ||
|
||
import com.xxl.job.core.biz.model.ReturnT; | ||
import com.xxl.job.core.handler.IJobHandler; | ||
import com.xxl.job.core.log.XxlJobLogger; | ||
import com.xxl.job.core.util.ShardingUtil; | ||
|
||
|
||
/** | ||
* 分片广播任务 | ||
* | ||
* @author xuxueli 2017-07-25 20:56:50 | ||
*/ | ||
public class ShardingJobHandler extends IJobHandler { | ||
|
||
@Override | ||
public ReturnT<String> execute(String... params) throws Exception { | ||
|
||
// 分片参数 | ||
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo(); | ||
XxlJobLogger.log("分片参数:当前分片序号 = {0}, 总分片数 = {1}", shardingVO.getIndex(), shardingVO.getTotal()); | ||
|
||
// 业务逻辑 | ||
for (int i = 0; i < shardingVO.getTotal(); i++) { | ||
if (i == shardingVO.getIndex()) { | ||
XxlJobLogger.log("第 {0} 片, 命中分片开始处理", i); | ||
} else { | ||
XxlJobLogger.log("第 {0} 片, 忽略", i); | ||
} | ||
} | ||
|
||
return ReturnT.SUCCESS; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/resources/log4j.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd"> | ||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" threshold="null" debug="null"> | ||
|
||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-jfinal [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender"> | ||
<param name="file" value="/data/applogs/xxl-job/xxl-job-executor-sample-jfinal.log"/> | ||
<param name="append" value="true"/> | ||
<param name="encoding" value="UTF-8"/> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-jfinal [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<level value="INFO" /> | ||
<appender-ref ref="CONSOLE" /> | ||
<appender-ref ref="FILE" /> | ||
</root> | ||
|
||
</log4j:configuration> |
13 changes: 13 additions & 0 deletions
13
...tor-samples/xxl-job-executor-sample-jfinal/src/main/resources/xxl-job-executor.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### 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 executor address | ||
xxl.job.executor.appname=xxl-job-executor-sample | ||
xxl.job.executor.ip= | ||
xxl.job.executor.port=9997 | ||
|
||
### xxl-job log path | ||
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/ | ||
|
||
### xxl-job, access token | ||
xxl.job.accessToken= |
22 changes: 22 additions & 0 deletions
22
xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
id="WebApp_ID" version="2.5"> | ||
<display-name>jfinal-demo</display-name> | ||
|
||
<!-- jfinal --> | ||
<filter> | ||
<filter-name>jfinal</filter-name> | ||
<filter-class>com.jfinal.core.JFinalFilter</filter-class> | ||
<init-param> | ||
<param-name>configClass</param-name> | ||
<param-value>com.xuxueli.executor.sample.jfinal.config.JFinalCoreConfig</param-value> | ||
</init-param> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>jfinal</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
|
||
</web-app> |