[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [ernie/master 2/4] Move initialization code to constructors where it belongs.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Sat, 27 Feb 2010 10:10:02 +0100
Subject: Move initialization code to constructors where it belongs.
Commit: 18cdc091988bf694e002ba66138e653254ceeb3b
---
src/ArchiveReader.java | 7 ---
src/BridgeDescriptorParser.java | 8 ---
src/BridgeSnapshotReader.java | 5 --
src/BridgeStatsFileHandler.java | 86 ++++++++++++++----------------
src/CachedRelayDescriptorReader.java | 7 ---
src/ConsensusStatsFileHandler.java | 100 +++++++++++++++++-----------------
src/DirreqStatsFileHandler.java | 57 +++++++++-----------
src/RelayDescriptorDownloader.java | 7 ---
src/RelayDescriptorParser.java | 44 ++++++---------
src/SanitizedBridgesReader.java | 5 --
10 files changed, 134 insertions(+), 192 deletions(-)
diff --git a/src/ArchiveReader.java b/src/ArchiveReader.java
index a375d9e..1706089 100644
--- a/src/ArchiveReader.java
+++ b/src/ArchiveReader.java
@@ -10,13 +10,6 @@ public class ArchiveReader {
public ArchiveReader(RelayDescriptorParser rdp, String archivesDir) {
Logger logger = Logger.getLogger(ArchiveReader.class.getName());
if (new File(archivesDir).exists()) {
- if (rdp != null) {
- try {
- rdp.initialize();
- } catch (IOException e) {
- return;
- }
- }
logger.info("Importing files in directory " + archivesDir
+ "/...");
Stack<File> filesInInputDir = new Stack<File>();
diff --git a/src/BridgeDescriptorParser.java b/src/BridgeDescriptorParser.java
index 9021e5d..7099571 100644
--- a/src/BridgeDescriptorParser.java
+++ b/src/BridgeDescriptorParser.java
@@ -17,14 +17,6 @@ public class BridgeDescriptorParser {
this.logger =
Logger.getLogger(BridgeDescriptorParser.class.getName());
}
- public void initialize() throws IOException {
- if (this.csfh != null) {
- this.csfh.initialize();
- }
- if (this.bsfh != null) {
- this.bsfh.initialize();
- }
- }
public void parse(BufferedReader br, String dateTime, boolean sanitized)
throws IOException, ParseException {
SimpleDateFormat timeFormat = new SimpleDateFormat(
diff --git a/src/BridgeSnapshotReader.java b/src/BridgeSnapshotReader.java
index 62a314e..1f87b44 100644
--- a/src/BridgeSnapshotReader.java
+++ b/src/BridgeSnapshotReader.java
@@ -38,11 +38,6 @@ public class BridgeSnapshotReader {
return;
}
}
- try {
- bdp.initialize();
- } catch (IOException e) {
- return;
- }
logger.info("Importing files in directory " + bridgeDirectoriesDir
+ "/...");
Stack<File> filesInInputDir = new Stack<File>();
diff --git a/src/BridgeStatsFileHandler.java b/src/BridgeStatsFileHandler.java
index 82fbeb6..fa957e0 100644
--- a/src/BridgeStatsFileHandler.java
+++ b/src/BridgeStatsFileHandler.java
@@ -13,7 +13,6 @@ public class BridgeStatsFileHandler {
private SortedSet<String> countries;
private SortedSet<String> hashedRelays = new TreeSet<String>();
private SortedMap<String, String> observations;
- private boolean initialized;
private boolean hashedRelaysModified;
private boolean observationsModified;
private Logger logger;
@@ -28,75 +27,70 @@ public class BridgeStatsFileHandler {
+ "/hashed-relay-identities");
this.logger =
Logger.getLogger(BridgeStatsFileHandler.class.getName());
- }
- public void initialize() throws IOException {
- if (this.initialized) {
- return;
- }
- this.initialized = true;
if (this.bridgeStatsFile.exists()) {
this.logger.info("Reading file " + statsDir
+ "/bridge-stats-raw...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.bridgeStatsFile));
- String line = br.readLine();
- if (line != null) {
- String[] headers = line.split(",");
- for (int i = 3; i < headers.length; i++) {
- this.countries.add(headers[i]);
- }
- while ((line = br.readLine()) != null) {
- String[] readData = line.split(",");
- String hashedBridgeIdentity = readData[0];
- String date = readData[1];
- String time = readData[2];
- SortedMap<String, String> obs = new TreeMap<String, String>();
- for (int i = 3; i < readData.length; i++) {
- obs.put(headers[i], readData[i]);
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.bridgeStatsFile));
+ String line = br.readLine();
+ if (line != null) {
+ String[] headers = line.split(",");
+ for (int i = 3; i < headers.length; i++) {
+ this.countries.add(headers[i]);
+ }
+ while ((line = br.readLine()) != null) {
+ String[] readData = line.split(",");
+ String hashedBridgeIdentity = readData[0];
+ String date = readData[1];
+ String time = readData[2];
+ SortedMap<String, String> obs = new TreeMap<String, String>();
+ for (int i = 3; i < readData.length; i++) {
+ obs.put(headers[i], readData[i]);
+ }
+ this.addObs(hashedBridgeIdentity, date, time, obs);
}
- this.addObs(hashedBridgeIdentity, date, time, obs);
}
+ br.close();
+ this.observationsModified = false;
+ this.logger.info("Finished reading file " + statsDir
+ + "/bridge-stats-raw.");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file " + statsDir
+ + "/bridge-stats-raw!", e);
}
- br.close();
- this.observationsModified = false;
- this.logger.info("Finished reading file " + statsDir
- + "/bridge-stats-raw.");
}
if (this.hashedRelayIdentitiesFile.exists()) {
this.logger.info("Reading file " + statsDir
+ "/hashed-relay-identities...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.hashedRelayIdentitiesFile));
- String line = null;
- while ((line = br.readLine()) != null) {
- this.hashedRelays.add(line);
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.hashedRelayIdentitiesFile));
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ this.hashedRelays.add(line);
+ }
+ br.close();
+ this.hashedRelaysModified = false;
+ this.logger.info("Finished reading file " + statsDir
+ + "/hashed-relay-identities.");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file " + statsDir
+ + "/hashed-relay-identities!", e);
}
- br.close();
- this.hashedRelaysModified = false;
- this.logger.info("Finished reading file " + statsDir
- + "/hashed-relay-identities.");
}
}
public void addHashedRelay(String hashedRelayIdentity)
throws IOException {
- if (!this.initialized) {
- throw new RuntimeException("Not initialized!");
- }
this.hashedRelays.add(hashedRelayIdentity);
this.hashedRelaysModified = true;
}
public boolean isKnownRelay(String hashedBridgeIdentity)
throws IOException {
- if (!this.initialized) {
- throw new RuntimeException("Not initialized!");
- }
return this.hashedRelays.contains(hashedBridgeIdentity);
}
public void addObs(String hashedIdentity, String date,
String time, Map<String, String> obs) throws IOException {
- if (!this.initialized) {
- throw new RuntimeException("Not initialized!");
- }
String key = hashedIdentity + "," + date;
StringBuilder sb = new StringBuilder(key + "," + time);
for (String c : countries) {
diff --git a/src/CachedRelayDescriptorReader.java b/src/CachedRelayDescriptorReader.java
index ea4d1a7..bf81d44 100644
--- a/src/CachedRelayDescriptorReader.java
+++ b/src/CachedRelayDescriptorReader.java
@@ -17,13 +17,6 @@ public class CachedRelayDescriptorReader {
File cachedDescDir = new File("cacheddesc");
if (cachedDescDir.exists()) {
logger.info("Reading cacheddesc/ directory.");
- if (rdp != null) {
- try {
- rdp.initialize(); // TODO get rid of this non-sense
- } catch (IOException e) {
- return;
- }
- }
for (File f : cachedDescDir.listFiles()) {
try {
// descriptors may contain non-ASCII chars; read as bytes to
diff --git a/src/ConsensusStatsFileHandler.java b/src/ConsensusStatsFileHandler.java
index 27d914e..15f9169 100644
--- a/src/ConsensusStatsFileHandler.java
+++ b/src/ConsensusStatsFileHandler.java
@@ -17,7 +17,6 @@ public class ConsensusStatsFileHandler {
new TreeMap<String, String>();
private SortedMap<String, String> bcsAggr =
new TreeMap<String, String>();
- private boolean initialized;
private boolean consensusResultsModified;
private boolean bridgeConsensusResultsModified;
private Logger logger;
@@ -32,80 +31,83 @@ public class ConsensusStatsFileHandler {
this.consensusStatsFile = new File(statsDir + "/consensus-stats");
this.logger =
Logger.getLogger(ConsensusStatsFileHandler.class.getName());
- }
- public void initialize() throws IOException {
- if (this.initialized) {
- return;
- }
- this.initialized = true;
if (this.consensusStatsRawFile.exists()) {
this.logger.info("Reading file " + statsDir
+ "/consensus-stats-raw...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.consensusStatsRawFile));
- String line = null;
- while ((line = br.readLine()) != null) {
- this.consensusResults.put(line.split(",")[0], line);
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.consensusStatsRawFile));
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ this.consensusResults.put(line.split(",")[0], line);
+ }
+ br.close();
+ this.logger.info("Finished reading file " + statsDir
+ + "/consensus-stats-raw.");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file " + statsDir
+ + "/consensus-stats-raw!", e);
}
- br.close();
- this.logger.info("Finished reading file " + statsDir
- + "/consensus-stats-raw.");
}
if (this.bridgeConsensusStatsRawFile.exists()) {
this.logger.info("Reading file " + statsDir
+ "/bridge-consensus-stats-raw...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.bridgeConsensusStatsRawFile));
- String line = null;
- while ((line = br.readLine()) != null) {
- bridgeConsensusResults.put(line.split(",")[0], line);
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.bridgeConsensusStatsRawFile));
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ bridgeConsensusResults.put(line.split(",")[0], line);
+ }
+ br.close();
+ this.logger.info("Finished reading file " + statsDir
+ + "/bridge-consensus-stats-raw.");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file " + statsDir
+ + "/bridge-consensus-stats-raw!", e);
}
- br.close();
- this.logger.info("Finished reading file " + statsDir
- + "/bridge-consensus-stats-raw.");
}
if (this.consensusStatsFile.exists()) {
this.logger.info("Reading file " + statsDir
+ "/consensus-stats...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.consensusStatsFile));
- String line = br.readLine();
- while ((line = br.readLine()) != null) {
- String[] parts = line.split(",");
- String date = parts[0];
- boolean foundOneNotNA = false;
- for (int i = 1; i < parts.length - 1; i++) {
- if (!parts[i].equals("NA")) {
- foundOneNotNA = true;
- break;
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.consensusStatsFile));
+ String line = br.readLine();
+ while ((line = br.readLine()) != null) {
+ String[] parts = line.split(",");
+ String date = parts[0];
+ boolean foundOneNotNA = false;
+ for (int i = 1; i < parts.length - 1; i++) {
+ if (!parts[i].equals("NA")) {
+ foundOneNotNA = true;
+ break;
+ }
+ }
+ if (foundOneNotNA) {
+ String relays = line.substring(0, line.lastIndexOf(","));
+ String bridges = line.substring(line.lastIndexOf(",") + 1) + "\n";
+ csAggr.put(date, relays);
+ bcsAggr.put(date, bridges);
}
}
- if (foundOneNotNA) {
- String relays = line.substring(0, line.lastIndexOf(","));
- String bridges = line.substring(line.lastIndexOf(",") + 1) + "\n";
- csAggr.put(date, relays);
- bcsAggr.put(date, bridges);
- }
+ br.close();
+ this.logger.info("Finished reading file " + statsDir
+ + "/consensus-stats.");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file " + statsDir
+ + "/consensus-stats.", e);
}
- br.close();
- this.logger.info("Finished reading file " + statsDir
- + "/consensus-stats.");
}
}
public void addConsensusResults(String validAfter, int exit, int fast,
int guard, int running, int stable) throws IOException {
- if (!this.initialized) {
- throw new RuntimeException("Not initialized!");
- }
this.consensusResults.put(validAfter, validAfter + "," + exit + "," + fast
+ "," + guard + "," + running + "," + stable);
this.consensusResultsModified = true;
}
public void addBridgeConsensusResults(String published, int running)
throws IOException {
- if (!this.initialized) {
- throw new RuntimeException("Not initialized!");
- }
bridgeConsensusResults.put(published, published + "," + running);
this.bridgeConsensusResultsModified = true;
}
diff --git a/src/DirreqStatsFileHandler.java b/src/DirreqStatsFileHandler.java
index 84e6eb7..c9eba5e 100644
--- a/src/DirreqStatsFileHandler.java
+++ b/src/DirreqStatsFileHandler.java
@@ -11,7 +11,6 @@ public class DirreqStatsFileHandler {
private SortedSet<String> countries;
private File dirreqStatsFile;
private SortedMap<String, String> observations;
- private boolean initialized;
private boolean modified;
private Logger logger;
public DirreqStatsFileHandler(String statsDir,
@@ -22,46 +21,42 @@ public class DirreqStatsFileHandler {
this.observations = new TreeMap<String, String>();
this.logger =
Logger.getLogger(DirreqStatsFileHandler.class.getName());
- }
- public void initialize() throws IOException {
- if (this.initialized) {
- return;
- }
- this.initialized = true;
if (this.dirreqStatsFile.exists()) {
this.logger.info("Reading file " + statsDir + "/dirreq-stats...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.dirreqStatsFile));
- String line = br.readLine();
- if (line != null) {
- String[] headers = line.split(",");
- for (int i = 2; i < headers.length - 1; i++) {
- this.countries.add(headers[i]);
- }
- while ((line = br.readLine()) != null) {
- String[] readData = line.split(",");
- String dirNickname = readData[0];
- String date = readData[1];
- if (!readData[readData.length - 1].equals("NA")) {
- Map<String, String> obs = new HashMap<String, String>();
- for (int i = 2; i < readData.length - 1; i++) {
- obs.put(headers[i], readData[i]);
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.dirreqStatsFile));
+ String line = br.readLine();
+ if (line != null) {
+ String[] headers = line.split(",");
+ for (int i = 2; i < headers.length - 1; i++) {
+ this.countries.add(headers[i]);
+ }
+ while ((line = br.readLine()) != null) {
+ String[] readData = line.split(",");
+ String dirNickname = readData[0];
+ String date = readData[1];
+ if (!readData[readData.length - 1].equals("NA")) {
+ Map<String, String> obs = new HashMap<String, String>();
+ for (int i = 2; i < readData.length - 1; i++) {
+ obs.put(headers[i], readData[i]);
+ }
+ String share = readData[readData.length - 1];
+ this.addObs(dirNickname, date, obs, share);
}
- String share = readData[readData.length - 1];
- this.addObs(dirNickname, date, obs, share);
}
}
+ br.close();
+ this.logger.info("Finished reading file " + statsDir
+ + "/dirreq-stats...");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file " + statsDir
+ + "/dirreq-stats!", e);
}
- br.close();
- this.logger.info("Finished reading file " + statsDir
- + "/dirreq-stats...");
}
}
public void addObs(String dirNickname, String date,
Map<String, String> obs, String share) throws IOException {
- if (!this.initialized) {
- throw new RuntimeException("Not initialized!");
- }
String obsKey = dirNickname + "," + date;
StringBuilder sb = new StringBuilder(obsKey);
for (String c : this.countries) {
diff --git a/src/RelayDescriptorDownloader.java b/src/RelayDescriptorDownloader.java
index c9e5ceb..4f64820 100644
--- a/src/RelayDescriptorDownloader.java
+++ b/src/RelayDescriptorDownloader.java
@@ -17,13 +17,6 @@ public class RelayDescriptorDownloader {
RelayDescriptorDownloader.class.getName());
List<String> remainingAuthorities =
new ArrayList<String>(authorities);
- if (rdp != null) {
- try {
- rdp.initialize(); // TODO get rid of this non-sense
- } catch (IOException e) {
- return;
- }
- }
Set<String> urls = new HashSet<String>();
Set<String> downloaded = new HashSet<String>();
if (rdp != null) {
diff --git a/src/RelayDescriptorParser.java b/src/RelayDescriptorParser.java
index b17c1e7..b466103 100644
--- a/src/RelayDescriptorParser.java
+++ b/src/RelayDescriptorParser.java
@@ -14,7 +14,6 @@ public class RelayDescriptorParser {
private File relayDescriptorParseHistory;
private SortedMap<String, String> lastParsedExtraInfos;
private String lastParsedConsensus;
- private boolean initialized = false;
private boolean relayDescriptorParseHistoryModified = false;
private DirreqStatsFileHandler dsfh;
private ConsensusStatsFileHandler csfh;
@@ -35,39 +34,30 @@ public class RelayDescriptorParser {
this.countries = countries;
this.directories = directories;
this.logger = Logger.getLogger(RelayDescriptorParser.class.getName());
- }
- public void initialize() throws IOException {
- if (this.initialized) {
- return;
- }
- if (this.csfh != null) {
- this.csfh.initialize();
- }
- if (this.bsfh != null) {
- this.bsfh.initialize();
- }
- if (this.dsfh != null) {
- this.dsfh.initialize();
- }
this.lastParsedConsensus = null;
this.lastParsedExtraInfos = new TreeMap<String, String>();
if (this.relayDescriptorParseHistory.exists()) {
this.logger.info("Reading file " + statsDir
+ "/relay-descriptor-parse-history...");
- BufferedReader br = new BufferedReader(new FileReader(
- this.relayDescriptorParseHistory));
- String line = null;
- while ((line = br.readLine()) != null) {
- if (line.startsWith("consensus")) {
- this.lastParsedConsensus = line.split(",")[2];
- } else if (line.startsWith("extrainfo")) {
- this.lastParsedExtraInfos.put(line.split(",")[1],
- line.split(",")[2]);
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(
+ this.relayDescriptorParseHistory));
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ if (line.startsWith("consensus")) {
+ this.lastParsedConsensus = line.split(",")[2];
+ } else if (line.startsWith("extrainfo")) {
+ this.lastParsedExtraInfos.put(line.split(",")[1],
+ line.split(",")[2]);
+ }
}
+ br.close();
+ this.logger.info("Finished reading file " + statsDir
+ + "/relay-descriptor-parse-history");
+ } catch (IOException e) {
+ this.logger.log(Level.WARNING, "Failed reading file "
+ + statsDir + "/relay-descriptor-parse-history!", e);
}
- br.close();
- this.logger.info("Finished reading file " + statsDir
- + "/relay-descriptor-parse-history");
}
}
public void parse(BufferedReader br) throws IOException {
diff --git a/src/SanitizedBridgesReader.java b/src/SanitizedBridgesReader.java
index 52f4bb4..8c068c2 100644
--- a/src/SanitizedBridgesReader.java
+++ b/src/SanitizedBridgesReader.java
@@ -10,11 +10,6 @@ public class SanitizedBridgesReader {
Logger logger =
Logger.getLogger(SanitizedBridgesReader.class.getName());
if (new File(bridgesDir).exists()) {
- try {
- bdp.initialize();
- } catch (IOException e) {
- return;
- }
logger.info("Importing files in directory " + bridgesDir + "/...");
Stack<File> filesInInputDir = new Stack<File>();
filesInInputDir.add(new File(bridgesDir));
--
1.6.5