I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Forked from I2P Developers / i2p.i2p
9474 commits behind the upstream repository.
  • zzz's avatar
    bb2363f6
    - Fix DummyHandler · bb2363f6
    zzz authored
    - Notes on news.xml enhancements
    - Fix handling existing torrent
    - Add dn to magnet link generation
    - Fix progress info
    bb2363f6
    History
    - Fix DummyHandler
    zzz authored
    - Notes on news.xml enhancements
    - Fix handling existing torrent
    - Add dn to magnet link generation
    - Fix progress info
DummyHandler.java 1.97 KiB
package net.i2p.router.update;

import java.net.URI;
import java.util.Collections;
import java.util.List;

import net.i2p.router.RouterContext;
import net.i2p.update.*;

/**
 * Dummy to lock up the updates for a period of time
 *
 * @since 0.9.4
 */
class DummyHandler implements Checker, Updater {
    private final RouterContext _context;
    private final ConsoleUpdateManager _mgr;
    
    public DummyHandler(RouterContext ctx, ConsoleUpdateManager mgr) {
        _context = ctx;
        _mgr = mgr;
    }

    /**
     *  Spins off an UpdateTask that sleeps
     */
    public UpdateTask check(UpdateType type, UpdateMethod method,
                            String id, String currentVersion, long maxTime) {
        if (type != UpdateType.TYPE_DUMMY)
            return null;
         return new DummyRunner(_context, _mgr, maxTime);
    }

    /**
     *  Spins off an UpdateTask that sleeps
     */
    public UpdateTask update(UpdateType type, UpdateMethod method, List<URI> updateSources,
                             String id, String newVersion, long maxTime) {
        if (type != UpdateType.TYPE_DUMMY)
            return null;
         return new DummyRunner(_context, _mgr, maxTime);
    }

    /**
     *  Use for both check and update
     */
    private static class DummyRunner extends UpdateRunner {
        private final long _delay;

        public DummyRunner(RouterContext ctx, ConsoleUpdateManager mgr, long maxTime) {
            super(ctx, mgr, Collections.EMPTY_LIST);
            _delay = maxTime;
        }

        @Override
        public UpdateType getType() { return UpdateType.TYPE_DUMMY; }

        @Override
        public UpdateMethod getMethod() { return UpdateMethod.METHOD_DUMMY; }

        @Override
        protected void update() {
            try {
                Thread.sleep(_delay);
            } catch (InterruptedException ie) {}
            _mgr.notifyCheckComplete(this, false, false);
            _mgr.notifyTaskFailed(this, "dummy", null);
        }
    }
}