Store settings in the DB, listen for events when settings are updated.

This commit is contained in:
akwizgran
2014-03-10 17:59:13 +00:00
parent abaf1d7e96
commit d151633a60
9 changed files with 187 additions and 56 deletions

View File

@@ -0,0 +1,6 @@
package org.briarproject.api;
public class Settings extends StringMap {
private static final long serialVersionUID = 8439364293077111359L;
}

View File

@@ -0,0 +1,29 @@
package org.briarproject.api;
import java.util.Hashtable;
import java.util.Map;
abstract class StringMap extends Hashtable<String, String> {
private static final long serialVersionUID = 2497176435908100448L;
protected StringMap(Map<String, String> m) {
super(m);
}
protected StringMap() {
super();
}
public boolean getBoolean(String key, boolean defaultValue) {
String s = get(key);
if(s == null) return defaultValue;
if("true".equals(s)) return true;
if("false".equals(s)) return false;
return defaultValue;
}
public void putBoolean(String key, boolean value) {
put(key, String.valueOf(value));
}
}

View File

@@ -1,15 +1,16 @@
package org.briarproject.api;
import java.util.Hashtable;
import java.util.Map;
public class TransportConfig extends Hashtable<String, String> {
public class TransportConfig extends StringMap {
private static final long serialVersionUID = 2330384620787778596L;
public TransportConfig(Map<String, String> c) {
super(c);
public TransportConfig(Map<String, String> m) {
super(m);
}
public TransportConfig() {}
public TransportConfig() {
super();
}
}

View File

@@ -1,15 +1,16 @@
package org.briarproject.api;
import java.util.Hashtable;
import java.util.Map;
public class TransportProperties extends Hashtable<String, String> {
public class TransportProperties extends StringMap {
private static final long serialVersionUID = 7533739534204953625L;
public TransportProperties(Map<String, String> p) {
super(p);
public TransportProperties(Map<String, String> m) {
super(m);
}
public TransportProperties() {}
public TransportProperties() {
super();
}
}

View File

@@ -9,6 +9,7 @@ import org.briarproject.api.AuthorId;
import org.briarproject.api.Contact;
import org.briarproject.api.ContactId;
import org.briarproject.api.LocalAuthor;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties;
@@ -233,6 +234,9 @@ public interface DatabaseComponent {
/** Returns all temporary secrets. */
Collection<TemporarySecret> getSecrets() throws DbException;
/** Returns all settings. */
Settings getSettings() throws DbException;
/** Returns the maximum latencies of all local transports. */
Map<TransportId, Long> getTransportLatencies() throws DbException;
@@ -263,6 +267,9 @@ public interface DatabaseComponent {
void mergeLocalProperties(TransportId t, TransportProperties p)
throws DbException;
/** Merges the given settings with the existing settings. */
void mergeSettings(Settings s) throws DbException;
/** Processes an ack from the given contact. */
void receiveAck(ContactId c, Ack a) throws DbException;

View File

@@ -0,0 +1,6 @@
package org.briarproject.api.event;
/** An event that is broadcast when one or more settings are updated. */
public class SettingsUpdatedEvent extends Event {
}