From 1492973910b9cdaeaa8f485d30fb73172d039c4f Mon Sep 17 00:00:00 2001 From: Ronald Roskens Date: Thu, 17 Jun 2010 22:00:24 -0500 Subject: [PATCH 3/3] Optimize for the case where the end time of the outage is prior to our current time, by only computing the end time. --- .../opennms/netmgt/config/BasicScheduleUtils.java | 48 ++++++++++++-------- 1 files changed, 29 insertions(+), 19 deletions(-) diff --git a/opennms-services/src/main/java/org/opennms/netmgt/config/BasicScheduleUtils.java b/opennms-services/src/main/java/org/opennms/netmgt/config/BasicScheduleUtils.java index 03fa9ec..d35e4e4 100644 --- a/opennms-services/src/main/java/org/opennms/netmgt/config/BasicScheduleUtils.java +++ b/opennms-services/src/main/java/org/opennms/netmgt/config/BasicScheduleUtils.java @@ -60,7 +60,7 @@ public class BasicScheduleUtils { log.debug("isTimeInOutage: checking for time '" + cal.getTime() + "' in schedule '" + sched.getName() + "'"); if (sched == null) return false; - long curCalTime = cal.getTime().getTime(); + long curCalTime = cal.getTimeInMillis(); Calendar outCalBegin = new GregorianCalendar(); Calendar outCalEnd = new GregorianCalendar(); @@ -103,26 +103,36 @@ public class BasicScheduleUtils { // if time of day was specified and did not match, continue if (oTimeDay != null && !inOutage) continue; - - // set time in out calendars - setOutCalTime(outCalBegin, begins); + + /** + * set time in out calendars, starting with the end time. + * + * By starting with the end time, we can optimize out the case where + * the end time is prior to our current time, meaning we don't need + * to convert the time from a string to an object. + * + */ setOutCalTime(outCalEnd, ends); - - // check if calendar passed is in the out cal range - if (log.isDebugEnabled()) - log.debug("isTimeInOutage: checking begin/end time...\n current: " + cal.getTime() + "\n begin: " + outCalBegin.getTime() + "\n end: " + outCalEnd.getTime()); - - // round these to the surrounding seconds since we can only specify - // this to seconds - // accuracy in the config file - long outCalBeginTime = outCalBegin.getTimeInMillis() / 1000 * 1000; long outCalEndTime = (outCalEnd.getTimeInMillis() / 1000 + 1) * 1000; - - if (curCalTime >= outCalBeginTime && curCalTime < outCalEndTime) - inOutage = true; - else - inOutage = false; - + + if (log.isDebugEnabled()) + log.debug("isTimeInOutage: comparing current time to end time: \n current: " + cal.getTime() + "\n end: " + outCalEnd.getTime()); + + if (curCalTime < outCalEndTime) { + // Our end time is before our current time, check the beginning. + + setOutCalTime(outCalBegin, begins); + long outCalBeginTime = outCalBegin.getTimeInMillis() / 1000 * 1000; + + if (log.isDebugEnabled()) + log.debug("isTimeInOutage: comparing current time to begin time: \n current: " + cal.getTime() + "\n begin: " + outCalBegin.getTime()); + + if (curCalTime < outCalBeginTime) { + inOutage = false; + } else { + inOutage = true; + } + } } return inOutage; } -- 1.6.4.2