[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Remove some references to DateTimeHelper constants.



commit 1576e9ad60d6bfe08fb9945772c6d239a76ffbce
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri Aug 15 12:05:31 2014 +0200

    Remove some references to DateTimeHelper constants.
---
 .../org/torproject/onionoo/server/NodeIndexer.java |   14 +++++++-----
 .../onionoo/server/PerformanceMetrics.java         |   16 +++++++------
 .../torproject/onionoo/server/ResourceServlet.java |   24 ++++++++++++--------
 .../onionoo/updater/ReverseDomainNameResolver.java |    9 +++-----
 .../java/org/torproject/onionoo/util/Logger.java   |    9 ++++----
 .../onionoo/UptimeDocumentWriterTest.java          |    9 ++++----
 6 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 1cbd75e..bafd442 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -20,7 +20,6 @@ import org.torproject.onionoo.docs.DocumentStore;
 import org.torproject.onionoo.docs.DocumentStoreFactory;
 import org.torproject.onionoo.docs.SummaryDocument;
 import org.torproject.onionoo.docs.UpdateStatus;
-import org.torproject.onionoo.util.DateTimeHelper;
 import org.torproject.onionoo.util.Time;
 import org.torproject.onionoo.util.TimeFactory;
 
@@ -77,11 +76,14 @@ public class NodeIndexer implements ServletContextListener, Runnable {
     }
   }
 
