|
|
|
@ -53,6 +53,8 @@ import de.anomic.server.serverAbstractSwitch;
|
|
|
|
|
|
|
|
|
|
public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
|
|
|
|
|
private static final long delayBetweenSave = 2000;
|
|
|
|
|
|
|
|
|
|
// configuration management
|
|
|
|
|
private final File configFile;
|
|
|
|
|
private Map configProps;
|
|
|
|
@ -64,6 +66,7 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
private final TreeMap switchActions;
|
|
|
|
|
protected serverLog log;
|
|
|
|
|
protected int serverJobs;
|
|
|
|
|
private long lastTimeSaved;
|
|
|
|
|
|
|
|
|
|
public serverAbstractSwitch(String rootPath, String initPath, String configPath) {
|
|
|
|
|
// we initialize the switchboard with a property file,
|
|
|
|
@ -130,6 +133,9 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
|
|
|
|
|
// init busy state control
|
|
|
|
|
serverJobs = 0;
|
|
|
|
|
|
|
|
|
|
// save control
|
|
|
|
|
lastTimeSaved = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// a logger for this switchboard
|
|
|
|
@ -147,6 +153,7 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
|
|
|
|
|
public void setConfig(String key, String value) {
|
|
|
|
|
// perform action before setting new value
|
|
|
|
|
synchronized (configProps) {
|
|
|
|
|
Map.Entry entry;
|
|
|
|
|
serverSwitchAction action;
|
|
|
|
|
Iterator i = switchActions.entrySet().iterator();
|
|
|
|
@ -176,8 +183,10 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getConfig(String key, String dflt) {
|
|
|
|
|
synchronized (configProps) {
|
|
|
|
|
// get the value
|
|
|
|
|
Object s = configProps.get(key);
|
|
|
|
|
|
|
|
|
@ -196,7 +205,9 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return value
|
|
|
|
|
if (s == null) return dflt; else return (String)s;
|
|
|
|
|
if (s == null) return dflt;
|
|
|
|
|
else return (String) s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getConfigLong(String key, long dflt) {
|
|
|
|
@ -212,11 +223,16 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveConfig() {
|
|
|
|
|
if (System.currentTimeMillis() > this.lastTimeSaved + delayBetweenSave) {
|
|
|
|
|
try {
|
|
|
|
|
synchronized (configProps) {
|
|
|
|
|
serverFileUtils.saveMap(configFile, configProps, configComment);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.out.println("ERROR: cannot write config file " + configFile.toString() + ": " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
this.lastTimeSaved = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map getRemoved() {
|
|
|
|
|