chris@1: /* chris@1: * SONEWS News Server chris@1: * see AUTHORS for the list of contributors chris@1: * chris@1: * This program is free software: you can redistribute it and/or modify chris@1: * it under the terms of the GNU General Public License as published by chris@1: * the Free Software Foundation, either version 3 of the License, or chris@1: * (at your option) any later version. chris@1: * chris@1: * This program is distributed in the hope that it will be useful, chris@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@1: * GNU General Public License for more details. chris@1: * chris@1: * You should have received a copy of the GNU General Public License chris@1: * along with this program. If not, see . chris@1: */ chris@1: chris@1: package org.sonews.util; chris@1: chris@1: import org.sonews.daemon.Config; chris@1: import org.sonews.daemon.storage.Database; chris@1: import org.sonews.daemon.storage.Article; chris@1: import java.util.Date; chris@1: chris@1: /** chris@1: * The purger is started in configurable intervals to search chris@1: * for old messages that can be purged. chris@1: * @author Christian Lins chris@1: * @since sonews/0.5.0 chris@1: */ chris@1: public class Purger chris@1: { chris@1: chris@1: private long lifetime; chris@1: chris@1: public Purger() chris@1: { chris@1: this.lifetime = Config.getInstance().get("sonews.article.lifetime", 30) chris@1: * 24L * 60L * 60L * 1000L; // in Milliseconds chris@1: } chris@1: chris@1: /** chris@1: * Loops through all messages and deletes them if their time chris@1: * has come. chris@1: */ chris@1: void purge() chris@1: throws Exception chris@1: { chris@1: System.out.println("Purging old messages..."); chris@1: chris@1: for (;;) chris@1: { chris@1: // TODO: Delete articles directly in database chris@1: Article art = null; //Database.getInstance().getOldestArticle(); chris@1: if (art == null) // No articles in the database chris@1: { chris@1: break; chris@1: } chris@1: chris@1: /* if (art.getDate().getTime() < (new Date().getTime() + this.lifetime)) chris@1: { chris@1: // Database.getInstance().delete(art); chris@1: System.out.println("Deleted: " + art); chris@1: } chris@1: else chris@1: { chris@1: break; chris@1: }*/ chris@1: } chris@1: } chris@1: chris@1: public static void main(String[] args) chris@1: { chris@1: try chris@1: { chris@1: Purger purger = new Purger(); chris@1: purger.purge(); chris@1: System.exit(0); chris@1: } chris@1: catch(Exception ex) chris@1: { chris@1: ex.printStackTrace(); chris@1: System.exit(1); chris@1: } chris@1: } chris@1: chris@1: }