You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/05/05 22:08:37 UTC
svn commit: r1479364 -
/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/Synchronizer.java
Author: oheger
Date: Sun May 5 20:08:37 2013
New Revision: 1479364
URL: http://svn.apache.org/r1479364
Log:
Added Synchronizer interface.
Added:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/Synchronizer.java
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/Synchronizer.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/Synchronizer.java?rev=1479364&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/Synchronizer.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/Synchronizer.java Sun May 5 20:08:37 2013
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration;
+
+/**
+ * <p>
+ * An interface controlling synchronization of configuration instances.
+ * </p>
+ * <p>
+ * Each {@code Configuration} object derived from {@link AbstractConfiguration}
+ * has an associated {@code Synchronizer} object. Before an operation on the
+ * configuration is performed (e.g. a property read or an update), the
+ * {@code Synchronizer} is invoked. Depending on the concrete implementation of
+ * the {@code Synchronizer} used, the configuration can be made thread-safe.
+ * </p>
+ * <p>
+ * Whether a configuration has to be thread-safe or not is a matter of a
+ * concrete use case. For instance, an application that just reads some
+ * configuration settings on startup does need a thread-safe configuration
+ * implementation. A configuration in contrast which is shared between multiple
+ * components and updated concurrently should better be thread-safe. In order to
+ * satisfy both kinds of use cases, the support for thread-safety has been
+ * extracted out of the configuration implementation and refactored into this
+ * {@code Synchronizer} interface. By assigning different {@code Synchronizer}
+ * implementations to a configuration instance, the instance's support for
+ * concurrent access can be adapted to the concrete use case.
+ * </p>
+ * <p>
+ * The methods defined by this interface are similar to a <em>read-write
+ * lock</em>. The {@code Synchronizer} is notified when read or write operations
+ * start and end. A concrete implementation can then apply a specific policy to
+ * decide when threads need to block or when access to the configuration for the
+ * desired operation is granted.
+ * </p>
+ *
+ * @version $Id: $
+ * @since 2.0
+ */
+public interface Synchronizer
+{
+ /**
+ * Notifies this {@code Synchronizer} that the current thread is going to
+ * start a read operation on the managed configuration. This call can block
+ * if a concrete implementation decides that the thread has to wait until a
+ * specific condition is fulfilled.
+ */
+ void beginRead();
+
+ /**
+ * Notifies this {@code Synchronizer} that the current thread has finished
+ * its read operation. This may cause other waiting threads to be granted
+ * access to the managed configuration.
+ */
+ void endRead();
+
+ /**
+ * Notifies this {@code Synchronizer} that the current thread is going to
+ * start a write operation on the managed configuration. This call may
+ * block. For instance, a concrete implementation may suspend the thread
+ * until all read operations currently active are finished,
+ */
+ void beginWrite();
+
+ /**
+ * Notifies this {@code Synchronizer} that the current thread has finished
+ * its write operation. This may cause other waiting threads to be granted
+ * access to the managed configuration.
+ */
+ void endWrite();
+}