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