Code cleanup.

This commit is contained in:
akwizgran
2016-01-20 10:30:36 +00:00
parent 2216e2b0f2
commit f5f572139a
6 changed files with 31 additions and 59 deletions

View File

@@ -23,14 +23,13 @@ import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.Settings;
import org.briarproject.api.settings.SettingsManager;
import org.briarproject.api.TransportId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.SettingsUpdatedEvent;
import org.briarproject.api.settings.SettingsManager;
import org.briarproject.util.StringUtils;
import java.util.logging.Logger;
@@ -263,8 +262,8 @@ OnClickListener {
runOnDbThread(new Runnable() {
public void run() {
try {
settings = settingsManager.getSettings("settings-activity");
long now = System.currentTimeMillis();
settings = settingsManager.getSettings("settings-activity");
Settings btSettings = settingsManager.getSettings("bt");
Settings torSettings = settingsManager.getSettings("tor");
long duration = System.currentTimeMillis() - now;
@@ -335,7 +334,7 @@ OnClickListener {
if (adapter != null) {
AndroidUtils.setBluetooth(adapter, bluetoothSetting);
}
storeBluetoothSetting();
storeBluetoothSettings();
displaySettings();
} else if (view == torOverWifi || view == torOverWifiHint) {
torSetting = !torSetting;
@@ -385,7 +384,7 @@ OnClickListener {
settingsManager.mergeSettings(s, "tor");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Merging config took " + duration + " ms");
LOG.info("Merging settings took " + duration + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
@@ -394,7 +393,7 @@ OnClickListener {
});
}
private void storeBluetoothSetting() {
private void storeBluetoothSettings() {
runOnDbThread(new Runnable() {
public void run() {
try {
@@ -404,7 +403,7 @@ OnClickListener {
settingsManager.mergeSettings(s, "bt");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Merging config took " + duration + " ms");
LOG.info("Merging settings took " + duration + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);

View File

@@ -190,7 +190,7 @@ public interface DatabaseComponent {
Map<ContactId, TransportProperties> getRemoteProperties(TransportId t)
throws DbException;
/** Returns all settings for a given namespace. */
/** Returns all settings in the given namespace. */
Settings getSettings(String namespace) throws DbException;
/** Returns all contacts who subscribe to the given group. */
@@ -223,7 +223,10 @@ public interface DatabaseComponent {
void mergeLocalProperties(TransportId t, TransportProperties p)
throws DbException;
/** Merges the given settings with the existing settings. */
/**
* Merges the given settings with the existing settings in the given
* namespace.
*/
void mergeSettings(Settings s, String namespace) throws DbException;
/** Processes an ack from the given contact. */

View File

@@ -1,20 +1,16 @@
package org.briarproject.api.settings;
import org.briarproject.api.db.DbException;
import org.briarproject.api.Settings;
import org.briarproject.api.db.DbException;
public interface SettingsManager {
/**
* Returns the settings object identified by the provided namespace
* string
*/
/** Returns all settings in the given namespace. */
Settings getSettings(String namespace) throws DbException;
/**
* Merges (read syncs) the provided settings identified by the provided namespace
* string
*/
* Merges the given settings with the existing settings in the given
* namespace.
*/
void mergeSettings(Settings s, String namespace) throws DbException;
}

View File

@@ -411,7 +411,7 @@ interface Database<T> {
int maxLength) throws DbException;
/**
* Returns all settings that belong to a namespace.
* Returns all settings in the given namespace.
* <p>
* Locking: read.
*/
@@ -526,11 +526,12 @@ interface Database<T> {
throws DbException;
/**
* Merges the given settings with the existing settings.
* Merges the given settings with the existing settings in the given
* namespace.
* <p>
* Locking: write.
*/
void mergeSettings(T txn, Settings s, String Namespace) throws DbException;
void mergeSettings(T txn, Settings s, String namespace) throws DbException;
/**
* Marks a message as needing to be acknowledged to the given contact.

View File

@@ -1,5 +1,6 @@
package org.briarproject.plugins;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties;
import org.briarproject.api.contact.ContactId;
@@ -27,8 +28,6 @@ import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
import org.briarproject.api.property.TransportPropertyManager;
import org.briarproject.api.system.Clock;
import org.briarproject.api.ui.UiCallback;
import org.briarproject.api.Settings;
import org.briarproject.api.settings.SettingsManager;
import java.io.IOException;
import java.util.ArrayList;
@@ -168,9 +167,7 @@ class PluginManagerImpl implements PluginManager {
public void run() {
try {
TransportId id = factory.getId();
String namespace = id.toString();
SimplexCallback callback = new SimplexCallback(id, namespace);
SimplexCallback callback = new SimplexCallback(id);
SimplexPlugin plugin = factory.createPlugin(callback);
if (plugin == null) {
if (LOG.isLoggable(INFO)) {
@@ -233,8 +230,7 @@ class PluginManagerImpl implements PluginManager {
public void run() {
try {
TransportId id = factory.getId();
String namespace = id.toString();
DuplexCallback callback = new DuplexCallback(id, namespace);
DuplexCallback callback = new DuplexCallback(id);
DuplexPlugin plugin = factory.createPlugin(callback);
if (plugin == null) {
if (LOG.isLoggable(INFO)) {
@@ -313,22 +309,18 @@ class PluginManagerImpl implements PluginManager {
private abstract class PluginCallbackImpl implements PluginCallback {
protected final TransportId id;
protected final String namespace;
protected PluginCallbackImpl(TransportId id, String namespace) {
protected PluginCallbackImpl(TransportId id) {
this.id = id;
this.namespace = namespace;
}
public Settings getSettings() {
try {
return db.getSettings(namespace);
return db.getSettings(id.getString());
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
return new Settings();
}
}
public TransportProperties getLocalProperties() {
@@ -352,13 +344,11 @@ class PluginManagerImpl implements PluginManager {
}
public void mergeSettings(Settings s) {
try {
db.mergeSettings(s, namespace);
db.mergeSettings(s, id.getString());
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
}
public void mergeLocalProperties(TransportProperties p) {
@@ -383,7 +373,6 @@ class PluginManagerImpl implements PluginManager {
public void transportEnabled() {
eventBus.broadcast(new TransportEnabledEvent(id));
Plugin p = plugins.get(id);
if (p != null) poller.pollNow(p);
}
@@ -396,8 +385,8 @@ class PluginManagerImpl implements PluginManager {
private class SimplexCallback extends PluginCallbackImpl
implements SimplexPluginCallback {
private SimplexCallback(TransportId id, String namespace) {
super(id, namespace);
private SimplexCallback(TransportId id) {
super(id);
}
public void readerCreated(TransportConnectionReader r) {
@@ -412,8 +401,8 @@ class PluginManagerImpl implements PluginManager {
private class DuplexCallback extends PluginCallbackImpl
implements DuplexPluginCallback {
private DuplexCallback(TransportId id, String namespace) {
super(id, namespace);
private DuplexCallback(TransportId id) {
super(id);
}
public void incomingConnectionCreated(DuplexTransportConnection d) {

View File

@@ -2,43 +2,27 @@ package org.briarproject.settings;
import com.google.inject.Inject;
import org.briarproject.api.settings.SettingsManager;
import org.briarproject.api.Settings;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import java.util.logging.Logger;
import java.util.Collection;
import org.briarproject.api.settings.SettingsManager;
class SettingsManagerImpl implements SettingsManager {
private final DatabaseComponent db;
private static final Logger LOG =
Logger.getLogger("SettingsManagerImpl");
@Inject
SettingsManagerImpl(DatabaseComponent db) {
this.db = db;
}
/**
* Returns the settings object identified by the provided namespace
* string
*/
@Override
public Settings getSettings(String namespace) throws DbException {
return db.getSettings(namespace);
}
/**
* Merges (read syncs) the provided settings identified by the provided namespace
* string
*/
@Override
public void mergeSettings(Settings s, String namespace) throws DbException {
db.mergeSettings(s, namespace);
}
}