[tor-commits] [onionoo/master] Split DataWriter interface into two interfaces.
karsten at torproject.org
karsten at torproject.org
Fri Apr 11 07:38:01 UTC 2014
commit 09f83c84dd160d86c75cd4957625aefe1ee5c8ec
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Thu Mar 13 15:35:40 2014 +0100
Split DataWriter interface into two interfaces.
Classes implementing DataWriter perform two tasks: update internal status
files and rewrite output document files. These tasks could also be
performed by two separate classes, and there may be cases when we want to
rewrite output document files using already existing internal status
files. As the first step in splitting up these classes, split the
DataWriter interface into two interfaces StatusUpdater and DocumentWriter.
The current classes that implement DataWriter need to implement the two
new interfaces.
---
.../torproject/onionoo/BandwidthDataWriter.java | 6 +++---
src/org/torproject/onionoo/ClientsDataWriter.java | 6 +++---
src/org/torproject/onionoo/DataWriter.java | 11 -----------
src/org/torproject/onionoo/DocumentWriter.java | 11 +++++++++++
src/org/torproject/onionoo/Main.java | 20 ++++++++++++--------
src/org/torproject/onionoo/NodeDataWriter.java | 6 +++---
src/org/torproject/onionoo/StatusUpdater.java | 11 +++++++++++
src/org/torproject/onionoo/UptimeDataWriter.java | 6 +++---
src/org/torproject/onionoo/WeightsDataWriter.java | 6 +++---
9 files changed, 49 insertions(+), 34 deletions(-)
diff --git a/src/org/torproject/onionoo/BandwidthDataWriter.java b/src/org/torproject/onionoo/BandwidthDataWriter.java
index 67dc427..227df2b 100644
--- a/src/org/torproject/onionoo/BandwidthDataWriter.java
+++ b/src/org/torproject/onionoo/BandwidthDataWriter.java
@@ -35,8 +35,8 @@ import org.torproject.descriptor.ExtraInfoDescriptor;
* last 3 days in the bandwidth document may not be equivalent to the last
* 3 days as of publishing the document, but that's something clients can
* work around. */
-public class BandwidthDataWriter implements DataWriter,
- DescriptorListener, FingerprintListener {
+public class BandwidthDataWriter implements DescriptorListener,
+ StatusUpdater, FingerprintListener, DocumentWriter {
private DescriptorSource descriptorSource;
@@ -88,7 +88,7 @@ public class BandwidthDataWriter implements DataWriter,
/* Status files are already updated while processing descriptors. */
}
- public void updateDocuments() {
+ public void writeDocuments() {
/* Document files are already updated while processing descriptors. */
}
diff --git a/src/org/torproject/onionoo/ClientsDataWriter.java b/src/org/torproject/onionoo/ClientsDataWriter.java
index b045bfa..2ccdff7 100644
--- a/src/org/torproject/onionoo/ClientsDataWriter.java
+++ b/src/org/torproject/onionoo/ClientsDataWriter.java
@@ -51,8 +51,8 @@ import org.torproject.descriptor.ExtraInfoDescriptor;
* "transports":{"obfs2":0.4581},
* "versions":{"v4":1.0000}}
*/
-public class ClientsDataWriter implements DataWriter, DescriptorListener,
- FingerprintListener {
+public class ClientsDataWriter implements DescriptorListener,
+ StatusUpdater, FingerprintListener, DocumentWriter {
private static class ResponseHistory
implements Comparable<ResponseHistory> {
@@ -418,7 +418,7 @@ public class ClientsDataWriter implements DataWriter, DescriptorListener,
private SortedSet<String> updateDocuments = new TreeSet<String>();
- public void updateDocuments() {
+ public void writeDocuments() {
for (String hashedFingerprint : this.updateDocuments) {
SortedSet<ResponseHistory> history =
this.readHistory(hashedFingerprint);
diff --git a/src/org/torproject/onionoo/DataWriter.java b/src/org/torproject/onionoo/DataWriter.java
deleted file mode 100644
index c374153..0000000
--- a/src/org/torproject/onionoo/DataWriter.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.torproject.onionoo;
-
-public interface DataWriter {
-
- public void updateStatuses();
-
- public void updateDocuments();
-
- public String getStatsString();
-}
-
diff --git a/src/org/torproject/onionoo/DocumentWriter.java b/src/org/torproject/onionoo/DocumentWriter.java
new file mode 100644
index 0000000..4cdeef9
--- /dev/null
+++ b/src/org/torproject/onionoo/DocumentWriter.java
@@ -0,0 +1,11 @@
+/* Copyright 2014 The Tor Project
+ * See LICENSE for licensing information */
+package org.torproject.onionoo;
+
+public interface DocumentWriter {
+
+ public abstract void writeDocuments();
+
+ public abstract String getStatsString();
+}
+
diff --git a/src/org/torproject/onionoo/Main.java b/src/org/torproject/onionoo/Main.java
index 5631a5e..abae5cf 100644
--- a/src/org/torproject/onionoo/Main.java
+++ b/src/org/torproject/onionoo/Main.java
@@ -40,7 +40,9 @@ public class Main {
Logger.printStatusTime("Initialized clients data writer");
UptimeDataWriter udw = new UptimeDataWriter(dso, ds, t);
Logger.printStatusTime("Initialized uptime data writer");
- DataWriter[] dws = new DataWriter[] { ndw, bdw, wdw, cdw, udw };
+ StatusUpdater[] sus = new StatusUpdater[] { ndw, bdw, wdw, cdw, udw };
+ DocumentWriter[] dws = new DocumentWriter[] { ndw, bdw, wdw, cdw,
+ udw };
Logger.printStatus("Reading descriptors.");
dso.readRelayNetworkConsensuses();
@@ -61,13 +63,13 @@ public class Main {
Logger.printStatusTime("Read bridge-pool assignments");
Logger.printStatus("Updating internal status files.");
- for (DataWriter dw : dws) {
- dw.updateStatuses();
+ for (StatusUpdater su : sus) {
+ su.updateStatuses();
}
Logger.printStatus("Updating document files.");
- for (DataWriter dw : dws) {
- dw.updateDocuments();
+ for (DocumentWriter dw : dws) {
+ dw.writeDocuments();
}
Logger.printStatus("Shutting down.");
@@ -77,13 +79,15 @@ public class Main {
Logger.printStatusTime("Flushed document cache");
Logger.printStatus("Gathering statistics.");
- for (DataWriter dw : dws) {
- String statsString = dw.getStatsString();
+ for (StatusUpdater su : sus) {
+ String statsString = su.getStatsString();
if (statsString != null) {
- Logger.printStatistics(dw.getClass().getSimpleName(),
+ Logger.printStatistics(su.getClass().getSimpleName(),
statsString);
}
}
+ /* TODO Print status updater statistics once all data writers have
+ * been separated. */
Logger.printStatistics("Descriptor source", dso.getStatsString());
Logger.printStatistics("Document store", ds.getStatsString());
Logger.printStatistics("GeoIP lookup service", ls.getStatsString());
diff --git a/src/org/torproject/onionoo/NodeDataWriter.java b/src/org/torproject/onionoo/NodeDataWriter.java
index b59500a..5941b1c 100644
--- a/src/org/torproject/onionoo/NodeDataWriter.java
+++ b/src/org/torproject/onionoo/NodeDataWriter.java
@@ -33,8 +33,8 @@ import org.torproject.onionoo.LookupService.LookupResult;
* The parts of details files coming from server descriptors always come
* from the last known descriptor of a relay or bridge, not from the
* descriptor that was last referenced in a network status. */
-public class NodeDataWriter implements DataWriter, DescriptorListener,
- FingerprintListener {
+public class NodeDataWriter implements DescriptorListener, StatusUpdater,
+ FingerprintListener, DocumentWriter {
private DescriptorSource descriptorSource;
@@ -148,7 +148,7 @@ public class NodeDataWriter implements DataWriter, DescriptorListener,
Logger.printStatusTime("Wrote out summary");
}
- public void updateDocuments() {
+ public void writeDocuments() {
this.writeOutDetails();
Logger.printStatusTime("Wrote detail data files");
}
diff --git a/src/org/torproject/onionoo/StatusUpdater.java b/src/org/torproject/onionoo/StatusUpdater.java
new file mode 100644
index 0000000..fb82182
--- /dev/null
+++ b/src/org/torproject/onionoo/StatusUpdater.java
@@ -0,0 +1,11 @@
+/* Copyright 2014 The Tor Project
+ * See LICENSE for licensing information */
+package org.torproject.onionoo;
+
+public interface StatusUpdater {
+
+ public abstract void updateStatuses();
+
+ public abstract String getStatsString();
+}
+
diff --git a/src/org/torproject/onionoo/UptimeDataWriter.java b/src/org/torproject/onionoo/UptimeDataWriter.java
index e2b1bee..4692b18 100644
--- a/src/org/torproject/onionoo/UptimeDataWriter.java
+++ b/src/org/torproject/onionoo/UptimeDataWriter.java
@@ -20,8 +20,8 @@ import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.NetworkStatusEntry;
import org.torproject.descriptor.RelayNetworkStatusConsensus;
-public class UptimeDataWriter implements DataWriter, DescriptorListener,
- FingerprintListener {
+public class UptimeDataWriter implements DescriptorListener,
+ StatusUpdater, FingerprintListener, DocumentWriter {
private DescriptorSource descriptorSource;
@@ -305,7 +305,7 @@ public class UptimeDataWriter implements DataWriter, DescriptorListener,
}
}
- public void updateDocuments() {
+ public void writeDocuments() {
SortedSet<UptimeHistory>
knownRelayStatuses = new TreeSet<UptimeHistory>(),
knownBridgeStatuses = new TreeSet<UptimeHistory>();
diff --git a/src/org/torproject/onionoo/WeightsDataWriter.java b/src/org/torproject/onionoo/WeightsDataWriter.java
index 21c3272..d230662 100644
--- a/src/org/torproject/onionoo/WeightsDataWriter.java
+++ b/src/org/torproject/onionoo/WeightsDataWriter.java
@@ -25,8 +25,8 @@ import org.torproject.descriptor.NetworkStatusEntry;
import org.torproject.descriptor.RelayNetworkStatusConsensus;
import org.torproject.descriptor.ServerDescriptor;
-public class WeightsDataWriter implements DataWriter, DescriptorListener,
- FingerprintListener {
+public class WeightsDataWriter implements DescriptorListener,
+ StatusUpdater, FingerprintListener, DocumentWriter {
private DescriptorSource descriptorSource;
@@ -73,7 +73,7 @@ public class WeightsDataWriter implements DataWriter, DescriptorListener,
Logger.printStatusTime("Updated weights status files");
}
- public void updateDocuments() {
+ public void writeDocuments() {
this.writeWeightsDataFiles();
Logger.printStatusTime("Wrote weights document files");
}
More information about the tor-commits
mailing list