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.ioc;
014
015import org.apache.tapestry5.commons.ObjectLocator;
016import org.apache.tapestry5.ioc.annotations.EagerLoad;
017import org.apache.tapestry5.ioc.services.UpdateListenerHub;
018
019/**
020 * Optional interface that may be implemented by a service implementation (or even
021 * a {@linkplain ObjectLocator#proxy(Class, Class) proxy} to give the service implementation
022 * more control over its lifecyle.
023 * 
024 * @since 5.2.2
025 */
026public interface ReloadAware
027{
028    /**
029     * Invoked when Tapestry {@linkplain UpdateListenerHub#fireCheckForUpdates() notices
030     * that the implementation class has changed}. The existing instance is notified, so that
031     * it can cleanly shutdown now, before being re-instantiated. This is necessary when the
032     * service implementation retains some form of external resources.
033     *
034     * In addition, the implementation may request an immediate reload. Normally, reloading of the service is deferred
035     * until a method of the proxy object is invoked (this causes the normal just-in-time instantiation of the
036     * implementation). When this method returns true, the implementation is re-created immediately. This is most often
037     * the case for services that are {@linkplain EagerLoad eagerly loaded} in the first place.
038     * 
039     * @return true if the service should be reloaded immediately, false if reload should be deferred
040     */
041    boolean shutdownImplementationForReload();
042}