Skip to content

Commit

Permalink
例子
Browse files Browse the repository at this point in the history
  • Loading branch information
qq254963746 committed Apr 24, 2016
1 parent 114272a commit be3ea6a
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lts-example-jobclient/lts-example-jobclient-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.github.ltsopensource.example.java;

import com.github.ltsopensource.core.commons.utils.StringUtils;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.core.exception.JobSubmitException;
import com.github.ltsopensource.jobclient.JobClient;
import com.github.ltsopensource.jobclient.JobClientBuilder;
import com.github.ltsopensource.jobclient.domain.Response;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* Created by hugui.hg on 4/23/16.
*/
public class TestSubmit {

static JobClient jobClient;

public static void main(String[] args) throws IOException {
// 方式2
jobClient = new JobClientBuilder()
.setPropertiesConfigure("lts.properties")
.setJobCompletedHandler(new JobCompletedHandlerImpl())
.build();

jobClient.start();

startConsole();
}

private static int mode = 2;

public static void startConsole() throws IOException {

BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));

String help = "命令参数: \n" +
"\t1:cronExpression模式,如 0 0/1 * * * ?(一分钟执行一次), \n\t2:指定时间模式 yyyy-MM-dd HH:mm:ss,在执行时间模式下,如果字符串now,表示立即执行 \n" +
"\tquit:退出\n" +
"\thelp:帮助";
System.out.println(help);
System.out.println("指定时间模式:");

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
jobClient.stop();
}
}));

String input;
while (!"quit".equals(input = buffer.readLine())) {
try {
if ("now".equals(input)) {
input = "";
}
if ("help".equals(input)) {
System.out.println(help);
} else if ("1".equals(input)) {
mode = 1;
} else if ("2".equals(input)) {
mode = 2;
} else {
if (mode == 1) {
submitWithCronExpression(jobClient, input);
} else if (mode == 2) {
submitWithTrigger(jobClient, input);
}
}

if (mode == 1) {
System.out.print("cronExpression模式:");
} else if (mode == 2) {
System.out.print("指定时间模式:");
}

} catch (Exception e) {
System.out.println("输入错误");
}
}
System.exit(0);
}

public static void submitWithCronExpression(final JobClient jobClient, String cronExpression) throws ParseException, JobSubmitException {
Job job = new Job();
// 必填,尽量taskId 有一定规律性,能让自己识别
job.setTaskId(StringUtils.generateUUID());
// 任务的参数,value必须为字符串
job.setParam("shopId", "111");
// 执行节点的group名称
job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
// 是否接收执行反馈消息 jobClient.setJobFinishedHandler(new JobFinishedHandlerImpl()); 中接受
job.setNeedFeedback(true);
// 这个是 cron expression 和 quartz 一样,可选
job.setCronExpression(cronExpression);
// 这个是指定执行时间,可选
// job.setTriggerTime(new Date());
// 当 cronExpression 和 triggerTime 都不设置的时候,默认是立即执行任务
// response 返回提交成功还是失败
Response response = jobClient.submitJob(job);


System.out.println(response);
}

public static void submitWithTrigger(final JobClient jobClient, String triggerTime) throws ParseException, JobSubmitException {
Job job = new Job();
job.setTaskId(StringUtils.generateUUID());
job.setParam("shopId", "111");
job.setMaxRetryTimes(5);
job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
job.setNeedFeedback(true);
if (triggerTime != null && !"".equals(triggerTime.trim())) {
job.setTriggerTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(triggerTime).getTime());
}
Response response = jobClient.submitJob(job);
System.out.println(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>lts-example-jobclient-springboot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lts-example-jobclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-examples</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion lts-example-jobtracker/lts-example-jobtracker-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobtracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-jobtracker:1.6.8-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-core:1.6.8-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-jobtracker:1.6.8-beta1" level="project" />
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-core:1.6.8-beta1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-spring:1.6.8-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.ltsopensource:lts-spring:1.6.8-beta1" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.16" level="project" />
<orderEntry type="library" name="Maven: com.github.sgroschupf:zkclient:0.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.zookeeper:zookeeper:3.3.3" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobtracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobtracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobtracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion lts-example-jobtracker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-examples</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>lts-example-jobtracker</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lts-example-monitor/lts-example-monitor-springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-monitor</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion lts-example-monitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-examples</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion lts-example-quartz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-examples</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-tasktracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion lts-example-tasktracker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-examples</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
15 changes: 2 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts-examples</artifactId>
<version>1.6.8-SNAPSHOT</version>
<version>1.6.8-beta1</version>
<modules>
<module>lts-example-jobtracker</module>
<module>lts-example-tasktracker</module>
Expand Down Expand Up @@ -42,7 +42,7 @@
<aspectj.version>1.7.2</aspectj.version>
<javax.mail.version>1.5.4</javax.mail.version>
<spring.boot.version>1.3.3.RELEASE</spring.boot.version>
<lts.version>1.6.8-SNAPSHOT</lts.version>
<lts.version>1.6.8-beta1</lts.version>
<quartz.version>2.2.2</quartz.version>
</properties>

Expand Down Expand Up @@ -213,17 +213,6 @@
</dependencies>
</dependencyManagement>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
Expand Down

0 comments on commit be3ea6a

Please sign in to comment.