1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.core.spi;
16  
17  /**
18   * This class configuration events which can be of various types such as
19   *  CHANGE_DETECTED, CONFIGURATION_STARTED and CONFIGURATION_ENDED.
20   *
21   *  Configuration events can be accompanied by supplemental data which can be null.
22   *
23   * @since 1.3.6/1.4.6
24   */
25  
26  public class ConfigurationEvent {
27  
28  
29      public enum EventType {
30          CHANGE_DETECTOR_REGISTERED,
31  
32          CHANGE_DETECTOR_RUNNING,
33          CHANGE_DETECTED,
34          CONFIGURATION_STARTED,
35          PARTIAL_CONFIGURATION_ENDED_SUCCESSFULLY,
36          CONFIGURATION_ENDED_SUCCESSFULLY,
37          CONFIGURATION_ENDED_WITH_XML_PARSING_ERRORS;
38      }
39      final EventType eventType;
40      final Object data;
41  
42      /**
43       * Construct a ConfigurationEvent instance.
44       *
45       * @param eventType
46       * @param data supplemental data, can be null
47       */
48      private ConfigurationEvent(EventType eventType, Object data) {
49          this.eventType = eventType;
50          this.data = data;
51      }
52  
53      static public ConfigurationEvent newConfigurationChangeDetectorRunningEvent(Object data) {
54          return new ConfigurationEvent(EventType.CHANGE_DETECTOR_RUNNING, data);
55      }
56  
57      static public ConfigurationEvent newConfigurationChangeDetectorRegisteredEvent(Object data) {
58          return new ConfigurationEvent(EventType.CHANGE_DETECTOR_REGISTERED, data);
59      }
60      static public ConfigurationEvent newConfigurationChangeDetectedEvent(Object data) {
61          return new ConfigurationEvent(EventType.CHANGE_DETECTED, data);
62      }
63      static public ConfigurationEvent newConfigurationStartedEvent(Object data) {
64          return new ConfigurationEvent(EventType.CONFIGURATION_STARTED, data);
65      }
66      static public ConfigurationEvent newPartialConfigurationEndedSuccessfullyEvent(Object data) {
67          return new ConfigurationEvent(EventType.PARTIAL_CONFIGURATION_ENDED_SUCCESSFULLY, data);
68      }
69  
70  
71      static public ConfigurationEvent newConfigurationEndedSuccessfullyEvent(Object data) {
72          return new ConfigurationEvent(EventType.CONFIGURATION_ENDED_SUCCESSFULLY, data);
73      }
74      static public ConfigurationEvent newConfigurationEndedWithXMLParsingErrorsEvent(Object data) {
75          return new ConfigurationEvent(EventType.CONFIGURATION_ENDED_WITH_XML_PARSING_ERRORS, data);
76      }
77      public EventType getEventType() {
78          return eventType;
79      }
80  
81      public Object getData() {
82          return data;
83      }
84  
85  
86      @Override
87      public String toString() {
88          return "ConfigurationEvent{" + "eventType=" + eventType + ", data=" + data + '}';
89      }
90  }