Please answer these questions before submitting your issue.
Question
- What do you want to know?
use java schedule to design alarm plugin whether face some problem in cluster mode? or I don't understand the whole architecture
public void start(List<AlarmCallback> allCallbacks) {
LocalDateTime now = LocalDateTime.now();
lastExecuteTime = now;
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> {
try {
List<AlarmMessage> alarmMessageList = new ArrayList<>(30);
LocalDateTime checkTime = LocalDateTime.now();
int minutes = Minutes.minutesBetween(lastExecuteTime, checkTime).getMinutes();
boolean[] hasExecute = new boolean[] {false};
runningContext.values().forEach(ruleList -> ruleList.forEach(runningRule -> {
if (minutes > 0) {
runningRule.moveTo(checkTime);
/**
* Don't run in the first quarter per min, avoid to trigger false alarm.
*/
if (checkTime.getSecondOfMinute() > 15) {
hasExecute[0] = true;
alarmMessageList.addAll(runningRule.check());
}
}
}));
// Set the last execute time, and make sure the second is `00`, such as: 18:30:00
if (hasExecute[0]) {
lastExecuteTime = checkTime.minusSeconds(checkTime.getSecondOfMinute());
}
if (alarmMessageList.size() > 0) {
allCallbacks.forEach(callback -> callback.doAlarm(alarmMessageList));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}, 10, 10, TimeUnit.SECONDS);
}
Bug
-
Which version of SkyWalking, OS and JRE?
-
Which company or project?
-
What happen?
If possible, provide a way for reproducing the error. e.g. demo application, component version.
Requirement or improvement
- Please describe about your requirements or improvement suggestions.
Please answer these questions before submitting your issue.
Question
use java schedule to design alarm plugin whether face some problem in cluster mode? or I don't understand the whole architecture
Bug
Which version of SkyWalking, OS and JRE?
Which company or project?
What happen?
If possible, provide a way for reproducing the error. e.g. demo application, component version.
Requirement or improvement