]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - argeo/api/init/RuntimeManager.java
1 package org
.argeo
.api
.init
;
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
;
9 import java
.util
.Properties
;
10 import java
.util
.function
.Consumer
;
12 /** Dynamically manages multiple runtimes within a single JVM. */
13 public interface RuntimeManager
{
14 String JVM_ARGS
= "jvm.args";
15 String STATE
= "state";
18 public void startRuntime(String relPath
, Consumer
<Map
<String
, String
>> configCallback
);
20 public void closeRuntime(String relPath
, boolean async
);
22 static void loadConfig(Path dir
, Map
<String
, String
> config
) {
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
);
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
)) {
37 for (Object key
: props
.keySet()) {
38 config
.put(key
.toString(), props
.getProperty(key
.toString()));
41 } catch (IOException e
) {
42 throw new UncheckedIOException("Cannot load configuration from " + dir
, e
);