Skip to content

Commit be3ea6a

Browse files
committed
例子
1 parent 114272a commit be3ea6a

File tree

25 files changed

+150
-38
lines changed

25 files changed

+150
-38
lines changed

lts-example-jobclient/lts-example-jobclient-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobclient</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.github.ltsopensource.example.java;
2+
3+
import com.github.ltsopensource.core.commons.utils.StringUtils;
4+
import com.github.ltsopensource.core.domain.Job;
5+
import com.github.ltsopensource.core.exception.JobSubmitException;
6+
import com.github.ltsopensource.jobclient.JobClient;
7+
import com.github.ltsopensource.jobclient.JobClientBuilder;
8+
import com.github.ltsopensource.jobclient.domain.Response;
9+
10+
import java.io.BufferedReader;
11+
import java.io.IOException;
12+
import java.io.InputStreamReader;
13+
import java.text.ParseException;
14+
import java.text.SimpleDateFormat;
15+
16+
/**
17+
* Created by hugui.hg on 4/23/16.
18+
*/
19+
public class TestSubmit {
20+
21+
static JobClient jobClient;
22+
23+
public static void main(String[] args) throws IOException {
24+
// 方式2
25+
jobClient = new JobClientBuilder()
26+
.setPropertiesConfigure("lts.properties")
27+
.setJobCompletedHandler(new JobCompletedHandlerImpl())
28+
.build();
29+
30+
jobClient.start();
31+
32+
startConsole();
33+
}
34+
35+
private static int mode = 2;
36+
37+
public static void startConsole() throws IOException {
38+
39+
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
40+
41+
String help = "命令参数: \n" +
42+
"\t1:cronExpression模式,如 0 0/1 * * * ?(一分钟执行一次), \n\t2:指定时间模式 yyyy-MM-dd HH:mm:ss,在执行时间模式下,如果字符串now,表示立即执行 \n" +
43+
"\tquit:退出\n" +
44+
"\thelp:帮助";
45+
System.out.println(help);
46+
System.out.println("指定时间模式:");
47+
48+
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
49+
@Override
50+
public void run() {
51+
jobClient.stop();
52+
}
53+
}));
54+
55+
String input;
56+
while (!"quit".equals(input = buffer.readLine())) {
57+
try {
58+
if ("now".equals(input)) {
59+
input = "";
60+
}
61+
if ("help".equals(input)) {
62+
System.out.println(help);
63+
} else if ("1".equals(input)) {
64+
mode = 1;
65+
} else if ("2".equals(input)) {
66+
mode = 2;
67+
} else {
68+
if (mode == 1) {
69+
submitWithCronExpression(jobClient, input);
70+
} else if (mode == 2) {
71+
submitWithTrigger(jobClient, input);
72+
}
73+
}
74+
75+
if (mode == 1) {
76+
System.out.print("cronExpression模式:");
77+
} else if (mode == 2) {
78+
System.out.print("指定时间模式:");
79+
}
80+
81+
} catch (Exception e) {
82+
System.out.println("输入错误");
83+
}
84+
}
85+
System.exit(0);
86+
}
87+
88+
public static void submitWithCronExpression(final JobClient jobClient, String cronExpression) throws ParseException, JobSubmitException {
89+
Job job = new Job();
90+
// 必填,尽量taskId 有一定规律性,能让自己识别
91+
job.setTaskId(StringUtils.generateUUID());
92+
// 任务的参数,value必须为字符串
93+
job.setParam("shopId", "111");
94+
// 执行节点的group名称
95+
job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
96+
// 是否接收执行反馈消息 jobClient.setJobFinishedHandler(new JobFinishedHandlerImpl()); 中接受
97+
job.setNeedFeedback(true);
98+
// 这个是 cron expression 和 quartz 一样,可选
99+
job.setCronExpression(cronExpression);
100+
// 这个是指定执行时间,可选
101+
// job.setTriggerTime(new Date());
102+
// 当 cronExpression 和 triggerTime 都不设置的时候,默认是立即执行任务
103+
// response 返回提交成功还是失败
104+
Response response = jobClient.submitJob(job);
105+
106+
107+
System.out.println(response);
108+
}
109+
110+
public static void submitWithTrigger(final JobClient jobClient, String triggerTime) throws ParseException, JobSubmitException {
111+
Job job = new Job();
112+
job.setTaskId(StringUtils.generateUUID());
113+
job.setParam("shopId", "111");
114+
job.setMaxRetryTimes(5);
115+
job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
116+
job.setNeedFeedback(true);
117+
if (triggerTime != null && !"".equals(triggerTime.trim())) {
118+
job.setTriggerTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(triggerTime).getTime());
119+
}
120+
Response response = jobClient.submitJob(job);
121+
System.out.println(response);
122+
}
123+
}

lts-example-jobclient/lts-example-jobclient-spring-annotation/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobclient</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

lts-example-jobclient/lts-example-jobclient-spring-xml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobclient</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

lts-example-jobclient/lts-example-jobclient-springboot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobclient</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>lts-example-jobclient-springboot</artifactId>

lts-example-jobclient/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-examples</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<packaging>pom</packaging>

lts-example-jobtracker/lts-example-jobtracker-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobtracker</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

lts-example-jobtracker/lts-example-jobtracker-spring-annotaion/lts-example-jobtracker-spring-annotaion.iml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
2020
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" />
2121
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.2.5.RELEASE" level="project" />
22-
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-jobtracker:1.6.8-SNAPSHOT" level="project" />
23-
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-core:1.6.8-SNAPSHOT" level="project" />
22+
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-jobtracker:1.6.8-beta1" level="project" />
23+
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-core:1.6.8-beta1" level="project" />
2424
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
25-
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-spring:1.6.8-SNAPSHOT" level="project" />
25+
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-spring:1.6.8-beta1" level="project" />
2626
<orderEntry type="library" name="Maven: log4j:log4j:1.2.16" level="project" />
2727
<orderEntry type="library" name="Maven: com.github.sgroschupf:zkclient:0.1" level="project" />
2828
<orderEntry type="library" name="Maven: org.apache.zookeeper:zookeeper:3.3.3" level="project" />

lts-example-jobtracker/lts-example-jobtracker-spring-annotaion/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobtracker</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

lts-example-jobtracker/lts-example-jobtracker-spring-xml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>lts-example-jobtracker</artifactId>
77
<groupId>com.github.ltsopensource</groupId>
8-
<version>1.6.8-SNAPSHOT</version>
8+
<version>1.6.8-beta1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

0 commit comments

Comments
 (0)