* load clientApp.* lines from clients.config by default, falling back on
reading the router's props only if that file doesn't exist. * by default, only log CRIT messages to the screen (the rest are sent to the log file). this will be useful with the upcoming service controller * refactor a common Properties helper to DataHelper.loadProps
This commit is contained in:
@ -183,10 +183,9 @@ public class Router {
|
||||
try {
|
||||
File f = new File(filename);
|
||||
if (f.canRead()) {
|
||||
fis = new FileInputStream(f);
|
||||
props.load(fis);
|
||||
DataHelper.loadProps(props, f);
|
||||
} else {
|
||||
log.error("Configuration file " + filename + " does not exist");
|
||||
log.warn("Configuration file " + filename + " does not exist");
|
||||
}
|
||||
} catch (Exception ioe) {
|
||||
log.error("Error loading the router configuration from " + filename, ioe);
|
||||
|
@ -15,6 +15,7 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
@ -212,26 +213,11 @@ class ProfilePersistenceHelper {
|
||||
}
|
||||
|
||||
private void loadProps(Properties props, File file) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new InputStreamReader(new FileInputStream(file)), 16*1024);
|
||||
String line = null;
|
||||
while ( (line = in.readLine()) != null) {
|
||||
if (line.trim().length() <= 0) continue;
|
||||
if (line.charAt(0) == '#') continue;
|
||||
int split = line.indexOf('=');
|
||||
if (split <= 0) continue;
|
||||
String key = line.substring(0, split);
|
||||
String val = line.substring(split+1);
|
||||
if ( (key.length() > 0) && (val.length() > 0) )
|
||||
props.setProperty(key, val);
|
||||
}
|
||||
DataHelper.loadProps(props, file);
|
||||
} catch (IOException ioe) {
|
||||
_log.warn("Error loading properties from " + file.getName(), ioe);
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Hash getHash(String name) {
|
||||
|
@ -1,9 +1,13 @@
|
||||
package net.i2p.router.startup;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.I2PThread;
|
||||
@ -19,17 +23,22 @@ class LoadClientAppsJob extends JobImpl {
|
||||
private Log _log;
|
||||
/** wait 2 minutes before starting up client apps */
|
||||
private final static long STARTUP_DELAY = 2*60*1000;
|
||||
|
||||
private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile";
|
||||
private static final String DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config";
|
||||
|
||||
public LoadClientAppsJob(RouterContext ctx) {
|
||||
super(ctx);
|
||||
_log = ctx.logManager().getLog(LoadClientAppsJob.class);
|
||||
}
|
||||
public void runJob() {
|
||||
Properties clientApps = getClientApps();
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String className = getContext().router().getConfigSetting("clientApp."+i+".main");
|
||||
String clientName = getContext().router().getConfigSetting("clientApp."+i+".name");
|
||||
String args = getContext().router().getConfigSetting("clientApp."+i+".args");
|
||||
String onBoot = getContext().router().getConfigSetting("clientApp." + i + ".onBoot");
|
||||
String className = clientApps.getProperty("clientApp."+i+".main");
|
||||
String clientName = clientApps.getProperty("clientApp."+i+".name");
|
||||
String args = clientApps.getProperty("clientApp."+i+".args");
|
||||
String onBoot = clientApps.getProperty("clientApp." + i + ".onBoot");
|
||||
boolean onStartup = false;
|
||||
if (onBoot != null)
|
||||
onStartup = "true".equals(onBoot) || "yes".equals(onBoot);
|
||||
@ -49,6 +58,24 @@ class LoadClientAppsJob extends JobImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private Properties getClientApps() {
|
||||
Properties rv = new Properties();
|
||||
String clientConfigFile = getContext().getProperty(PROP_CLIENT_CONFIG_FILENAME, DEFAULT_CLIENT_CONFIG_FILENAME);
|
||||
File cfgFile = new File(clientConfigFile);
|
||||
|
||||
// fall back to use router.config's clientApp.* lines
|
||||
if (!cfgFile.exists())
|
||||
return new Properties(getContext().router().getConfigMap());
|
||||
|
||||
try {
|
||||
DataHelper.loadProps(rv, cfgFile);
|
||||
} catch (IOException ioe) {
|
||||
_log.warn("Error loading the client app properties from " + cfgFile.getName(), ioe);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
private class DelayedRunClient extends JobImpl {
|
||||
private String _className;
|
||||
private String _clientName;
|
||||
|
Reference in New Issue
Block a user