001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014
015package ch.qos.logback.core.spi;
016
017/**
018 * This class configuration events which can be of various types such as
019 *  CHANGE_DETECTED, CONFIGURATION_STARTED and CONFIGURATION_ENDED.
020 *
021 *  Configuration events can be accompanied by supplemental data which can be null.
022 *
023 * @since 1.3.6/1.4.6
024 */
025
026public class ConfigurationEvent {
027
028
029    public enum EventType {
030        CHANGE_DETECTOR_REGISTERED,
031
032        CHANGE_DETECTOR_RUNNING,
033        CHANGE_DETECTED,
034        CONFIGURATION_STARTED,
035        PARTIAL_CONFIGURATION_ENDED_SUCCESSFULLY,
036        CONFIGURATION_ENDED_SUCCESSFULLY,
037        CONFIGURATION_ENDED_WITH_XML_PARSING_ERRORS;
038    }
039    final EventType eventType;
040    final Object data;
041
042    /**
043     * Construct a ConfigurationEvent instance.
044     *
045     * @param eventType
046     * @param data supplemental data, can be null
047     */
048    private ConfigurationEvent(EventType eventType, Object data) {
049        this.eventType = eventType;
050        this.data = data;
051    }
052
053    static public ConfigurationEvent newConfigurationChangeDetectorRunningEvent(Object data) {
054        return new ConfigurationEvent(EventType.CHANGE_DETECTOR_RUNNING, data);
055    }
056
057    static public ConfigurationEvent newConfigurationChangeDetectorRegisteredEvent(Object data) {
058        return new ConfigurationEvent(EventType.CHANGE_DETECTOR_REGISTERED, data);
059    }
060    static public ConfigurationEvent newConfigurationChangeDetectedEvent(Object data) {
061        return new ConfigurationEvent(EventType.CHANGE_DETECTED, data);
062    }
063    static public ConfigurationEvent newConfigurationStartedEvent(Object data) {
064        return new ConfigurationEvent(EventType.CONFIGURATION_STARTED, data);
065    }
066    static public ConfigurationEvent newPartialConfigurationEndedSuccessfullyEvent(Object data) {
067        return new ConfigurationEvent(EventType.PARTIAL_CONFIGURATION_ENDED_SUCCESSFULLY, data);
068    }
069
070
071    static public ConfigurationEvent newConfigurationEndedSuccessfullyEvent(Object data) {
072        return new ConfigurationEvent(EventType.CONFIGURATION_ENDED_SUCCESSFULLY, data);
073    }
074    static public ConfigurationEvent newConfigurationEndedWithXMLParsingErrorsEvent(Object data) {
075        return new ConfigurationEvent(EventType.CONFIGURATION_ENDED_WITH_XML_PARSING_ERRORS, data);
076    }
077    public EventType getEventType() {
078        return eventType;
079    }
080
081    public Object getData() {
082        return data;
083    }
084
085
086    @Override
087    public String toString() {
088        return "ConfigurationEvent{" + "eventType=" + eventType + ", data=" + data + '}';
089    }
090}