]> git.argeo.org Git - lgpl/argeo-commons.git/blob - init/RuntimeManager.java
Prepare next development cycle
[lgpl/argeo-commons.git] / init / RuntimeManager.java
1 package org.argeo.api.init;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.UncheckedIOException;
6 import java.nio.file.Files;
7 import java.nio.file.Path;
8 import java.util.Map;
9 import java.util.Properties;
10 import java.util.function.Consumer;
11
12 /** Dynamically manages multiple runtimes within a single JVM. */
13 public interface RuntimeManager {
14 String JVM_ARGS = "jvm.args";
15 String STATE = "state";
16 String DATA = "data";
17
18 public void startRuntime(String relPath, Consumer<Map<String, String>> configCallback);
19
20 public void closeRuntime(String relPath, boolean async);
21
22 static void loadConfig(Path dir, Map<String, String> config) {
23 try {
24 // System.out.println("Load from " + dir);
25 Path jvmArgsPath = dir.resolve(RuntimeManager.JVM_ARGS);
26 if (!Files.exists(jvmArgsPath)) {
27 // load from parent directory
28 loadConfig(dir.getParent(), config);
29 }
30
31 if (Files.exists(dir))
32 for (Path p : Files.newDirectoryStream(dir, "*.ini")) {
33 Properties props = new Properties();
34 try (InputStream in = Files.newInputStream(p)) {
35 props.load(in);
36 }
37 for (Object key : props.keySet()) {
38 config.put(key.toString(), props.getProperty(key.toString()));
39 }
40 }
41 } catch (IOException e) {
42 throw new UncheckedIOException("Cannot load configuration from " + dir, e);
43 }
44 }
45 }