<commit_before>/*
 * #%L
 * Bitrepository Audit Trail Service
 * %%
 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */
package org.bitrepository.audittrails.preserver;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.bitrepository.audittrails.store.AuditTrailStore;
import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE;
import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE;
import org.bitrepository.client.eventhandler.EventHandler;
import org.bitrepository.common.ArgumentValidator;
import org.bitrepository.common.exceptions.OperationFailedException;
import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.utils.Base16Utils;
import org.bitrepository.common.utils.CalendarUtils;
import org.bitrepository.common.utils.ChecksumUtils;
import org.bitrepository.common.utils.FileUtils;
import org.bitrepository.common.utils.SettingsUtils;
import org.bitrepository.common.utils.TimeUtils;
import org.bitrepository.modify.putfile.BlockingPutFileClient;
import org.bitrepository.modify.putfile.PutFileClient;
import org.bitrepository.protocol.CoordinationLayerException;
import org.bitrepository.protocol.FileExchange;
import org.bitrepository.settings.referencesettings.AuditTrailPreservation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Handles the preservation of audit trails to a collection defined for the local repository.
 * This means, that each set of audit trails will be preserved within its own collection.
 */
public class LocalAuditTrailPreserver implements AuditTrailPreserver {
    /** The log.*/
    private Logger log = LoggerFactory.getLogger(getClass());
    /** The audit trails store, where the audit trails can be extracted.*/
    private final AuditTrailStore store;
    /** The put file client for sending the resulting files. */
    private final BlockingPutFileClient client;

    /** The timer for scheduling the preservation of audit trails.*/
    private Timer timer;
    /** The timertask for preserving the audit trails.*/
    private AuditPreservationTimerTask auditTask = null;
    /** The mapping between collection and the Audit trail packer for packing and compressing the audit trails.*/
    Map<String, AuditPacker> auditPackers = new HashMap<String, AuditPacker>();
    /** The preservationSettings for the local audit trail preserver.*/
    private final AuditTrailPreservation preservationSettings;
    /** The full settings (needed for checksum calculation) */
    private final Settings settings;
    /** The fileexchange to use for uploading files which should be put to the preservation collection */
    private final FileExchange exchange;
    
    /**
     * Constructor.
     * @param settings The preservationSettings for the audit trail service.
     * @param store The storage of the audit trails, which should be preserved.
     * @param client The PutFileClient for putting the audit trail packages to the collection.
     */
    public LocalAuditTrailPreserver(Settings settings, AuditTrailStore store, PutFileClient client,
                                    FileExchange exchange) {
        ArgumentValidator.checkNotNull(settings, "Settings preservationSettings");
        ArgumentValidator.checkNotNull(store, "AuditTrailStore store");
        ArgumentValidator.checkNotNull(client, "PutFileClient client");
        
        this.settings = settings;
        this.preservationSettings = settings.getReferenceSettings().getAuditTrailServiceSettings().getAuditTrailPreservation();
        this.store = store;
        this.client = new BlockingPutFileClient(client);
        this.exchange = exchange;
        for(String collectionID : SettingsUtils.getAllCollectionsIDs()) {
            this.auditPackers.put(collectionID, new AuditPacker(store, preservationSettings, collectionID));
        }
    }
    
