-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Job.java
151 lines (121 loc) · 3.76 KB
/
Job.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.lts.core.domain;
import com.lts.core.commons.utils.JSONUtils;
import com.lts.core.commons.utils.StringUtils;
import com.lts.core.exception.JobSubmitException;
import com.lts.core.support.CronExpression;
import com.lts.remoting.annotation.NotNull;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @author Robert HG (254963746@qq.com) on 8/13/14.
*/
public class Job {
@NotNull
protected String taskId;
/**
* 优先级 (数值越大 优先级越低)
*/
protected Integer priority = 100;
// 提交的节点 (可以手动指定)
protected String submitNodeGroup;
// 执行的节点
@NotNull
protected String taskTrackerNodeGroup;
protected Map<String, String> extParams;
// 是否要反馈给客户端
protected boolean needFeedback = true;
/**
* 执行表达式 和 quartz 的一样
* 如果这个为空,表示立即执行的
*/
private String cronExpression;
/**
* 任务的最早出发时间
* 如果设置了 cronExpression, 那么这个字段没用
*/
private Long triggerTime;
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getSubmitNodeGroup() {
return submitNodeGroup;
}
public void setSubmitNodeGroup(String submitNodeGroup) {
this.submitNodeGroup = submitNodeGroup;
}
public String getTaskTrackerNodeGroup() {
return taskTrackerNodeGroup;
}
public void setTaskTrackerNodeGroup(String taskTrackerNodeGroup) {
this.taskTrackerNodeGroup = taskTrackerNodeGroup;
}
public boolean isNeedFeedback() {
return needFeedback;
}
public void setNeedFeedback(boolean needFeedback) {
this.needFeedback = needFeedback;
}
public Map<String, String> getExtParams() {
return extParams;
}
public void setExtParams(Map<String, String> extParams) {
this.extParams = extParams;
}
public String getParam(String key) {
if (extParams == null) {
return null;
}
return extParams.get(key);
}
public void setParam(String key, String value) {
if (extParams == null) {
extParams = new HashMap<String, String>();
}
extParams.put(key, value);
}
public String getCronExpression() {
return cronExpression;
}
public void setCronExpression(String cronExpression) {
this.cronExpression = cronExpression;
}
public boolean isSchedule() {
return this.cronExpression != null && !"".equals(this.cronExpression.trim());
}
public void setTriggerTime(Date date){
if(date != null){
this.triggerTime = date.getTime();
}
}
public Long getTriggerTime() {
return triggerTime;
}
public void setTriggerTime(Long triggerTime) {
this.triggerTime = triggerTime;
}
@Override
public String toString() {
return JSONUtils.toJSONString(this);
}
public void checkField() throws JobSubmitException {
if (taskId == null) {
throw new JobSubmitException("taskId can not be null! job is " + toString());
}
if (taskTrackerNodeGroup == null) {
throw new JobSubmitException("taskTrackerNodeGroup can not be null! job is " + toString());
}
if (StringUtils.isNotEmpty(cronExpression) && !CronExpression.isValidExpression(cronExpression)) {
throw new JobSubmitException("cronExpression invalid! job is " + toString());
}
}
}