From 419d6a8e186c467a4cb513e29b7cb757ec5c5d7e Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 8 Oct 2015 13:42:31 +0000 Subject: [PATCH] SimpleTimer2: Additional fix for uncaught IllegalStateException affecting streaming timers (ticket #1672) Minor streaming cleanup --- .../i2p/client/streaming/impl/Connection.java | 4 ++- core/java/src/net/i2p/util/SimpleTimer2.java | 25 +++++++++++++------ history.txt | 12 +++++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java b/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java index f5e93ddf0..478afcdb8 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java @@ -1311,7 +1311,9 @@ class Connection { } public long getNextSendTime() { return _nextSend; } + public void timeReached() { retransmit(); } + /** * Retransmit the packet if we need to. * @@ -1323,7 +1325,7 @@ class Connection { * * @return true if the packet was sent, false if it was not */ - public boolean retransmit() { + private boolean retransmit() { if (_packet.getAckTime() > 0) return false; diff --git a/core/java/src/net/i2p/util/SimpleTimer2.java b/core/java/src/net/i2p/util/SimpleTimer2.java index fa803338c..aff0b61f6 100644 --- a/core/java/src/net/i2p/util/SimpleTimer2.java +++ b/core/java/src/net/i2p/util/SimpleTimer2.java @@ -257,6 +257,8 @@ public class SimpleTimer2 { private long _nextRun; /** whether this was scheduled during RUNNING state. LOCKING: this */ private boolean _rescheduleAfterRun; + /** whether this was cancelled during RUNNING state. LOCKING: this */ + private boolean _cancelAfterRun; /** must call schedule() later */ public TimedEvent(SimpleTimer2 pool) { @@ -290,7 +292,8 @@ public class SimpleTimer2 { if (_log.shouldLog(Log.DEBUG)) _log.debug("Scheduling: " + this + " timeout = " + timeoutMs + " state: " + _state); if (timeoutMs <= 0) { - if (_log.shouldLog(Log.WARN)) + // streaming timers do call with timeoutMs == 0 + if (timeoutMs < 0 && _log.shouldLog(Log.WARN)) _log.warn("Timeout <= 0: " + this + " timeout = " + timeoutMs + " state: " + _state); timeoutMs = 1; // otherwise we may execute before _future is updated, which is fine // except it triggers 'early execution' warning logging @@ -298,6 +301,7 @@ public class SimpleTimer2 { // always set absolute time of execution _nextRun = timeoutMs + System.currentTimeMillis(); + _cancelAfterRun = false; switch(_state) { case RUNNING: @@ -373,7 +377,9 @@ public class SimpleTimer2 { case CANCELLED: // fall through case IDLE: break; // my preference is to throw IllegalState here, but let it be. - case RUNNING: // fall through + case RUNNING: + _cancelAfterRun = true; + return true; case SCHEDULED: boolean cancelled = _future.cancel(false); if (cancelled) @@ -447,11 +453,16 @@ public class SimpleTimer2 { case CANCELLED: break; // nothing case RUNNING: - _state = TimedEventState.IDLE; - // do we need to reschedule? - if (_rescheduleAfterRun) { - _rescheduleAfterRun = false; - schedule(_nextRun - System.currentTimeMillis()); + if (_cancelAfterRun) { + _cancelAfterRun = false; + _state = TimedEventState.CANCELLED; + } else { + _state = TimedEventState.IDLE; + // do we need to reschedule? + if (_rescheduleAfterRun) { + _rescheduleAfterRun = false; + schedule(_nextRun - System.currentTimeMillis()); + } } } } diff --git a/history.txt b/history.txt index fc5a07713..bd4cde9e3 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,15 @@ +2015-10-08 zzz + * SimpleTimer2: Additional fix for uncaught IllegalStateException + affecting streaming timers (ticket #1672) + +2015-10-02 zzz + * Router: Don't check config files for reload on Android + +2015-09-28 zzz + * Addressbook: Fix isValidDest() for EC/Ed dests + * i2psnark: Support adding plain base 32 hashes + * Susimail: Hide headers and buttons if search results are empty + 2015-09-27 dg * Router: Fix soft restarts for 'massive' clock jumps (over +150s or -61s) and recover from standby and hibernate (ticket #1014). diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 31c35f8c3..ea17ad55f 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 14; + public final static long BUILD = 15; /** for example "-test" */ public final static String EXTRA = "";