|
|
|
@ -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();
|
|
|
|
@ -170,14 +177,16 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
entry = (Map.Entry) i.next();
|
|
|
|
|
action = (serverSwitchAction) entry.getValue();
|
|
|
|
|
try {
|
|
|
|
|
action.doAfterSetConfig(key, value, (oldValue==null)?null:(String)oldValue);
|
|
|
|
|
action.doAfterSetConfig(key, value, (oldValue == null) ? null : (String) oldValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.logSevere("serverAction afterSetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getConfig(String key, String dflt) {
|
|
|
|
|
synchronized (configProps) {
|
|
|
|
|
// get the value
|
|
|
|
|
Object s = configProps.get(key);
|
|
|
|
|
|
|
|
|
@ -189,14 +198,16 @@ public abstract class serverAbstractSwitch implements serverSwitch {
|
|
|
|
|
entry = (Map.Entry) i.next();
|
|
|
|
|
action = (serverSwitchAction) entry.getValue();
|
|
|
|
|
try {
|
|
|
|
|
action.doWhenGetConfig(key, (s==null)?null:(String)s, dflt);
|
|
|
|
|
action.doWhenGetConfig(key, (s == null) ? null : (String) s, dflt);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.logSevere("serverAction whenGetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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() {
|
|
|
|
|