DemoTaskBean.java
1.8 KB
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
package com.taobao.pamirs.schedule.test;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.taobao.pamirs.schedule.IScheduleTaskDealSingle;
import com.taobao.pamirs.schedule.TaskItemDefine;
/**
* 单个任务处理实现
*
* @author xuannan
*
*/
public class DemoTaskBean implements IScheduleTaskDealSingle<Long> {
protected static transient Logger log = LoggerFactory.getLogger(DemoTaskBean.class);
public Comparator<Long> getComparator() {
return new Comparator<Long>() {
public int compare(Long o1, Long o2) {
return o1.compareTo(o2);
}
public boolean equals(Object obj) {
return this == obj;
}
};
}
public List<Long> selectTasks(String taskParameter,String ownSign, int taskItemNum,
List<TaskItemDefine> queryCondition, int fetchNum) throws Exception {
List<Long> result = new ArrayList<Long>();
int num = fetchNum / queryCondition.size();
Random random = new Random(System.currentTimeMillis());
String message = "获取数据...[ownSign=" + ownSign + ",taskParameter=\"" + taskParameter +"\"]:";
boolean isFirst = true;
for (TaskItemDefine s : queryCondition) {
long taskItem = Integer.parseInt(s.getTaskItemId()) * 10000000L;
for (int i = 0; i < num; i++) {
result.add(taskItem + random.nextLong()% 100000L);
}
if (isFirst == false) {
message = message + ",";
}else{
isFirst = false;
}
message = message + s.getTaskItemId() + "{" + s.getParameter() +"}";
}
log.info(message);
return result;
}
public boolean execute(Long task, String ownSign) throws Exception {
Thread.sleep(50);
log.info("处理任务["+ownSign+"]:" + task);
return true;
}
}