All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.boot.cleanup.Cleaner Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * Created on 06.11.2003
 *
 */
package at.spardat.xma.boot.cleanup;

import java.util.Properties;
import java.util.Timer;

import at.spardat.xma.boot.BootRuntime;
import at.spardat.xma.boot.Statics;
import at.spardat.xma.boot.logger.Logger;
import at.spardat.xma.boot.logger.LogLevel;

/**
 * @author s3595
 */
public class Cleaner {

    /* default initial cleanup is 15 minutes (value in seconds) */
    private static int DEFAULT_INITAL_CLEANUP_DELAY_MILLISEC = 900 * 1000;

    /* default cleanup cache interval is 3 hours (value in seconds) */
    private static int DEFAULT_CLEANUP_INTERVAL_MILLISEC = 10800 * 1000;

    private Logger log_;

    /** configuration properties */
    private Properties props;

    /* cleanup timer */
    private Timer cleanupTimer;

    public Cleaner( BootRuntime runtime ) {

        props = runtime.getConfigProperties();
        log_ = Logger.getLogger( "boot.cleaner");

    }

    public Properties getProperties( ) {
        return props;
    }

    public void startCleanup() {
        try {
            cleanupTimer = new Timer(true);
            long initialDelayMilliSec  = DEFAULT_INITAL_CLEANUP_DELAY_MILLISEC;
            long cleanupIntervalMilliSec = DEFAULT_CLEANUP_INTERVAL_MILLISEC;

            try {
                String strInitalDelay = props.getProperty(Statics.CFG_PROP_CLEANUP_INITIAL_DELAY);
                initialDelayMilliSec          = Integer.parseInt(strInitalDelay) * 1000;
                if(initialDelayMilliSec<=0) initialDelayMilliSec = DEFAULT_INITAL_CLEANUP_DELAY_MILLISEC;

                String strCleanupInterval = props.getProperty(Statics.CFG_PROP_CLEANUP_INTERVAL);
                cleanupIntervalMilliSec          = Integer.parseInt(strCleanupInterval) * 1000;
                if(cleanupIntervalMilliSec<=0) cleanupIntervalMilliSec = DEFAULT_CLEANUP_INTERVAL_MILLISEC;

            } catch (Exception e) {
                log_.log(LogLevel.WARNING, "Could not read Properties: " + Statics.CFG_PROP_CLEANUP_INITIAL_DELAY + ", " + Statics.CFG_PROP_CLEANUP_INTERVAL, e );
            }

            cleanupTimer.schedule(new CleanerDeamon(this), initialDelayMilliSec, cleanupIntervalMilliSec);
            log_.log(LogLevel.ALL, "cleaner deamon initialized. first run: {0} interval: {1}", new Object[] { new Long(initialDelayMilliSec), new Long(cleanupIntervalMilliSec) });

        } catch( Exception ex) {
            log_.log(LogLevel.WARNING, "Error schedule/initialize cleaner deamon" ,ex );
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy