    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.sync;
    018
    019/**
    020 * <p>
    021 * An interface controlling synchronization of configuration instances.
    022 * </p>
    023 * <p>
    024 * Each {@code Configuration} object derived from
    025 * {@link org.apache.commons.configuration2.AbstractConfiguration AbstractConfiguration}
    026 * has an associated {@code Synchronizer} object. Before an operation on the
    027 * configuration is performed (e.g. a property read or an update), the
    028 * {@code Synchronizer} is invoked. Depending on the concrete implementation of
    029 * the {@code Synchronizer} used, the configuration can be made thread-safe.
    030 * </p>
    031 * <p>
    032 * Whether a configuration has to be thread-safe or not is a matter of a
    033 * concrete use case. For instance, an application that just reads some
    034 * configuration settings on startup does need a thread-safe configuration
    035 * implementation. A configuration in contrast which is shared between multiple
    036 * components and updated concurrently should better be thread-safe. In order to
    037 * satisfy both kinds of use cases, the support for thread-safety has been
    038 * extracted out of the configuration implementation and refactored into this
    039 * {@code Synchronizer} interface. By assigning different {@code Synchronizer}
    040 * implementations to a configuration instance, the instance's support for
    041 * concurrent access can be adapted to the concrete use case.
    042 * </p>
    043 * <p>
    044 * The methods defined by this interface are similar to a <em>read-write
    045 * lock</em>. The {@code Synchronizer} is notified when read or write operations
    046 * start and end. A concrete implementation can then apply a specific policy to
    047 * decide when threads need to block or when access to the configuration for the
    048 * desired operation is granted.
    049 * </p>
    050 *
    051 * @version $Id: Synchronizer.java 1678634 2015-05-10 20:21:39Z oheger $
    052 * @since 2.0
    053 */
    054public interface Synchronizer
    055{
    056    /**
    057     * Notifies this {@code Synchronizer} that the current thread is going to
    058     * start a read operation on the managed configuration. This call can block
    059     * if a concrete implementation decides that the thread has to wait until a
    060     * specific condition is fulfilled.
    061     */
    062    void beginRead();
    063
    064    /**
    065     * Notifies this {@code Synchronizer} that the current thread has finished
    066     * its read operation. This may cause other waiting threads to be granted
    067     * access to the managed configuration.
    068     */
    069    void endRead();
    070
    071    /**
    072     * Notifies this {@code Synchronizer} that the current thread is going to
    073     * start a write operation on the managed configuration. This call may
    074     * block. For instance, a concrete implementation may suspend the thread
    075     * until all read operations currently active are finished,
    076     */
    077    void beginWrite();
    078
    079    /**
    080     * Notifies this {@code Synchronizer} that the current thread has finished
    081     * its write operation. This may cause other waiting threads to be granted
    082     * access to the managed configuration.
    083     */
    084    void endWrite();
    085}