forked from I2P_Developers/i2p.i2p
SimpleTimer (ticket #653):
- Move all remaining uses to SimpleTimer2
- Deprecate
This commit is contained in:
@@ -953,6 +953,7 @@ public class I2PAppContext {
|
||||
/**
|
||||
* Use instead of SimpleTimer.getInstance()
|
||||
* @since 0.9 to replace static instance in the class
|
||||
* @deprecated use SimpleTimer2
|
||||
*/
|
||||
public SimpleTimer simpleTimer() {
|
||||
if (!_simpleTimerInitialized)
|
||||
@@ -960,6 +961,9 @@ public class I2PAppContext {
|
||||
return _simpleTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use SimpleTimer2
|
||||
*/
|
||||
private void initializeSimpleTimer() {
|
||||
synchronized (_lock19) {
|
||||
if (_simpleTimer == null)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package net.i2p.util;
|
||||
|
||||
/**
|
||||
* Deprecated - used only by SimpleTimer
|
||||
*
|
||||
* @author sponge
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ public class SimpleTimer {
|
||||
|
||||
/**
|
||||
* If you have a context, use context.simpleTimer() instead
|
||||
* @deprecated use SimpleTimer2
|
||||
*/
|
||||
public static SimpleTimer getInstance() {
|
||||
return I2PAppContext.getGlobalContext().simpleTimer();
|
||||
@@ -39,6 +40,7 @@ public class SimpleTimer {
|
||||
/**
|
||||
* To be instantiated by the context.
|
||||
* Others should use context.simpleTimer() instead
|
||||
* @deprecated use SimpleTimer2
|
||||
*/
|
||||
public SimpleTimer(I2PAppContext context) {
|
||||
this(context, "SimpleTimer");
|
||||
@@ -47,6 +49,7 @@ public class SimpleTimer {
|
||||
/**
|
||||
* To be instantiated by the context.
|
||||
* Others should use context.simpleTimer() instead
|
||||
* @deprecated use SimpleTimer2
|
||||
*/
|
||||
private SimpleTimer(I2PAppContext context, String name) {
|
||||
runn = new SimpleStore(true);
|
||||
@@ -146,6 +149,7 @@ public class SimpleTimer {
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME if you plan to use this class again
|
||||
while (_events.containsKey(time))
|
||||
time = new Long(time.longValue() + 1);
|
||||
_events.put(time, event);
|
||||
|
||||
@@ -205,10 +205,8 @@ public class SimpleTimer2 {
|
||||
}
|
||||
|
||||
/**
|
||||
* More efficient than reschedule().
|
||||
* Only call this after calling the non-scheduling constructor,
|
||||
* or from within timeReached(), or you will get duplicates on the queue.
|
||||
* Otherwise use reschedule().
|
||||
* Slightly more efficient than reschedule().
|
||||
* Does nothing if already scheduled.
|
||||
*/
|
||||
public synchronized void schedule(long timeoutMs) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
@@ -236,7 +234,8 @@ public class SimpleTimer2 {
|
||||
|
||||
/**
|
||||
* Use the earliest of the new time and the old time
|
||||
* Do not call from within timeReached()
|
||||
* May be called from within timeReached(), but schedule() is
|
||||
* better there.
|
||||
*
|
||||
* @param timeoutMs
|
||||
*/
|
||||
@@ -245,8 +244,8 @@ public class SimpleTimer2 {
|
||||
}
|
||||
|
||||
/**
|
||||
* useEarliestTime must be false if called from within timeReached(), as
|
||||
* it won't be rescheduled, in favor of the currently running task
|
||||
* May be called from within timeReached(), but schedule() is
|
||||
* better there.
|
||||
*
|
||||
* @param timeoutMs
|
||||
* @param useEarliestTime if its already scheduled, use the earlier of the
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Date;
|
||||
*
|
||||
* Use socket.setsotimeout instead?
|
||||
*/
|
||||
public class SocketTimeout implements SimpleTimer.TimedEvent {
|
||||
public class SocketTimeout extends SimpleTimer2.TimedEvent {
|
||||
private Socket _targetSocket;
|
||||
private long _startTime;
|
||||
private long _inactivityDelay;
|
||||
@@ -24,12 +24,13 @@ public class SocketTimeout implements SimpleTimer.TimedEvent {
|
||||
private Runnable _command;
|
||||
public SocketTimeout(long delay) { this(null, delay); }
|
||||
public SocketTimeout(Socket socket, long delay) {
|
||||
super(SimpleTimer2.getInstance());
|
||||
_inactivityDelay = delay;
|
||||
_targetSocket = socket;
|
||||
_cancelled = false;
|
||||
_lastActivity = _startTime = System.currentTimeMillis();
|
||||
_totalTimeoutTime = -1;
|
||||
SimpleTimer.getInstance().addEvent(SocketTimeout.this, delay);
|
||||
schedule(delay);
|
||||
}
|
||||
public void timeReached() {
|
||||
if (_cancelled) return;
|
||||
@@ -44,13 +45,13 @@ public class SocketTimeout implements SimpleTimer.TimedEvent {
|
||||
}
|
||||
if (_command != null) _command.run();
|
||||
} else {
|
||||
SimpleTimer.getInstance().addEvent(SocketTimeout.this, _inactivityDelay);
|
||||
schedule(_inactivityDelay);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
public boolean cancel() {
|
||||
_cancelled = true;
|
||||
SimpleTimer.getInstance().removeEvent(SocketTimeout.this);
|
||||
return super.cancel();
|
||||
}
|
||||
public void setSocket(Socket s) { _targetSocket = s; }
|
||||
public void resetTimer() { _lastActivity = System.currentTimeMillis(); }
|
||||
|
||||
Reference in New Issue
Block a user