JobStatistics.java
2.23 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
* Copyright (c) 2005, 2014 springside.github.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
*******************************************************************************/
package com.cjs.cms.util.redis.scheduler;
import com.cjs.cms.util.redis.JedisTemplate;
import redis.clients.jedis.Jedis;
import redis.clients.util.Pool;
/**
* 支持对当前任务池情况的状态数据查询.
*
* @author calvin
*/
public class JobStatistics {
private JedisTemplate jedisTemplate;
private String scheduledJobKey;
private String readyJobKey;
private String lockJobKey;
private String dispatchCounterKey;
private String retryCounterKey;
public JobStatistics(String jobName, Pool<Jedis> jedisPool) {
scheduledJobKey = Keys.getScheduledJobKey(jobName);
readyJobKey = Keys.getReadyJobKey(jobName);
lockJobKey = Keys.getLockJobKey(jobName);
dispatchCounterKey = Keys.getDispatchCounterKey(jobName);
retryCounterKey = Keys.getRetryCounterKey(jobName);
jedisTemplate = new JedisTemplate(jedisPool);
}
/**
* 获取已安排但未达到触发条件的Job数量.
*/
public long getScheduledJobNumber() {
return jedisTemplate.zcard(scheduledJobKey);
}
/**
* 获取已触发但未被客户端取走的Job数量.
*/
public long getReadyJobNumber() {
return jedisTemplate.llen(readyJobKey);
}
/**
* 获取高可靠模式下,已被取走执行但未报告完成的Job数量.
*/
public long getLockJobNumber() {
return jedisTemplate.zcard(lockJobKey);
}
/**
* 获取已触发的Job总数。
*/
public long getDispatchCounter() {
return jedisTemplate.getAsLong(dispatchCounterKey);
}
/**
* 获取高可靠模式下,已重做的Job总数。
*/
public long getRetryCounter() {
return jedisTemplate.getAsLong(retryCounterKey);
}
/**
* 重置所有计数器.
*/
public void restCounters() {
jedisTemplate.set(dispatchCounterKey, "0");
jedisTemplate.set(retryCounterKey, "0");
}
}