001//  Copyright 2013 The Apache Software Foundation
002//
003//  Licensed under the Apache License, Version 2.0 (the "License");
004//  you may not use this file except in compliance with the License.
005//  You may obtain a copy of the License at
006//
007//  http://www.apache.org/licenses/LICENSE-2.0
008//
009//  Unless required by applicable law or agreed to in writing, software
010//  distributed under the License is distributed on an "AS IS" BASIS,
011//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012//  See the License for the specific language governing permissions and
013//  limitations under the License.
014
015package org.apache.tapestry5.http.internal.services;
016
017/**
018 * A wrapper around {@link java.util.concurrent.locks.ReentrantReadWriteLock} used to manage the lock for a session.
019 * Once a lock is acquired, a callback is registered with the {@link org.apache.tapestry5.ioc.services.PerthreadManager}
020 * to release the lock at the end of the request.
021 *
022 * @since 5.4
023 */
024public interface SessionLock
025{
026    /**
027     * Acquires the read lock, if the shared read lock, or exclusive write lock, is not already held by this thread.
028     */
029    void acquireReadLock();
030
031    /**
032     * Acquires the exclusive write lock; may release the (shared) read lock before acquiring the write lock;
033     * this may block for a while. Does nothing if the write lock is already held by this thread.
034     */
035    void acquireWriteLock();
036}