Skip to content

Commit

Permalink
Refactored configuration, restructured "segments" and renamed to "zon…
Browse files Browse the repository at this point in the history
…es".
  • Loading branch information
nmihajlovski committed Aug 19, 2016
1 parent 0ed0580 commit 859bb6c
Show file tree
Hide file tree
Showing 26 changed files with 656 additions and 409 deletions.
@@ -0,0 +1,38 @@
package org.rapidoid.config;

/*
* #%L
* rapidoid-commons
* %%
* Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors
* %%
* Licensed 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.
* #L%
*/

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.lambda.ToMap;
import org.rapidoid.value.Value;

@Authors("Nikolche Mihajlovski")
@Since("5.2.0")
public interface BasicConfig extends ToMap<String, Object> {

Value<Object> entry(String key);

boolean has(String key);

BasicConfig sub(String... keys);

}
26 changes: 17 additions & 9 deletions rapidoid-commons/src/main/java/org/rapidoid/config/Conf.java
Expand Up @@ -46,7 +46,7 @@ public Config map(String name) throws Exception {
} }
}); });


public static final Config ROOT = new Config(); public static final Config ROOT = new ConfigImpl();


public static final Config USERS = section("users"); public static final Config USERS = section("users");
public static final Config JOBS = section("jobs"); public static final Config JOBS = section("jobs");
Expand Down Expand Up @@ -160,16 +160,20 @@ public static synchronized void reload() {


ROOT.clear(); ROOT.clear();


loadDefaultConfig();

loadConfig(detached);

ROOT.args(args);

applyConfig();
}

public static void loadConfig(List<List<String>> detached) {
String filenameBase = U.or(ROOT.filenameBase(), "config"); String filenameBase = U.or(ROOT.filenameBase(), "config");
String configFilenamePattern = filenameBase + ".y?ml"; String configFilenamePattern = filenameBase + ".y?ml";
String configProfilePattern = filenameBase + "-%s.y?ml"; String configProfilePattern = filenameBase + "-%s.y?ml";


ConfigUtil.load(Msc.path("default", configFilenamePattern), ROOT, true);

for (String profile : Env.profiles()) {
ConfigUtil.load(Msc.path("default", U.frmt(configProfilePattern, profile)), ROOT, true);
}

ConfigUtil.load(Msc.path(path, configFilenamePattern), ROOT, false); ConfigUtil.load(Msc.path(path, configFilenamePattern), ROOT, false);


for (String profile : Env.profiles()) { for (String profile : Env.profiles()) {
Expand All @@ -179,10 +183,14 @@ public static synchronized void reload() {
for (List<String> keys : detached) { for (List<String> keys : detached) {
autoRefresh(keys.isEmpty() ? ROOT : ROOT.sub(keys)); autoRefresh(keys.isEmpty() ? ROOT : ROOT.sub(keys));
} }
}


ROOT.args(args); public static void loadDefaultConfig() {
ConfigUtil.load("default-config.yml", ROOT, true);


applyConfig(); for (String profile : Env.profiles()) {
ConfigUtil.load(U.frmt("default-config-%s.yml", profile), ROOT, true);
}
} }


private static void autoRefresh(Config... configs) { private static void autoRefresh(Config... configs) {
Expand Down

0 comments on commit 859bb6c

Please sign in to comment.