package at.gv.egovernment.moa.spss.server.service; import java.util.Date; import iaik.pki.revocation.RevocationSourceTypes; import iaik.pki.store.revocation.archive.Archive; import iaik.pki.store.revocation.archive.ArchiveFactory; import at.gv.egovernment.moa.logging.LogMsg; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.BoolUtils; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import at.gv.egovernment.moa.spss.server.logging.TransactionId; import at.gv.egovernment.moa.spss.util.MessageProvider; /** * A Runnable for periodically cleaning up the revocation archive. * @author Patrick Peck * @version $Id$ */ public class RevocationArchiveCleaner implements Runnable { /** The inverval between two clean-ups of the revocation archive. */ private long archiveCleanupInterval; /** * Create a new RevocationArchiveCleaner. * * @param archiveCleanupInterval The interval between two clean-ups of the * revocation archive. */ public RevocationArchiveCleaner(long archiveCleanupInterval) { this.archiveCleanupInterval = archiveCleanupInterval; } /** * Run the RevocationArchiveCleaner in its own * Thread. */ public void run() { while (true) { try { ConfigurationProvider config = ConfigurationProvider.getInstance(); String archiveInfo = config.getGenericConfiguration( ConfigurationProvider.ARCHIVE_REVOCATION_INFO_PROPERTY, "false"); if (BoolUtils.valueOf(archiveInfo)) { Archive archive = ArchiveFactory.getInstance().getArchive(); long archiveDurationMillis = (long) config.getCRLArchiveDuration() * 86400000; // delete old archive data if (archiveDurationMillis > 0) { Date olderThan = new Date(System.currentTimeMillis() - archiveDurationMillis); archive.deleteOldArchiveEntries( RevocationSourceTypes.CRL, olderThan, new TransactionId("RevocationArchiveCleaner")); } } } catch (Exception e) { MessageProvider msg = MessageProvider.getInstance(); Logger.error(new LogMsg(msg.getMessage("init.02", null)), e); } // sleep try { Thread.sleep(archiveCleanupInterval * 1000); } catch (InterruptedException e) { // ok to do nothing here } } } }