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        CONFIGURATION_ENDED_SUCCESSFULLY,
036        CONFIGURATION_ENDED_WITH_XML_PARSING_ERRORS;
037    }
038    final EventType eventType;
039    final Object data;
040
041    /**
042     * Construct a ConfigurationEvent instance.
043     *
044     * @param eventType
045     * @param data supplemental data, can be null
046     */
047    private ConfigurationEvent(EventType eventType, Object data) {
048        this.eventType = eventType;
049        this.data = data;
050    }
051
052    static public ConfigurationEvent newConfigurationChangeDetectorRunningEvent(Object data) {
053        return new ConfigurationEvent(EventType.CHANGE_DETECTOR_RUNNING, data);
054    }
055
056    static public ConfigurationEvent newConfigurationChangeDetectorRegisteredEvent(Object data) {
057        return new ConfigurationEvent(EventType.CHANGE_DETECTOR_REGISTERED, data);
058    }
059    static public ConfigurationEvent newConfigurationChangeDetectedEvent(Object data) {
060        return new ConfigurationEvent(EventType.CHANGE_DETECTED, data);
061    }
062    static public ConfigurationEvent newConfigurationStartedEvent(Object data) {
063        return new ConfigurationEvent(EventType.CONFIGURATION_STARTED, data);
064    }
065    static public ConfigurationEvent newConfigurationEndedSuccessfullyEvent(Object data) {
066        return new ConfigurationEvent(EventType.CONFIGURATION_ENDED_SUCCESSFULLY, data);
067    }
068    static public ConfigurationEvent newConfigurationEndedWithXMLParsingErrorsEvent(Object data) {
069        return new ConfigurationEvent(EventType.CONFIGURATION_ENDED_WITH_XML_PARSING_ERRORS, data);
070    }
071    public EventType getEventType() {
072        return eventType;
073    }
074
075    public Object getData() {
076        return data;
077    }
078
079
080    @Override
081    public String toString() {
082        return "ConfigurationEvent{" + "eventType=" + eventType + ", data=" + data + '}';
083    }
084}