/** * This method checks to see if it is time to run the garbage collection thread based on the * settings in the gateway.properties file. If it is, then it spins off a thread to do garbage * collection of the aggregator tables. */ public static void runGarbageCollection() { // see if we need to run the collector... // ---------------------------------------- if (bRunCollector()) { String sStaleDuration = ""; int iStaleDuration = 0; try { sStaleDuration = PropertyAccessor.getProperty(GATEWAY_PROPERTY_FILE, GARBAGE_COLLECT_STALE_DURATION); iStaleDuration = Integer.parseInt(sStaleDuration); } catch (Exception e) { String sErrorMessage = "Failed to read and parse property: " + GARBAGE_COLLECT_STALE_DURATION + " from PropertyFile: " + GATEWAY_PROPERTY_FILE + ".propertues. No " + "garbage collection will be done on the aggregator tables."; log.error(sErrorMessage); return; } if ((sStaleDuration == null) || (sStaleDuration.length() <= 0)) { String sErrorMessage = "Failed to read and parse property: " + GARBAGE_COLLECT_STALE_DURATION + " from PropertyFile: " + GATEWAY_PROPERTY_FILE + ".propertues. No " + "garbage collection will be done on the aggregator tables."; log.error(sErrorMessage); return; } Calendar oCal = Calendar.getInstance(); oCal.add(Calendar.SECOND, (-1) * iStaleDuration); log.debug("Running aggregator garbage collection thread now."); GarbageCollectorThread oCollectorThread = new GarbageCollectorThread(oCal.getTime()); oCollectorThread.run(); dtLastRun = new Date(); } }
/** * This method checks to see if we should run the collector based on the time settings in the * gateway.properties file. If we should run it, then true is returnd. Otherwise false is * returned. * * @return TRUE if we should run the garbage collector. */ private static boolean bRunCollector() { String sTimeDuration = ""; int iTimeDuration = 0; try { sTimeDuration = PropertyAccessor.getProperty(GATEWAY_PROPERTY_FILE, GARBAGE_COLLECT_TIME_DURATION); iTimeDuration = Integer.parseInt(sTimeDuration); } catch (Exception e) { String sErrorMessage = "Failed to read and parse property: " + GARBAGE_COLLECT_TIME_DURATION + " from PropertyFile: " + GATEWAY_PROPERTY_FILE + ".propertues. No " + "garbage collection will be done on the aggregator tables."; log.error(sErrorMessage); return false; } if ((sTimeDuration == null) || (sTimeDuration.length() <= 0)) { String sErrorMessage = "Failed to read and parse property: " + GARBAGE_COLLECT_TIME_DURATION + " from PropertyFile: " + GATEWAY_PROPERTY_FILE + ".propertues. No " + "garbage collection will be done on the aggregator tables."; log.error(sErrorMessage); return false; } Calendar oCal = Calendar.getInstance(); oCal.add(Calendar.SECOND, (-1) * iTimeDuration); if (oCal.getTime().getTime() > dtLastRun.getTime()) { return true; } return false; }