The Java code I'm reading is:
private void validateCoordinatorJob() throws Exception {
// check if startTime < endTime
if (!coordJob.getStartTime().before(coordJob.getEndTime())) {
throw new IllegalArgumentException("Coordinator Start Time must be earlier than End Time.");
}
try {
// Check if a coord job with cron frequency will materialize actions
int freq = Integer.parseInt(coordJob.getFrequency());
// Check if the frequency is faster than 5 min if enabled
if (ConfigurationService.getBoolean(CONF_CHECK_MAX_FREQUENCY)) {
CoordinatorJob.Timeunit unit = coordJob.getTimeUnit();
if (freq == 0 || (freq < 5 && unit == CoordinatorJob.Timeunit.MINUTE)) {
throw new IllegalArgumentException("Coordinator job with frequency [" + freq +
"] minutes is faster than allowed maximum of 5 minutes ("
+ CONF_CHECK_MAX_FREQUENCY + " is set to true)");
}
}
} catch (NumberFormatException e) {
Date start = coordJob.getStartTime();
Calendar cal = Calendar.getInstance();
cal.setTime(start);
cal.add(Calendar.MINUTE, -1);
start = cal.getTime();
Date nextTime = CoordCommandUtils.getNextValidActionTimeForCronFrequency(start, coordJob);
if (nextTime == null) {
throw new IllegalArgumentException("Invalid coordinator cron frequency: " + coordJob.getFrequency());
}
if (!nextTime.before(coordJob.getEndTime())) {
throw new IllegalArgumentException("Coordinator job with frequency '" +
coordJob.getFrequency() + "' materializes no actions between start and end time.");
}
}
}
What I don't get is whether "Coordinator job with frequency [" + freq + "] minutes is faster than allowed maximum of 5 minutes ("+ CONF_CHECK_MAX_FREQUENCY + " is set to true)"
log can be printed.
As long as I know, when if (freq == 0 || (freq < 5 && unit == CoordinatorJob.Timeunit.MINUTE))
condition meets and the program throws IllegalArgumentException.
The thrown exception will be caught at catch (NumberFormatException e)
, and handled in that block as e
.
But that e
is never used afterward.
So I wonder whether it's possible to print Coordinator job with frequency ...
log.
For me, it doesn't seem to have a difference between the original code and just putting the catch block into if (freq == 0 || (freq < 5 && unit == CoordinatorJob.Timeunit.MINUTE))
statement, as below:
private void validateCoordinatorJob() throws Exception {
// check if startTime < endTime
if (!coordJob.getStartTime().before(coordJob.getEndTime())) {
throw new IllegalArgumentException("Coordinator Start Time must be earlier than End Time.");
}
// Check if a coord job with cron frequency will materialize actions
int freq = Integer.parseInt(coordJob.getFrequency());
// Check if the frequency is faster than 5 min if enabled
if (ConfigurationService.getBoolean(CONF_CHECK_MAX_FREQUENCY)) {
CoordinatorJob.Timeunit unit = coordJob.getTimeUnit();
if (freq == 0 || (freq < 5 && unit == CoordinatorJob.Timeunit.MINUTE)) {
Date start = coordJob.getStartTime();
Calendar cal = Calendar.getInstance();
cal.setTime(start);
cal.add(Calendar.MINUTE, -1);
start = cal.getTime();
Date nextTime = CoordCommandUtils.getNextValidActionTimeForCronFrequency(start, coordJob);
if (nextTime == null) {
throw new IllegalArgumentException("Invalid coordinator cron frequency: " + coordJob.getFrequency());
}
if (!nextTime.before(coordJob.getEndTime())) {
throw new IllegalArgumentException("Coordinator job with frequency '" +
coordJob.getFrequency() + "' materializes no actions between start and end time.");
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…