+  private static final long ONE_MINUTE = 60L * 1000L,
+      ONE_DAY = 24L * 60L * ONE_MINUTE;
+
   public void run() {
     while (this.nodeIndexerThread != null) {
       this.indexNodeStatuses();
       try {
-        Thread.sleep(DateTimeHelper.ONE_MINUTE);
+        Thread.sleep(ONE_MINUTE);
       } catch (InterruptedException e) {
       }
     }
@@ -191,7 +193,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
         newRelaysByFamily.put(fingerprint, entry.getFamilyFingerprints());
       }
       int daysSinceFirstSeen = (int) ((time.currentTimeMillis()
-          - entry.getFirstSeenMillis()) / DateTimeHelper.ONE_DAY);
+          - entry.getFirstSeenMillis()) / ONE_DAY);
       if (!newRelaysByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
         newRelaysByFirstSeenDays.put(daysSinceFirstSeen,
             new HashSet<String>());
@@ -200,7 +202,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
       newRelaysByFirstSeenDays.get(daysSinceFirstSeen).add(
           hashedFingerprint);
       int daysSinceLastSeen = (int) ((time.currentTimeMillis()
-          - entry.getLastSeenMillis()) / DateTimeHelper.ONE_DAY);
+          - entry.getLastSeenMillis()) / ONE_DAY);
       if (!newRelaysByLastSeenDays.containsKey(daysSinceLastSeen)) {
         newRelaysByLastSeenDays.put(daysSinceLastSeen,
             new HashSet<String>());
@@ -250,7 +252,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
             hashedHashedFingerprint);
       }
       int daysSinceFirstSeen = (int) ((time.currentTimeMillis()
-          - entry.getFirstSeenMillis()) / DateTimeHelper.ONE_DAY);
+          - entry.getFirstSeenMillis()) / ONE_DAY);
       if (!newBridgesByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
         newBridgesByFirstSeenDays.put(daysSinceFirstSeen,
             new HashSet<String>());
@@ -260,7 +262,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
       newBridgesByFirstSeenDays.get(daysSinceFirstSeen).add(
           hashedHashedFingerprint);
       int daysSinceLastSeen = (int) ((time.currentTimeMillis()
-          - entry.getLastSeenMillis()) / DateTimeHelper.ONE_DAY);
+          - entry.getLastSeenMillis()) / ONE_DAY);
       if (!newBridgesByLastSeenDays.containsKey(daysSinceLastSeen)) {
         newBridgesByLastSeenDays.put(daysSinceLastSeen,
             new HashSet<String>());
diff --git a/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java b/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
index 09a20a2..9d9f3be 100644
--- a/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
+++ b/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
@@ -14,7 +14,6 @@ import java.util.TimeZone;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
-import org.torproject.onionoo.util.DateTimeHelper;
 import org.torproject.onionoo.util.Time;
 import org.torproject.onionoo.util.TimeFactory;
 
@@ -124,7 +123,8 @@ public class PerformanceMetrics {
 
   private static long lastLoggedMillis = -1L;
 
-  private static final long LOG_INTERVAL = DateTimeHelper.ONE_HOUR;
+  private static final long LOG_INTERVAL_SECONDS = 60L * 60L,
+      LOG_INTERVAL_MILLIS = LOG_INTERVAL_SECONDS * 1000L;
 
   private static Counter totalProcessedRequests = new Counter();
 
@@ -151,13 +151,14 @@ public class PerformanceMetrics {
       if (lastLoggedMillis < 0L) {
         lastLoggedMillis = time.currentTimeMillis();
       } else if (receivedRequestMillis - lastLoggedMillis >
-          LOG_INTERVAL) {
+          LOG_INTERVAL_MILLIS) {
         SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
             "yyyy-MM-dd HH:mm:ss");
         dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
         System.err.println("Request statistics ("
-            + dateTimeFormat.format(lastLoggedMillis + LOG_INTERVAL)
-            + ", " + (LOG_INTERVAL / DateTimeHelper.ONE_SECOND) + " s):");
+            + dateTimeFormat.format(lastLoggedMillis
+            + LOG_INTERVAL_MILLIS) + ", " + (LOG_INTERVAL_SECONDS)
+            + " s):");
         System.err.println("  Total processed requests: "
             + totalProcessedRequests);
         System.err.println("  Most frequently requested resource: "
@@ -183,8 +184,9 @@ public class PerformanceMetrics {
         handleRequestMillis.clear();
         buildResponseMillis.clear();
         do {
-          lastLoggedMillis += LOG_INTERVAL;
-        } while (receivedRequestMillis - lastLoggedMillis > LOG_INTERVAL);
+          lastLoggedMillis += LOG_INTERVAL_MILLIS;
+        } while (receivedRequestMillis - lastLoggedMillis >
+            LOG_INTERVAL_MILLIS);
       }
       totalProcessedRequests.increment();
       handleRequestMillis.addLong(parsedRequestMillis
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index 5f22c39..d527962 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -17,7 +17,6 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.torproject.onionoo.util.DateTimeHelper;
 import org.torproject.onionoo.util.Time;
 import org.torproject.onionoo.util.TimeFactory;
 
@@ -35,12 +34,14 @@ public class ResourceServlet extends HttpServlet {
         config.getInitParameter("maintenance").equals("1");
   }
 
+  private static final long INDEX_WAITING_TIME = 10L * 1000L;
+
   public long getLastModified(HttpServletRequest request) {
     if (this.maintenanceMode) {
       return super.getLastModified(request);
     } else {
       return NodeIndexerFactory.getNodeIndexer().getLastIndexed(
-          DateTimeHelper.TEN_SECONDS);
+          INDEX_WAITING_TIME);
     }
   }
 
@@ -53,6 +54,11 @@ public class ResourceServlet extends HttpServlet {
     this.doGet(requestWrapper, responseWrapper);
   }
 
+  private static final long INDEX_MAX_AGE = 6L * 60L * 60L * 1000L,
+      CACHE_MIN_TIME = 5L * 60L * 1000L,
+      CACHE_MAX_TIME = 45L * 60L * 1000L,
+      CACHE_INTERVAL = 5L * 60L * 1000L;
+
   public void doGet(HttpServletRequestWrapper request,
       HttpServletResponseWrapper response) throws IOException {
 
@@ -64,18 +70,18 @@ public class ResourceServlet extends HttpServlet {
     long nowMillis = TimeFactory.getTime().currentTimeMillis();
     long indexWrittenMillis =
         NodeIndexerFactory.getNodeIndexer().getLastIndexed(
-        DateTimeHelper.TEN_SECONDS);
+        INDEX_WAITING_TIME);
     long indexAgeMillis = nowMillis - indexWrittenMillis;
-    if (indexAgeMillis > DateTimeHelper.SIX_HOURS) {
+    if (indexAgeMillis > INDEX_MAX_AGE) {
       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
     }
-    long cacheMaxAgeMillis = Math.max(DateTimeHelper.FIVE_MINUTES,
-        ((DateTimeHelper.FOURTY_FIVE_MINUTES - indexAgeMillis)
-        / DateTimeHelper.FIVE_MINUTES) * DateTimeHelper.FIVE_MINUTES);
+    long cacheMaxAgeMillis = Math.max(CACHE_MIN_TIME,
+        ((CACHE_MAX_TIME - indexAgeMillis)
+        / CACHE_INTERVAL) * CACHE_INTERVAL);
 
     NodeIndex nodeIndex = NodeIndexerFactory.getNodeIndexer().
-        getLatestNodeIndex(DateTimeHelper.TEN_SECONDS);
+        getLatestNodeIndex(INDEX_WAITING_TIME);
     if (nodeIndex == null) {
       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
@@ -311,7 +317,7 @@ public class ResourceServlet extends HttpServlet {
     response.setContentType("application/json");
     response.setCharacterEncoding("utf-8");
     response.setHeader("Cache-Control", "public, max-age="
-        + (cacheMaxAgeMillis / DateTimeHelper.ONE_SECOND));
+        + (cacheMaxAgeMillis / 1000L));
     PrintWriter pw = response.getWriter();
     rb.buildResponse(pw);
     int relayDocumentsWritten = rh.getOrderedRelays().size();
diff --git a/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java b/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java
index 833c900..dc662a5 100644
--- a/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java
+++ b/src/main/java/org/torproject/onionoo/updater/ReverseDomainNameResolver.java
@@ -10,7 +10,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.torproject.onionoo.util.DateTimeHelper;
 import org.torproject.onionoo.util.Logger;
 import org.torproject.onionoo.util.Time;
 import org.torproject.onionoo.util.TimeFactory;
@@ -23,12 +22,10 @@ public class ReverseDomainNameResolver {
     this.time = TimeFactory.getTime();
   }
 
-  static final long RDNS_LOOKUP_MAX_REQUEST_MILLIS =
-      DateTimeHelper.TEN_SECONDS;
-  static final long RDNS_LOOKUP_MAX_DURATION_MILLIS =
-      DateTimeHelper.FIVE_MINUTES;
+  static final long RDNS_LOOKUP_MAX_REQUEST_MILLIS = 10L * 1000L;
+  static final long RDNS_LOOKUP_MAX_DURATION_MILLIS = 5L * 60L * 1000L;
   private static final long RDNS_LOOKUP_MAX_AGE_MILLIS =
-      DateTimeHelper.TWELVE_HOURS;
+      12L * 60L * 60L * 1000L;
   private static final int RDNS_LOOKUP_WORKERS_NUM = 5;
 
   private Map<String, Long> addressLastLookupTimes;
diff --git a/src/main/java/org/torproject/onionoo/util/Logger.java b/src/main/java/org/torproject/onionoo/util/Logger.java
index b85059d..a9c7cde 100644
--- a/src/main/java/org/torproject/onionoo/util/Logger.java
+++ b/src/main/java/org/torproject/onionoo/util/Logger.java
@@ -27,11 +27,12 @@ public class Logger {
     return String.format("%,d", decimalNumber);
   }
 
+  private static final long ONE_SECOND = 1000L,
+      ONE_MINUTE = 60L * ONE_SECOND;
+
   public static String formatMillis(long millis) {
-    return String.format("%02d:%02d.%03d minutes",
-        millis / DateTimeHelper.ONE_MINUTE,
-        (millis % DateTimeHelper.ONE_MINUTE) / DateTimeHelper.ONE_SECOND,
-        millis % DateTimeHelper.ONE_SECOND);
+    return String.format("%02d:%02d.%03d minutes", millis / ONE_MINUTE,
+        (millis % ONE_MINUTE) / ONE_SECOND, millis % ONE_SECOND);
   }
 
   public static String formatBytes(long bytes) {
diff --git a/src/test/java/org/torproject/onionoo/UptimeDocumentWriterTest.java b/src/test/java/org/torproject/onionoo/UptimeDocumentWriterTest.java
index afae0e8..c109859 100644
--- a/src/test/java/org/torproject/onionoo/UptimeDocumentWriterTest.java
+++ b/src/test/java/org/torproject/onionoo/UptimeDocumentWriterTest.java
@@ -75,18 +75,19 @@ public class UptimeDocumentWriterTest {
         GABELMOO_FINGERPRINT);
   }
 
+  private static final long ONE_SECOND = 1000L,
+      ONE_HOUR = 60L * 60L * ONE_SECOND, FOUR_HOURS = 4L * ONE_HOUR;
+
   private void assertOneWeekGraph(UptimeDocument document, int graphs,
       String first, String last, int count, List<Integer> values) {
     this.assertGraph(document, graphs, "1_week", first, last,
-        (int) (DateTimeHelper.ONE_HOUR / DateTimeHelper.ONE_SECOND),
-        count, values);
+        (int) (ONE_HOUR / ONE_SECOND), count, values);
   }
 
   private void assertOneMonthGraph(UptimeDocument document, int graphs,
       String first, String last, int count, List<Integer> values) {
     this.assertGraph(document, graphs, "1_month", first, last,
-        (int) (DateTimeHelper.FOUR_HOURS / DateTimeHelper.ONE_SECOND),
-        count, values);
+        (int) (FOUR_HOURS / ONE_SECOND), count, values);
   }
 
   private void assertGraph(UptimeDocument document, int graphs,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits