Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
eeb2bfdf
提交
eeb2bfdf
authored
10月 16, 2020
作者:
xueli.xue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade
上级
6b6969b4
显示空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
0 行增加
和
924 行删除
+0
-924
pom.xml
xxl-job-executor-samples/pom.xml
+0
-3
pom.xml
...ob-executor-samples/xxl-job-executor-sample-jboot/pom.xml
+0
-55
JbootApp.java
...main/java/com/xuxueli/executor/sample/jboot/JbootApp.java
+0
-12
JbootConfig.java
...com/xuxueli/executor/sample/jboot/config/JbootConfig.java
+0
-65
IndexController.java
...eli/executor/sample/jboot/controller/IndexController.java
+0
-15
CommandJobHandler.java
...i/executor/sample/jboot/jobhandler/CommandJobHandler.java
+0
-54
DemoJobHandler.java
...ueli/executor/sample/jboot/jobhandler/DemoJobHandler.java
+0
-32
HttpJobHandler.java
...ueli/executor/sample/jboot/jobhandler/HttpJobHandler.java
+0
-121
ShardingJobHandler.java
.../executor/sample/jboot/jobhandler/ShardingJobHandler.java
+0
-36
jboot.properties
...executor-sample-jboot/src/main/resources/jboot.properties
+0
-18
logback.xml
...-job-executor-sample-jboot/src/main/resources/logback.xml
+0
-30
AppTest.java
...cutor-sample-jboot/src/test/java/com/xuxueli/AppTest.java
+0
-18
pom.xml
...job-executor-samples/xxl-job-executor-sample-nutz/pom.xml
+0
-39
MainModule.java
...ain/java/com/xuxueli/executor/sample/nutz/MainModule.java
+0
-23
NutzSetup.java
...va/com/xuxueli/executor/sample/nutz/config/NutzSetup.java
+0
-62
CommandJobHandler.java
...li/executor/sample/nutz/jobhandler/CommandJobHandler.java
+0
-54
DemoJobHandler.java
...xueli/executor/sample/nutz/jobhandler/DemoJobHandler.java
+0
-34
HttpJobHandler.java
...xueli/executor/sample/nutz/jobhandler/HttpJobHandler.java
+0
-121
ShardingJobHandler.java
...i/executor/sample/nutz/jobhandler/ShardingJobHandler.java
+0
-36
IndexModule.java
.../com/xuxueli/executor/sample/nutz/module/IndexModule.java
+0
-16
log4j.xml
...xxl-job-executor-sample-nutz/src/main/resources/log4j.xml
+0
-28
xxl-job-executor.properties
...ample-nutz/src/main/resources/xxl-job-executor.properties
+0
-18
web.xml
...-job-executor-sample-nutz/src/main/webapp/WEB-INF/web.xml
+0
-32
index.html
...s/xxl-job-executor-sample-nutz/src/main/webapp/index.html
+0
-2
没有找到文件。
xxl-job-executor-samples/pom.xml
浏览文件 @
eeb2bfdf
...
...
@@ -15,8 +15,6 @@
<module>
xxl-job-executor-sample-springboot
</module>
<module>
xxl-job-executor-sample-spring
</module>
<module>
xxl-job-executor-sample-jfinal
</module>
<module>
xxl-job-executor-sample-nutz
</module>
<module>
xxl-job-executor-sample-jboot
</module>
</modules>
</project>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-jboot/pom.xml
deleted
100644 → 0
浏览文件 @
6b6969b4
<?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>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-executor-samples
</artifactId>
<version>
2.2.1-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
xxl-job-executor-sample-jboot
</artifactId>
<packaging>
jar
</packaging>
<properties>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
</properties>
<dependencies>
<!-- jboot -->
<dependency>
<groupId>
io.jboot
</groupId>
<artifactId>
jboot
</artifactId>
<version>
2.0.9
</version>
</dependency>
<!-- xxl-job-core -->
<dependency>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-core
</artifactId>
<version>
${project.parent.version}
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.11
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-core
</artifactId>
<version>
1.1.11
</version>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
<version>
1.1.11
</version>
</dependency>
</dependencies>
</project>
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/JbootApp.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
);
}
}
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/config/JbootConfig.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
();
}
}
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/controller/IndexController.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/CommandJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
<
String
>(
IJobHandler
.
FAIL
.
getCode
(),
"command exit value("
+
exitValue
+
") is failed"
);
}
}
}
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/DemoJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
;
}
}
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
);
}
}
}
}
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/ShardingJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
;
}
}
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/jboot.properties
deleted
100644 → 0
浏览文件 @
6b6969b4
### 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
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/resources/logback.xml
deleted
100644 → 0
浏览文件 @
6b6969b4
<?xml version="1.0" encoding="UTF-8"?>
<configuration
debug=
"false"
scan=
"true"
scanPeriod=
"1 seconds"
>
<contextName>
logback
</contextName>
<property
name=
"log.path"
value=
"/data/applogs/xxl-job/xxl-job-executor-sample-jboot.log"
/>
<appender
name=
"console"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender
name=
"file"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${log.path}
</file>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<fileNamePattern>
${log.path}.%d{yyyy-MM-dd}.zip
</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>
%date %level [%thread] %logger{36} [%file : %line] %msg%n
</pattern>
</encoder>
</appender>
<root
level=
"info"
>
<appender-ref
ref=
"console"
/>
<appender-ref
ref=
"file"
/>
</root>
</configuration>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/test/java/com/xuxueli/AppTest.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
);
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/pom.xml
deleted
100644 → 0
浏览文件 @
6b6969b4
<?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>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-executor-samples
</artifactId>
<version>
2.2.1-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
xxl-job-executor-sample-nutz
</artifactId>
<packaging>
war
</packaging>
<dependencies>
<!-- nutz -->
<dependency>
<groupId>
org.nutz
</groupId>
<artifactId>
nutz
</artifactId>
<version>
1.r.62
</version>
</dependency>
<!-- slf4j -->
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
<version>
${slf4j-api.version}
</version>
</dependency>
<!-- xxl-job -->
<dependency>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-core
</artifactId>
<version>
${project.parent.version}
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/MainModule.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
{
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/config/NutzSetup.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
();
}
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/CommandJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
<
String
>(
IJobHandler
.
FAIL
.
getCode
(),
"command exit value("
+
exitValue
+
") is failed"
);
}
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/DemoJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
;
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
);
}
}
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/ShardingJobHandler.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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
<
String
>
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
;
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/module/IndexModule.java
deleted
100644 → 0
浏览文件 @
6b6969b4
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."
;
}
}
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/log4j.xml
deleted
100644 → 0
浏览文件 @
6b6969b4
<?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-nutz [%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-nutz.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-nutz [%c]-[%t]-[%M]-[%L]-[%p] %m%n"
/>
</layout>
</appender>
<root>
<level
value=
"INFO"
/>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE"
/>
</root>
</log4j:configuration>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/resources/xxl-job-executor.properties
deleted
100644 → 0
浏览文件 @
6b6969b4
### 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
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/WEB-INF/web.xml
deleted
100644 → 0
浏览文件 @
6b6969b4
<?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>
xxl-job-executor-sample-nutz
</display-name>
<context-param>
<param-name>
webAppRootKey
</param-name>
<param-value>
xxl-job-executor-sample-nutz
</param-value>
</context-param>
<!-- nutz -->
<filter>
<filter-name>
nutz
</filter-name>
<filter-class>
org.nutz.mvc.NutFilter
</filter-class>
<init-param>
<param-name>
modules
</param-name>
<param-value>
com.xuxueli.executor.sample.nutz.MainModule
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>
nutz
</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>
index.html
</welcome-file>
</welcome-file-list>
</web-app>
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/webapp/index.html
deleted
100644 → 0
浏览文件 @
6b6969b4
i am alive.
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论