parent
85179937cc
commit
0045d1e34a
@ -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>
|
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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.");
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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>
|
@ -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=
|
@ -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>
|
Loading…
Reference in new issue