Changeset 6bfd916f


Ignore:
Timestamp:
Sep 1, 2012 1:14:15 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3fbf60ee
Parents:
94f370e
Message:

SimpleTimer? (ticket #653):

  • Move all remaining uses to SimpleTimer2
  • Deprecate
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java

    r94f370e r6bfd916f  
    1414import net.i2p.data.SessionKey;
    1515import net.i2p.util.Log;
    16 import net.i2p.util.SimpleTimer;
    1716import net.i2p.util.SimpleTimer2;
    1817
     
    495494            _pendingPings.remove(id);
    496495        } else {
    497             SimpleTimer.getInstance().addEvent(new PingFailed(id, notifier), timeoutMs);
     496            PingFailed pf = new PingFailed(id, notifier);
     497            pf.schedule(timeoutMs);
    498498        }
    499499       
     
    506506    }
    507507   
    508     private class PingFailed implements SimpleTimer.TimedEvent {
     508    private class PingFailed extends SimpleTimer2.TimedEvent {
    509509        private final Long _id;
    510510        private final PingNotifier _notifier;
    511511
    512512        public PingFailed(Long id, PingNotifier notifier) {
     513            super(_context.simpleTimer2());
    513514            _id = id;
    514515            _notifier = notifier;
  • core/java/src/net/i2p/I2PAppContext.java

    r94f370e r6bfd916f  
    954954     * Use instead of SimpleTimer.getInstance()
    955955     * @since 0.9 to replace static instance in the class
     956     * @deprecated use SimpleTimer2
    956957     */
    957958    public SimpleTimer simpleTimer() {
     
    961962    }
    962963
     964    /**
     965     * @deprecated use SimpleTimer2
     966     */
    963967    private void initializeSimpleTimer() {
    964968        synchronized (_lock19) {
  • core/java/src/net/i2p/util/SimpleStore.java

    r94f370e r6bfd916f  
    66
    77/**
     8 *  Deprecated - used only by SimpleTimer
    89 *
    910 * @author sponge
  • core/java/src/net/i2p/util/SimpleTimer.java

    r94f370e r6bfd916f  
    2222    /**
    2323     *  If you have a context, use context.simpleTimer() instead
     24     *  @deprecated use SimpleTimer2
    2425     */
    2526    public static SimpleTimer getInstance() {
     
    4041     *  To be instantiated by the context.
    4142     *  Others should use context.simpleTimer() instead
     43     *  @deprecated use SimpleTimer2
    4244     */
    4345    public SimpleTimer(I2PAppContext context) {
     
    4850     *  To be instantiated by the context.
    4951     *  Others should use context.simpleTimer() instead
     52     *  @deprecated use SimpleTimer2
    5053     */
    5154    private SimpleTimer(I2PAppContext context, String name) {
     
    147150                }
    148151            }
     152            // FIXME if you plan to use this class again
    149153            while (_events.containsKey(time))
    150154                time = new Long(time.longValue() + 1);
  • core/java/src/net/i2p/util/SimpleTimer2.java

    r94f370e r6bfd916f  
    206206
    207207        /**
    208          *  More efficient than reschedule().
    209          *  Only call this after calling the non-scheduling constructor,
    210          *  or from within timeReached(), or you will get duplicates on the queue.
    211          *  Otherwise use reschedule().
     208         *  Slightly more efficient than reschedule().
     209         *  Does nothing if already scheduled.
    212210         */
    213211        public synchronized void schedule(long timeoutMs) {
     
    237235        /**
    238236         * Use the earliest of the new time and the old time
    239          * Do not call from within timeReached()
     237         * May be called from within timeReached(), but schedule() is
     238         * better there.
    240239         *
    241240         * @param timeoutMs
     
    246245
    247246        /**
    248          * useEarliestTime must be false if called from within timeReached(), as
    249          * it won't be rescheduled, in favor of the currently running task
     247         * May be called from within timeReached(), but schedule() is
     248         * better there.
    250249         *
    251250         * @param timeoutMs
  • core/java/src/net/i2p/util/SocketTimeout.java

    r94f370e r6bfd916f  
    1515 *  Use socket.setsotimeout instead?
    1616 */
    17 public class SocketTimeout implements SimpleTimer.TimedEvent {
     17public class SocketTimeout extends SimpleTimer2.TimedEvent {
    1818    private Socket _targetSocket;
    1919    private long _startTime;
     
    2525    public SocketTimeout(long delay) { this(null, delay); }
    2626    public SocketTimeout(Socket socket, long delay) {
     27        super(SimpleTimer2.getInstance());
    2728        _inactivityDelay = delay;
    2829        _targetSocket = socket;
     
    3031        _lastActivity = _startTime = System.currentTimeMillis();
    3132        _totalTimeoutTime = -1;
    32         SimpleTimer.getInstance().addEvent(SocketTimeout.this, delay);
     33        schedule(delay);
    3334    }
    3435    public void timeReached() {
     
    4546            if (_command != null) _command.run();
    4647        }  else {
    47             SimpleTimer.getInstance().addEvent(SocketTimeout.this, _inactivityDelay);
     48            schedule(_inactivityDelay);
    4849        }
    4950    }
    5051   
    51     public void cancel() {
     52    public boolean cancel() {
    5253        _cancelled = true;
    53         SimpleTimer.getInstance().removeEvent(SocketTimeout.this);
     54        return super.cancel();
    5455    }
    5556    public void setSocket(Socket s) { _targetSocket = s; }
  • router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java

    r94f370e r6bfd916f  
    2626import net.i2p.util.ConcurrentHashSet;
    2727import net.i2p.util.Log;
    28 import net.i2p.util.SimpleTimer;
     28import net.i2p.util.SimpleTimer2;
    2929
    3030/**
     
    255255    public void renderStatusHTML(Writer out) throws IOException {}
    256256   
    257     private class CleanupTask implements SimpleTimer.TimedEvent {
     257    private class CleanupTask extends SimpleTimer2.TimedEvent {
    258258        private long _nextExpire;
    259259
    260260        public CleanupTask() {
     261            super(_context.simpleTimer2());
    261262            _nextExpire = -1;
    262263        }
     
    313314            if (_nextExpire <= now)
    314315                _nextExpire = now + 10*1000;
    315             SimpleTimer.getInstance().addEvent(CleanupTask.this, _nextExpire - now);
     316            schedule(_nextExpire - now);
    316317        }
    317318
     
    320321            if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) {
    321322                _nextExpire = sel.getExpiration();
    322                 SimpleTimer.getInstance().addEvent(CleanupTask.this, _nextExpire - now);
     323                reschedule(_nextExpire - now);
    323324            }
    324325        }
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r94f370e r6bfd916f  
    4343import net.i2p.util.SimpleScheduler;
    4444import net.i2p.util.SimpleTimer;
     45import net.i2p.util.SimpleTimer2;
    4546import net.i2p.util.Translate;
    4647
     
    370371        _expireEvent.setIsAlive(true);
    371372        _testEvent.setIsAlive(true); // this queues it for 3-6 minutes in the future...
    372         SimpleTimer.getInstance().addEvent(_testEvent, 10*1000); // lets requeue it for Real Soon
     373        _testEvent.reschedule(10*1000); // lets requeue it for Real Soon
    373374    }
    374375   
     
    682683        }
    683684        _testEvent.forceRun();
    684         SimpleTimer.getInstance().addEvent(_testEvent, 5*1000);
     685        _testEvent.reschedule(5*1000);
    685686        return updated;
    686687    }
     
    860861        if (getReachabilityStatus() != CommSystemFacade.STATUS_OK) {
    861862            _testEvent.forceRun();
    862             SimpleTimer.getInstance().addEvent(_testEvent, 0);
     863            _testEvent.reschedule(0);
    863864        }
    864865        return true;
     
    934935
    935936    private class RemoveDropList implements SimpleTimer.TimedEvent {
    936         private RemoteHostId _peer;
     937        private final RemoteHostId _peer;
    937938        public RemoveDropList(RemoteHostId peer) { _peer = peer; }
    938939        public void timeReached() {
     
    23622363    }
    23632364   
    2364     private class ExpirePeerEvent implements SimpleTimer.TimedEvent {
     2365    private class ExpirePeerEvent extends SimpleTimer2.TimedEvent {
    23652366        private final Set<PeerState> _expirePeers;
    23662367        private final List<PeerState> _expireBuffer;
     
    23682369
    23692370        public ExpirePeerEvent() {
     2371            super(_context.simpleTimer2());
    23702372            _expirePeers = new ConcurrentHashSet(128);
    23712373            _expireBuffer = new ArrayList();
     
    24042406
    24052407            if (_alive)
    2406                 SimpleTimer.getInstance().addEvent(ExpirePeerEvent.this, 30*1000);
     2408                schedule(30*1000);
    24072409        }
    24082410        public void add(PeerState peer) {
     
    24152417            _alive = isAlive;
    24162418            if (isAlive) {
    2417                 SimpleTimer.getInstance().addEvent(ExpirePeerEvent.this, 30*1000);
     2419                reschedule(30*1000);
    24182420            } else {
    2419                 SimpleTimer.getInstance().removeEvent(ExpirePeerEvent.this);
     2421                cancel();
    24202422                _expirePeers.clear();
    24212423            }
     
    25162518    }
    25172519   
    2518     private class PeerTestEvent implements SimpleTimer.TimedEvent {
     2520    private class PeerTestEvent extends SimpleTimer2.TimedEvent {
    25192521        private volatile boolean _alive;
    25202522        /** when did we last test our reachability */
     
    25222524        private boolean _forceRun;
    25232525
     2526        PeerTestEvent() {
     2527            super(_context.simpleTimer2());
     2528        }
     2529       
    25242530        public void timeReached() {
    25252531            if (shouldTest()) {
     
    25332539                if (delay <= 0)
    25342540                    throw new RuntimeException("wtf, delay is " + delay);
    2535                 SimpleTimer.getInstance().addEvent(PeerTestEvent.this, delay);
     2541                schedule(delay);
    25362542            }
    25372543        }
     
    25592565            if (isAlive) {
    25602566                long delay = _context.random().nextInt(2*TEST_FREQUENCY);
    2561                 SimpleTimer.getInstance().addEvent(PeerTestEvent.this, delay);
     2567                reschedule(delay);
    25622568            } else {
    2563                 SimpleTimer.getInstance().removeEvent(PeerTestEvent.this);
     2569                cancel();
    25642570            }
    25652571        }
  • router/java/src/net/i2p/router/tunnel/FragmentHandler.java

    r94f370e r6bfd916f  
    1717import net.i2p.util.Log;
    1818import net.i2p.util.SimpleByteCache;
    19 import net.i2p.util.SimpleTimer;
     19import net.i2p.util.SimpleTimer2;
    2020
    2121/**
     
    370370                    }
    371371                    if (msg.getExpireEvent() != null)
    372                         SimpleTimer.getInstance().removeEvent(msg.getExpireEvent());
     372                        msg.getExpireEvent().cancel();
    373373                    receiveComplete(msg);
    374374                } else {
     
    379379                        if (_log.shouldLog(Log.DEBUG))
    380380                            _log.debug("In " + MAX_DEFRAGMENT_TIME + " dropping " + messageId);
    381                         SimpleTimer.getInstance().addEvent(evt, MAX_DEFRAGMENT_TIME);
     381                        evt.schedule(MAX_DEFRAGMENT_TIME);
    382382                    }
    383383                }
     
    438438                }
    439439                if (msg.getExpireEvent() != null)
    440                     SimpleTimer.getInstance().removeEvent(msg.getExpireEvent());
     440                    msg.getExpireEvent().cancel();
    441441                _context.statManager().addRateData("tunnel.fragmentedComplete", msg.getFragmentCount(), msg.getLifetime());
    442442                receiveComplete(msg);
     
    448448                    if (_log.shouldLog(Log.DEBUG))
    449449                        _log.debug("In " + MAX_DEFRAGMENT_TIME + " dropping " + msg.getMessageId() + "/" + fragmentNum);
    450                     SimpleTimer.getInstance().addEvent(evt, MAX_DEFRAGMENT_TIME);
     450                    evt.schedule(MAX_DEFRAGMENT_TIME);
    451451                }
    452452            }
     
    549549    }
    550550   
    551     private class RemoveFailed implements SimpleTimer.TimedEvent {
     551    private class RemoveFailed extends SimpleTimer2.TimedEvent {
    552552        private final FragmentedMessage _msg;
    553553
    554554        public RemoveFailed(FragmentedMessage msg) {
     555            super(_context.simpleTimer2());
    555556            _msg = msg;
    556557        }
  • router/java/src/net/i2p/router/tunnel/FragmentedMessage.java

    r94f370e r6bfd916f  
    88import net.i2p.util.ByteCache;
    99import net.i2p.util.Log;
    10 import net.i2p.util.SimpleTimer;
     10import net.i2p.util.SimpleTimer2;
    1111
    1212/**
     
    2929    private boolean _completed;
    3030    private long _releasedAfter;
    31     private SimpleTimer.TimedEvent _expireEvent;
     31    private SimpleTimer2.TimedEvent _expireEvent;
    3232   
    3333    private static final ByteCache _cache = ByteCache.getInstance(512, TrivialPreprocessor.PREPROCESSED_SIZE);
     
    161161        return found;
    162162    }
     163
    163164    /** used in the fragment handler so we can cancel the expire event on success */
    164     SimpleTimer.TimedEvent getExpireEvent() { return _expireEvent; }
    165     void setExpireEvent(SimpleTimer.TimedEvent evt) { _expireEvent = evt; }
     165    public SimpleTimer2.TimedEvent getExpireEvent() { return _expireEvent; }
     166
     167    public void setExpireEvent(SimpleTimer2.TimedEvent evt) { _expireEvent = evt; }
    166168   
    167169    /** have we received all of the fragments? */
  • router/java/src/net/i2p/router/tunnel/TunnelGateway.java

    r94f370e r6bfd916f  
    1111import net.i2p.router.RouterContext;
    1212import net.i2p.util.Log;
    13 import net.i2p.util.SimpleTimer;
     13import net.i2p.util.SimpleTimer2;
    1414
    1515/**
     
    125125       
    126126        if (delayedFlush) {
    127             _context.simpleTimer().addEvent(_delayedFlush, delayAmount);
     127            _delayedFlush.reschedule(delayAmount);
    128128        }
    129129        _context.statManager().addRateData("tunnel.lockedGatewayAdd", afterAdded-beforeLock, remaining);
     
    279279    }
    280280   
    281     private class DelayedFlush implements SimpleTimer.TimedEvent {
     281    protected class DelayedFlush extends SimpleTimer2.TimedEvent {
     282        DelayedFlush() {
     283            super(_context.simpleTimer2());
     284        }
     285
    282286        public void timeReached() {
    283287            boolean wantRequeue = false;
     
    305309           
    306310            if (wantRequeue)
    307                 _context.simpleTimer().addEvent(_delayedFlush, delayAmount);
     311                schedule(delayAmount);
    308312            else
    309313                _lastFlush = _context.clock().now();
  • router/java/src/net/i2p/router/util/DecayingBloomFilter.java

    r94f370e r6bfd916f  
    88import net.i2p.data.DataHelper;
    99import net.i2p.util.Log;
    10 import net.i2p.util.SimpleTimer;
     10import net.i2p.util.SimpleTimer2;
    1111
    1212import org.xlattice.crypto.filters.BloomSHA1;
     
    3939    protected long _currentDuplicates;
    4040    protected volatile boolean _keepDecaying;
    41     protected final SimpleTimer.TimedEvent _decayEvent;
     41    protected final SimpleTimer2.TimedEvent _decayEvent;
    4242    /** just for logging */
    4343    protected final String _name;
     
    6565        _decayEvent = new DecayEvent();
    6666        _keepDecaying = true;
    67         SimpleTimer.getInstance().addEvent(_decayEvent, _durationMs);
     67        _decayEvent.schedule(_durationMs);
    6868    }
    6969
     
    119119        _decayEvent = new DecayEvent();
    120120        _keepDecaying = true;
    121         SimpleTimer.getInstance().addEvent(_decayEvent, _durationMs);
     121        _decayEvent.schedule(_durationMs);
    122122        if (_log.shouldLog(Log.WARN))
    123123           _log.warn("New DBF " + name + " m = " + m + " k = " + k + " entryBytes = " + entryBytes +
     
    275275    public void stopDecaying() {
    276276        _keepDecaying = false;
    277         SimpleTimer.getInstance().removeEvent(_decayEvent);
     277        _decayEvent.cancel();
    278278    }
    279279   
     
    311311    }
    312312   
    313     private class DecayEvent implements SimpleTimer.TimedEvent {
     313    private class DecayEvent extends SimpleTimer2.TimedEvent {
     314        DecayEvent() {
     315            super(_context.simpleTimer2());
     316        }
     317       
    314318        public void timeReached() {
    315319            if (_keepDecaying) {
    316320                decay();
    317                 SimpleTimer.getInstance().addEvent(DecayEvent.this, _durationMs);
     321                schedule(_durationMs);
    318322            }
    319323        }
Note: See TracChangeset for help on using the changeset viewer.