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

com.rbmhtechnology.vind.monitoring.logger.MonitoringWriter Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.rbmhtechnology.vind.monitoring.logger;

import com.rbmhtechnology.vind.monitoring.logger.entry.MonitoringEntry;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * @author Thomas Kurz ([email protected])
 * @since 13.07.16.
 */
public abstract class MonitoringWriter { //TODO could be an interface

    public static MonitoringWriter getInstance() {
        ServiceLoader loader = ServiceLoader.load(MonitoringWriter.class);
        final Iterator it = loader.iterator();
        final MonitoringWriter server;
        if (!it.hasNext()) {
            throw new RuntimeException("No ReportWriter in classpath");
        } else {
            server = it.next();
        }
        if (it.hasNext()) {
            LoggerFactory.getLogger(MonitoringWriter.class).info("Multiple bindings for ReportWriter found: {}", loader.iterator());
        }
        return server;
    }

    public abstract void log(MonitoringEntry log);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy