    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.http.services;
    014
    015import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
    016
    017/**
    018 * Analyzes a session-persisted object, specifically to see if it is dirty or not.
    019 *
    020 * This service is provided to support applications which store mutable session attributes where the
    021 * session is replicated to a slower medium (e.g. RDMBS, Cluster, etc) this can help alleviate excessive writes
    022 * to the session store while ensuring changes are propagated.
    023 *
    024 * The service implementation uses a mapped configuration to form a
    025 * {@linkplain org.apache.tapestry5.ioc.services.StrategyBuilder strategy} based on object type. The service may be
    026 * injected using the {@link org.apache.tapestry5.ioc.annotations.Primary} marker annotation.
    027 *
    028 * @see org.apache.tapestry5.http.annotations.ImmutableSessionPersistedObject
    029 * @see org.apache.tapestry5.http.OptimizedSessionPersistedObject
    030 * @since 5.1.0.0
    031 */
    032@UsesMappedConfiguration(key = Class.class, value = SessionPersistedObjectAnalyzer.class)
    033public interface SessionPersistedObjectAnalyzer<T>
    034{
    035    /**
    036     * Atomically check and reset the dirty state of the session persisted object.
    037     *
    038     * The implementer should take consideration for the fact that session attributes are accessed concurrently. A
    039     * naive check/set algorithm may allow changes to go un-noticed.
    040     *
    041     * @param sessionPersistedObject the session attribute (never null)
    042     * @return true if the object needs to be re-stored into the session
    043     * @since 5.3
    044     */
    045    boolean checkAndResetDirtyState(T sessionPersistedObject);
    046
    047}