DownGradeStateMachine.java
1.97 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
package com.yoho.search.common.downgrade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by xy on 2016/8/24.
*/
public class DownGradeStateMachine {
private static final Logger logger = LoggerFactory.getLogger("DOWNGRADE");
/**
* 直接走全降级流程
*
* @return
*/
public static DownGradeLevelEnum getDirectDownGradeLevel() {
logger.info("direct change to DOWN_GRADE_LEVEL_ON ");
return DownGradeLevelEnum.DOWN_GRADE_LEVEL_ON;
}
/**
*
* @param downGradeLevelEnum
* 降级state状态
* @param downgrade
* true 降级通道;false 恢复通道
* @return
*/
public static DownGradeLevelEnum changeDownGradeLevel(DownGradeLevelEnum downGradeLevelEnum, boolean downgrade) {
logger.info("try changeDownGradeLevel , current is [{}], operation is [{}]", downGradeLevelEnum.name(), downgrade ? "downgrade" : "revert");
switch (downGradeLevelEnum) {
case DOWN_GRADE_LEVEL_OFF:
if (downgrade) {
downGradeLevelEnum = DownGradeLevelEnum.DOWN_GRADE_LEVEL_HALF;
logger.info("DownGradeLevel change from [{}] to [{}]", DownGradeLevelEnum.DOWN_GRADE_LEVEL_OFF, DownGradeLevelEnum.DOWN_GRADE_LEVEL_HALF);
}
break;
case DOWN_GRADE_LEVEL_HALF:
if (downgrade) {
downGradeLevelEnum = DownGradeLevelEnum.DOWN_GRADE_LEVEL_ON;
logger.info("DownGradeLevel change from [{}] to [{}]", DownGradeLevelEnum.DOWN_GRADE_LEVEL_HALF, DownGradeLevelEnum.DOWN_GRADE_LEVEL_ON);
} else {
downGradeLevelEnum = DownGradeLevelEnum.DOWN_GRADE_LEVEL_OFF;
logger.info("DownGradeLevel change from [{}] to [{}]", DownGradeLevelEnum.DOWN_GRADE_LEVEL_HALF, DownGradeLevelEnum.DOWN_GRADE_LEVEL_OFF);
}
break;
case DOWN_GRADE_LEVEL_ON:
if (!downgrade) {
downGradeLevelEnum = DownGradeLevelEnum.DOWN_GRADE_LEVEL_HALF;
logger.info("DownGradeLevel change from [{}] to [{}]", DownGradeLevelEnum.DOWN_GRADE_LEVEL_ON, DownGradeLevelEnum.DOWN_GRADE_LEVEL_HALF);
}
break;
}
return downGradeLevelEnum;
}
}