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.configuration; 018 019import org.apache.commons.configuration.reloading.Reloadable; 020 021/** 022 * <p>A base class for hierarchical configurations with specific reloading 023 * requirements.</p> 024 * <p>This class manages a lock object which can be used for synchronization.</p> 025 * 026 * @author <a 027 * href="http://commons.apache.org/configuration/team-list.html">Commons 028 * Configuration team</a> 029 * @since 1.7 030 * @version $Id: HierarchicalReloadableConfiguration.java 1210000 2011-12-03 20:43:38Z oheger $ 031 */ 032public class HierarchicalReloadableConfiguration extends HierarchicalConfiguration 033 implements Reloadable 034{ 035 /** Constant for the name used for the lock object. */ 036 private static final String LOCK_NAME = "HierarchicalReloadableConfigurationLock"; 037 038 /** The lock object used by this instance. */ 039 private final Object reloadLock; 040 041 /** 042 * Creates a new instance of {@code HierarchicalReloadableConfiguration}. 043 */ 044 public HierarchicalReloadableConfiguration() 045 { 046 super(); 047 reloadLock = new Lock(LOCK_NAME); 048 } 049 050 /** 051 * Creates a new instance of {@code HierarchicalReloadableConfiguration} and 052 * initializes it with the given lock object. 053 * 054 * @param lock the lock object 055 */ 056 public HierarchicalReloadableConfiguration(Object lock) 057 { 058 super(); 059 reloadLock = lock == null ? new Lock(LOCK_NAME) : lock; 060 } 061 062 /** 063 * Creates a new instance of {@code HierarchicalReloadableConfiguration} and 064 * copies all data contained in the specified configuration into the new 065 * one. 066 * 067 * @param c the configuration that is to be copied (if <b>null</b>, this 068 * constructor will behave like the standard constructor) 069 */ 070 public HierarchicalReloadableConfiguration(HierarchicalConfiguration c) 071 { 072 super(c); 073 reloadLock = new Lock(LOCK_NAME); 074 } 075 076 @Override 077 public Object getReloadLock() 078 { 079 return reloadLock; 080 } 081}