diff -r c404a87db5b7 -r 73b21e9f3958 src/org/sonews/util/Purger.java --- a/src/org/sonews/util/Purger.java Sun Aug 29 17:43:58 2010 +0200 +++ b/src/org/sonews/util/Purger.java Mon Aug 30 00:20:06 2010 +0200 @@ -40,110 +40,91 @@ public class Purger extends AbstractDaemon { - /** - * Loops through all messages and deletes them if their time - * has come. - */ - @Override - public void run() - { - try - { - while(isRunning()) - { - purgeDeleted(); - purgeOutdated(); + /** + * Loops through all messages and deletes them if their time + * has come. + */ + @Override + public void run() + { + try { + while (isRunning()) { + purgeDeleted(); + purgeOutdated(); - Thread.sleep(120000); // Sleep for two minutes - } - } - catch(StorageBackendException ex) - { - ex.printStackTrace(); - } - catch(InterruptedException ex) - { - Log.get().warning("Purger interrupted: " + ex); - } - } + Thread.sleep(120000); // Sleep for two minutes + } + } catch (StorageBackendException ex) { + ex.printStackTrace(); + } catch (InterruptedException ex) { + Log.get().warning("Purger interrupted: " + ex); + } + } - private void purgeDeleted() - throws StorageBackendException - { - List groups = StorageManager.current().getGroups(); - for(Channel channel : groups) - { - if(!(channel instanceof Group)) - continue; - - Group group = (Group)channel; - // Look for groups that are marked as deleted - if(group.isDeleted()) - { - List ids = StorageManager.current().getArticleNumbers(group.getInternalID()); - if(ids.size() == 0) - { - StorageManager.current().purgeGroup(group); - Log.get().info("Group " + group.getName() + " purged."); - } + private void purgeDeleted() + throws StorageBackendException + { + List groups = StorageManager.current().getGroups(); + for (Channel channel : groups) { + if (!(channel instanceof Group)) { + continue; + } - for(int n = 0; n < ids.size() && n < 10; n++) - { - Article art = StorageManager.current().getArticle(ids.get(n), group.getInternalID()); - StorageManager.current().delete(art.getMessageID()); - Log.get().info("Article " + art.getMessageID() + " purged."); - } - } - } - } + Group group = (Group) channel; + // Look for groups that are marked as deleted + if (group.isDeleted()) { + List ids = StorageManager.current().getArticleNumbers(group.getInternalID()); + if (ids.size() == 0) { + StorageManager.current().purgeGroup(group); + Log.get().info("Group " + group.getName() + " purged."); + } - private void purgeOutdated() - throws InterruptedException, StorageBackendException - { - long articleMaximum = - Config.inst().get("sonews.article.maxnum", Long.MAX_VALUE); - long lifetime = - Config.inst().get("sonews.article.lifetime", -1); + for (int n = 0; n < ids.size() && n < 10; n++) { + Article art = StorageManager.current().getArticle(ids.get(n), group.getInternalID()); + StorageManager.current().delete(art.getMessageID()); + Log.get().info("Article " + art.getMessageID() + " purged."); + } + } + } + } - if(lifetime > 0 || articleMaximum < Stats.getInstance().getNumberOfNews()) - { - Log.get().info("Purging old messages..."); - String mid = StorageManager.current().getOldestArticle(); - if (mid == null) // No articles in the database - { - return; - } + private void purgeOutdated() + throws InterruptedException, StorageBackendException + { + long articleMaximum = + Config.inst().get("sonews.article.maxnum", Long.MAX_VALUE); + long lifetime = + Config.inst().get("sonews.article.lifetime", -1); - Article art = StorageManager.current().getArticle(mid); - long artDate = 0; - String dateStr = art.getHeader(Headers.DATE)[0]; - try - { - artDate = Date.parse(dateStr) / 1000 / 60 / 60 / 24; - } - catch (IllegalArgumentException ex) - { - Log.get().warning("Could not parse date string: " + dateStr + " " + ex); - } + if (lifetime > 0 || articleMaximum < Stats.getInstance().getNumberOfNews()) { + Log.get().info("Purging old messages..."); + String mid = StorageManager.current().getOldestArticle(); + if (mid == null) // No articles in the database + { + return; + } - // Should we delete the message because of its age or because the - // article maximum was reached? - if (lifetime < 0 || artDate < (new Date().getTime() + lifetime)) - { - StorageManager.current().delete(mid); - System.out.println("Deleted: " + mid); - } - else - { - Thread.sleep(1000 * 60); // Wait 60 seconds - return; - } - } - else - { - Log.get().info("Lifetime purger is disabled"); - Thread.sleep(1000 * 60 * 30); // Wait 30 minutes - } - } + Article art = StorageManager.current().getArticle(mid); + long artDate = 0; + String dateStr = art.getHeader(Headers.DATE)[0]; + try { + artDate = Date.parse(dateStr) / 1000 / 60 / 60 / 24; + } catch (IllegalArgumentException ex) { + Log.get().warning("Could not parse date string: " + dateStr + " " + ex); + } + // Should we delete the message because of its age or because the + // article maximum was reached? + if (lifetime < 0 || artDate < (new Date().getTime() + lifetime)) { + StorageManager.current().delete(mid); + System.out.println("Deleted: " + mid); + } else { + Thread.sleep(1000 * 60); // Wait 60 seconds + return; + } + } else { + Log.get().info("Lifetime purger is disabled"); + Thread.sleep(1000 * 60 * 30); // Wait 30 minutes + } + } }