From c1418a1c2ed1923d91f269ce99a872f294d1f095 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Mon, 24 Jun 2019 14:23:33 +0000
Subject: [PATCH] StatManager cleanup and synch BuildTime update Make
 clock.skew stat non-required

---
 core/java/src/net/i2p/stat/StatManager.java   | 56 ++++++++++++-------
 core/java/src/net/i2p/time/BuildTime.java     |  4 +-
 core/java/src/net/i2p/util/Clock.java         |  2 +-
 .../java/src/net/i2p/router/RouterClock.java  |  2 +-
 4 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/core/java/src/net/i2p/stat/StatManager.java b/core/java/src/net/i2p/stat/StatManager.java
index 7f6d9859b6..b68b867106 100644
--- a/core/java/src/net/i2p/stat/StatManager.java
+++ b/core/java/src/net/i2p/stat/StatManager.java
@@ -30,6 +30,11 @@ public class StatManager {
     /** may be null */
     private StatLog _statLog;
 
+    private int coalesceCounter;
+    /** every this many minutes for frequencies */
+    private static final int FREQ_COALESCE_RATE = 9;
+
+
     /**
      *  Comma-separated stats or * for all.
      *  This property must be set at startup, or
@@ -47,7 +52,7 @@ public class StatManager {
      * appropriate application context itself.
      *
      */
-	public StatManager(I2PAppContext context) {
+    public StatManager(I2PAppContext context) {
         _context = context;
         _frequencyStats = new ConcurrentHashMap<String,FrequencyStat>(8);
         _rateStats = new ConcurrentHashMap<String,RateStat>(128);
@@ -57,18 +62,29 @@ public class StatManager {
     }
     
     /** @since 0.8.8 */
-    public void shutdown() {
+    public synchronized void shutdown() {
         _frequencyStats.clear();
         _rateStats.clear();
     }
 
-    /** may be null */
-    public StatLog getStatLog() { return _statLog; }
-    public void setStatLog(StatLog log) { 
+    /**
+     *  Gets the default stat log for RateStats
+     *  Deprecated, unused
+     *  @return null always
+     */
+    public synchronized StatLog getStatLog() { return _statLog; }
+
+    /**
+     *  Sets the default stat log for ALL known RateStats.
+     *  Deprecated, unused
+     *  @deprecated unused
+     */
+    @Deprecated
+    public synchronized void setStatLog(StatLog log) { 
         _statLog = log; 
-            for (RateStat rs : _rateStats.values()) {
-                rs.setStatLog(log);
-            }
+        for (RateStat rs : _rateStats.values()) {
+            rs.setStatLog(log);
+        }
     }
 
     /**
@@ -158,11 +174,7 @@ public class StatManager {
         if (stat != null) stat.addData(data);
     }
 
-    private int coalesceCounter;
-    /** every this many minutes for frequencies */
-    private static final int FREQ_COALESCE_RATE = 9;
-
-    public void coalesceStats() {
+    public synchronized void coalesceStats() {
         if (++coalesceCounter % FREQ_COALESCE_RATE == 0) {
                 for (FrequencyStat stat : _frequencyStats.values()) {
                     if (stat != null) {
@@ -170,15 +182,13 @@ public class StatManager {
                     }
                 }
         }
-            for (RateStat stat : _rateStats.values()) {
-                if (stat != null) {
-                    stat.coalesceStats();
-                }
-            }
+        for (RateStat stat : _rateStats.values()) {
+            stat.coalesceStats();
+        }
     }
 
     /**
-     *  Misnamed, as it returns a FrequenceyStat, not a Frequency.
+     *  Misnamed, as it returns a FrequencyStat, not a Frequency.
      */
     public FrequencyStat getFrequency(String name) {
         return _frequencyStats.get(name);
@@ -191,10 +201,12 @@ public class StatManager {
         return _rateStats.get(name);
     }
 
+    /** @return a copy */
     public Set<String> getFrequencyNames() {
         return new HashSet<String>(_frequencyStats.keySet());
     }
 
+    /** @return a copy */
     public Set<String> getRateNames() {
         return new HashSet<String>(_rateStats.keySet());
     }
@@ -258,9 +270,11 @@ public class StatManager {
      * @since 0.9.23
      */
     public void store(OutputStream out, String prefix) throws IOException {
-        for (FrequencyStat fs : _frequencyStats.values())
+        for (FrequencyStat fs : _frequencyStats.values()) {
             fs.store(out, prefix);
-        for (RateStat rs : _rateStats.values())
+        }
+        for (RateStat rs : _rateStats.values()) {
             rs.store(out,prefix);
+        }
     }
 }
diff --git a/core/java/src/net/i2p/time/BuildTime.java b/core/java/src/net/i2p/time/BuildTime.java
index 9ee7f70ea2..8697a66906 100644
--- a/core/java/src/net/i2p/time/BuildTime.java
+++ b/core/java/src/net/i2p/time/BuildTime.java
@@ -34,10 +34,10 @@ public class BuildTime {
     private static final long _latestTime;
     private static final long YEARS_25 = 25L*365*24*60*60*1000;
     /** update this periodically */
-    private static final String EARLIEST = "2019-03-13 12:00:00 UTC";
+    private static final String EARLIEST = "2019-06-23 12:00:00 UTC";
     // fallback if parse fails ticket #1976
     // date -d 201x-xx-xx +%s
-    private static final long EARLIEST_LONG = 1552449600 * 1000L;
+    private static final long EARLIEST_LONG = 1561262400 * 1000L;
 
     static {
         // this is the standard format of build.timestamp as set in the top-level build.xml
diff --git a/core/java/src/net/i2p/util/Clock.java b/core/java/src/net/i2p/util/Clock.java
index 537f4685dd..30523c9b85 100644
--- a/core/java/src/net/i2p/util/Clock.java
+++ b/core/java/src/net/i2p/util/Clock.java
@@ -128,7 +128,7 @@ public class Clock implements Timestamper.UpdateListener {
                 getLog().info("Updating clock offset to " + offsetMs + "ms from " + _offset + "ms");
             
             if (!_statCreated) {
-                _context.statManager().createRequiredRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*1000 });
+                _context.statManager().createRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 60*60*1000 });
                 _statCreated = true;
             }
             _context.statManager().addRateData("clock.skew", delta, 0);
diff --git a/router/java/src/net/i2p/router/RouterClock.java b/router/java/src/net/i2p/router/RouterClock.java
index a0932c7d0a..4f3dc9c9a3 100644
--- a/router/java/src/net/i2p/router/RouterClock.java
+++ b/router/java/src/net/i2p/router/RouterClock.java
@@ -189,7 +189,7 @@ public class RouterClock extends Clock {
                 getLog().info("Updating target clock offset to " + offsetMs + "ms from " + _offset + "ms, Stratum " + stratum);
             
             if (!_statCreated) {
-                _context.statManager().createRequiredRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*1000 });
+                _context.statManager().createRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 60*60*1000 });
                 _statCreated = true;
             }
             _context.statManager().addRateData("clock.skew", delta);
-- 
GitLab