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 * http://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 /** The common event super type for all reloading events. */
35 public static final EventType<ReloadingEvent> ANY = new EventType<>(Event.ANY, "RELOAD");
36
37 /**
38 * The serial version UID.
39 */
40 private static final long serialVersionUID = 20140701L;
41
42 /** Stores additional data about this event. */
43 private final Object data;
44
45 /**
46 * Creates a new instance of {@code ReloadingEvent} and initializes it.
47 *
48 * @param source the controller which generated this event
49 * @param addData an arbitrary data object to be evaluated by event listeners
50 */
51 public ReloadingEvent(final ReloadingController source, final Object addData) {
52 super(source, ANY);
53 data = addData;
54 }
55
56 /**
57 * Gets the {@code ReloadingController} which caused this event.
58 *
59 * @return the responsible {@code ReloadingController}
60 */
61 public ReloadingController getController() {
62 return (ReloadingController) getSource();
63 }
64
65 /**
66 * Gets an object with additional data about the reload operation. This is the object that was passed to the
67 * {@link ReloadingController} when it was asked to do a reloading check. This is a generic mechanism to pass arbitrary
68 * data to reloading listeners.
69 *
70 * @return additional data about the reload operation (can be <b>null</b>)
71 */
72 public Object getData() {
73 return data;
74 }
75 }