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

org.dspace.health.Check Maven / Gradle / Ivy

There is a newer version: 8.0
Show newest version
/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.health;

import org.apache.logging.log4j.Logger;

/**
 * Abstract check interface.
 *
 * @author LINDAT/CLARIN dev team
 */

public abstract class Check {

    protected static Logger log = org.apache.logging.log4j.LogManager.getLogger(Check.class);
    long took_ = -1L;
    String report_ = null;
    private String errors_ = "";

    // this method should be overridden
    protected abstract String run(ReportInfo ri);

    public void report(ReportInfo ri) {
        took_ = System.currentTimeMillis();
        try {
            String run_report = run(ri);
            report_ = errors_ + run_report;
        } finally {
            took_ = System.currentTimeMillis() - took_;
        }
    }

    protected void error(Throwable e) {
        error(e, null);
    }

    protected void error(Throwable e, String msg) {
        errors_ += "====\nException occurred!\n";
        if (null != e) {
            errors_ += e.toString() + "\n";
            log.error("Exception during healthcheck:", e);
        }
        if (null != msg) {
            errors_ += "Reason: " + msg + "\n";
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy