ReloadingEvent.java

  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. import org.apache.commons.configuration2.event.Event;
  19. import org.apache.commons.configuration2.event.EventType;

  20. /**
  21.  * <p>
  22.  * An event that is fired when a reload operation is required.
  23.  * </p>
  24.  * <p>
  25.  * Events of this type are generated by {@link ReloadingController} if the need for a reload operation is detected. From
  26.  * the pay-load of the event information about the components involved is available.
  27.  * </p>
  28.  *
  29.  * @since 2.0
  30.  */
  31. public class ReloadingEvent extends Event {
  32.     /** The common event super type for all reloading events. */
  33.     public static final EventType<ReloadingEvent> ANY = new EventType<>(Event.ANY, "RELOAD");

  34.     /**
  35.      * The serial version UID.
  36.      */
  37.     private static final long serialVersionUID = 20140701L;

  38.     /** Stores additional data about this event. */
  39.     private final Object data;

  40.     /**
  41.      * Creates a new instance of {@code ReloadingEvent} and initializes it.
  42.      *
  43.      * @param source the controller which generated this event
  44.      * @param addData an arbitrary data object to be evaluated by event listeners
  45.      */
  46.     public ReloadingEvent(final ReloadingController source, final Object addData) {
  47.         super(source, ANY);
  48.         data = addData;
  49.     }

  50.     /**
  51.      * Gets the {@code ReloadingController} which caused this event.
  52.      *
  53.      * @return the responsible {@code ReloadingController}
  54.      */
  55.     public ReloadingController getController() {
  56.         return (ReloadingController) getSource();
  57.     }

  58.     /**
  59.      * Gets an object with additional data about the reload operation. This is the object that was passed to the
  60.      * {@link ReloadingController} when it was asked to do a reloading check. This is a generic mechanism to pass arbitrary
  61.      * data to reloading listeners.
  62.      *
  63.      * @return additional data about the reload operation (can be <strong>null</strong>)
  64.      */
  65.     public Object getData() {
  66.         return data;
  67.     }
  68. }