View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.configuration2.reloading;
18  
19  import org.apache.commons.configuration2.event.Event;
20  import org.apache.commons.configuration2.event.EventType;
21  
22  /**
23   * <p>
24   * An event that is fired when a reload operation is required.
25   * </p>
26   * <p>
27   * Events of this type are generated by {@link ReloadingController} if the need for a reload operation is detected. From
28   * the pay-load of the event information about the components involved is available.
29   * </p>
30   *
31   * @since 2.0
32   */
33  public class ReloadingEvent extends Event {
34  
35      /** The common event super type for all reloading events. */
36      public static final EventType<ReloadingEvent> ANY = new EventType<>(Event.ANY, "RELOAD");
37  
38      /**
39       * The serial version UID.
40       */
41      private static final long serialVersionUID = 20140701L;
42  
43      /** Stores additional data about this event. */
44      private final Object data;
45  
46      /**
47       * Creates a new instance of {@code ReloadingEvent} and initializes it.
48       *
49       * @param source the controller which generated this event
50       * @param addData an arbitrary data object to be evaluated by event listeners
51       */
52      public ReloadingEvent(final ReloadingController source, final Object addData) {
53          super(source, ANY);
54          data = addData;
55      }
56  
57      /**
58       * Gets the {@code ReloadingController} which caused this event.
59       *
60       * @return the responsible {@code ReloadingController}
61       */
62      public ReloadingController getController() {
63          return (ReloadingController) getSource();
64      }
65  
66      /**
67       * Gets an object with additional data about the reload operation. This is the object that was passed to the
68       * {@link ReloadingController} when it was asked to do a reloading check. This is a generic mechanism to pass arbitrary
69       * data to reloading listeners.
70       *
71       * @return additional data about the reload operation (can be <strong>null</strong>)
72       */
73      public Object getData() {
74          return data;
75      }
76  }