    @Override
    public void start() {
        if(timer != null) {
            log.debug("Cancelling old timer.");
            timer.cancel();
        }
        long preservationInterval = preservationSettings.getAuditTrailPreservationInterval();
        log.info("Instantiating the preservation of audit trails every " +
                TimeUtils.millisecondsToHuman(preservationInterval));
        timer = new Timer();
        auditTask = new AuditPreservationTimerTask(preservationInterval);
        timer.scheduleAtFixedRate(auditTask,
                preservationSettings.getAuditTrailPreservationInterval()/10,
                preservationSettings.getAuditTrailPreservationInterval()/10);
    }
<commit_msg>Tuning audit trail preservation startup logging.<commit_after>/*
 * #%L
 * Bitrepository Audit Trail Service
 * %%
 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */
package org.bitrepository.audittrails.preserver;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.bitrepository.audittrails.store.AuditTrailStore;
import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE;
import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE;
import org.bitrepository.client.eventhandler.EventHandler;
import org.bitrepository.common.ArgumentValidator;
import org.bitrepository.common.exceptions.OperationFailedException;
import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.utils.Base16Utils;
import org.bitrepository.common.utils.CalendarUtils;
import org.bitrepository.common.utils.ChecksumUtils;
import org.bitrepository.common.utils.FileUtils;
import org.bitrepository.common.utils.SettingsUtils;
import org.bitrepository.common.utils.TimeUtils;
import org.bitrepository.modify.putfile.BlockingPutFileClient;
import org.bitrepository.modify.putfile.PutFileClient;
import org.bitrepository.protocol.CoordinationLayerException;
import org.bitrepository.protocol.FileExchange;
import org.bitrepository.settings.referencesettings.AuditTrailPreservation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Handles the preservation of audit trails to a collection defined for the local repository.
 * This means, that each set of audit trails will be preserved within its own collection.
 */
public class LocalAuditTrailPreserver implements AuditTrailPreserver {
    /** The log.*/
    private Logger log = LoggerFactory.getLogger(getClass());
    /** The audit trails store, where the audit trails can be extracted.*/
    private final AuditTrailStore store;
    /** The put file client for sending the resulting files. */
    private final BlockingPutFileClient client;

    /** The timer for scheduling the preservation of audit trails.*/
    private Timer timer;
    /** The timertask for preserving the audit trails.*/
    private AuditPreservationTimerTask auditTask = null;
    /** The mapping between collection and the Audit trail packer for packing and compressing the audit trails.*/
    Map<String, AuditPacker> auditPackers = new HashMap<String, AuditPacker>();
    /** The preservationSettings for the local audit trail preserver.*/
    private final AuditTrailPreservation preservationSettings;
    /** The full settings (needed for checksum calculation) */
    private final Settings settings;
    /** The fileexchange to use for uploading files which should be put to the preservation collection */
    private final FileExchange exchange;
    
    /**
     * Constructor.
     * @param settings The preservationSettings for the audit trail service.
     * @param store The storage of the audit trails, which should be preserved.
     * @param client The PutFileClient for putting the audit trail packages to the collection.
     */
    public LocalAuditTrailPreserver(Settings settings, AuditTrailStore store, PutFileClient client,
                                    FileExchange exchange) {
        ArgumentValidator.checkNotNull(settings, "Settings preservationSettings");
        ArgumentValidator.checkNotNull(store, "AuditTrailStore store");
        ArgumentValidator.checkNotNull(client, "PutFileClient client");
        
        this.settings = settings;
        this.preservationSettings = settings.getReferenceSettings().getAuditTrailServiceSettings().getAuditTrailPreservation();
        this.store = store;
        this.client = new BlockingPutFileClient(client);
        this.exchange = exchange;
        for(String collectionID : SettingsUtils.getAllCollectionsIDs()) {
            this.auditPackers.put(collectionID, new AuditPacker(store, preservationSettings, collectionID));
        }
    }
    
    @Override
    public void start() {
        if(timer != null) {
            log.debug("Cancelling old timer.");
            timer.cancel();
        }
        long preservationInterval = preservationSettings.getAuditTrailPreservationInterval();
        long timerCheckInterval = preservationInterval/10;
        log.info("Instantiating the preservation of audit trails every " +
                TimeUtils.millisecondsToHuman(preservationInterval) + ", starting in " +
                TimeUtils.millisecondsToHuman(timerCheckInterval));
        timer = new Timer();
        auditTask = new AuditPreservationTimerTask(preservationInterval);
        timer.scheduleAtFixedRate(auditTask, timerCheckInterval, timerCheckInterval);
    }

{'fraction_non_alphanumeric': 0.07742983485245014, 'fraction_numerical': 0.0034292933850735494, 'mean_word_length': 3.9561717352415027, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6005846', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2748, 'n_words': 897}