3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.config;
21 import org.sonews.util.Log;
22 import org.sonews.storage.StorageBackendException;
23 import org.sonews.storage.StorageManager;
24 import org.sonews.util.TimeoutMap;
27 * Provides access to the program wide configuration that is stored within
28 * the server's database.
29 * @author Christian Lins
32 class BackendConfig extends AbstractConfig
35 private static BackendConfig instance = new BackendConfig();
37 public static BackendConfig getInstance()
42 private final TimeoutMap<String, String> values
43 = new TimeoutMap<String, String>();
45 private BackendConfig()
51 * Returns the config value for the given key or the defaultValue if the
52 * key is not found in config.
58 public String get(String key, String defaultValue)
62 String configValue = values.get(key);
63 if(configValue == null)
65 if(StorageManager.current() == null)
67 Log.msg("Warning: BackendConfig not available, using default.", false);
71 configValue = StorageManager.current().getConfigValue(key);
72 if(configValue == null)
78 values.put(key, configValue);
87 catch(StorageBackendException ex)
89 Log.msg(ex.getMessage(), false);
95 * Sets the config value which is identified by the given key.
99 public void set(String key, String value)
101 values.put(key, value);
105 // Write values to database
106 StorageManager.current().setConfigValue(key, value);
108 catch(StorageBackendException ex)
110 ex.printStackTrace();