    001// Licensed under the Apache License, Version 2.0 (the "License");
    002// you may not use this file except in compliance with the License.
    003// You may obtain a copy of the License at
    004//
    005// http://www.apache.org/licenses/LICENSE-2.0
    006//
    007// Unless required by applicable law or agreed to in writing, software
    008// distributed under the License is distributed on an "AS IS" BASIS,
    009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    010// See the License for the specific language governing permissions and
    011// limitations under the License.
    012
    013package org.apache.tapestry5.commons.services;
    014
    015import java.util.List;
    016import java.util.Map;
    017import java.util.function.Function;
    018
    019import org.apache.tapestry5.ioc.annotations.IncompatibleChange;
    020
    021/**
    022 * An object which manages a list of {@link org.apache.tapestry5.commons.services.InvalidationListener}s. There are multiple
    023 * event hub services implementing this interface, each with a specific marker annotation; each can register listeners
    024 * and fire events; these are based on the type of resource that has been invalidated. Tapestry has built-in support
    025 * for:
    026 * <dl>
    027 * <dt>message catalog resources
    028 * <dd><a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/ComponentMessages.html">ComponentMessages</a> marker annotation
    029 * <dt>component templates
    030 * <dd><a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/ComponentTemplates.html">ComponentTemplates</a> marker annotation
    031 * <dt>component classes
    032 * <dd><a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/ComponentClasses.html">ComponentClasses</a> marker annotation
    033 * </dl>
    034 *
    035 * Starting in Tapestry 5.3, these services are disabled in production (it does nothing).
    036 *
    037 * @since 5.1.0.0
    038 */
    039public interface InvalidationEventHub
    040{
    041    /**
    042     * Adds a listener, who needs to know when an underlying resource of a given category has changed (so that the
    043     * receiver may discard any cached data that may have been invalidated). Does nothing in production mode.
    044     *
    045     * @deprecated in 5.4, use {@link #addInvalidationCallback(Runnable)} instead}
    046     */
    047    void addInvalidationListener(InvalidationListener listener);
    048
    049    /**
    050     * Adds a callback that is invoked when an underlying tracked resource has changed. Does nothing in production mode.
    051     *
    052     * @since  5.4
    053     */
    054    void addInvalidationCallback(Runnable callback);
    055
    056    /**
    057     * Adds a callback that clears the map.
    058     *
    059     * @since 5.4
    060     */
    061    void clearOnInvalidation(Map<?,?> map);
    062
    063    /**
    064     * Adds a callback, as a function that receives a list of strings and also returns a list of strings,
    065     * that is invoked when one or more listed underlying tracked resource have changed.
    066     * An empty list should be considered as all resources being changed and any caches needing to be cleared.
    067     * The return value of the function should be a non-null, but possibly empty, list of other resources that also
    068     * need to be invalidated in a recursive fashion.
    069     * This method does nothing in production mode.
    070     * @since 5.8.3
    071     */
    072    @IncompatibleChange(release = "5.8.3", details = "Added method")
    073    void addInvalidationCallback(Function<List<String>, List<String>> function);
    074
    075   /**
    076    * Notify resource-specific invalidations to listeners.
    077    * @since 5.8.3
    078    */
    079   @IncompatibleChange(release = "5.8.3", details = "Added method")
    080   void fireInvalidationEvent(List<String> resources);
    081
    082}