* Plugins: Track pending plugin clients better, don't hold references,

start delayed clients from SimpleTimer2 instead of Job queue (ticket #670)
This commit is contained in:
zzz
2013-04-26 16:41:09 +00:00
parent 1cea18346b
commit 0816cfe273
9 changed files with 89 additions and 42 deletions

View File

@@ -12,6 +12,7 @@ package net.i2p.router;
/**
* Defines an executable task
*
* For use by the router only. Not to be used by applications or plugins.
*/
public interface Job {
/**

View File

@@ -12,6 +12,8 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* Base implementation of a Job
*
* For use by the router only. Not to be used by applications or plugins.
*/
public abstract class JobImpl implements Job {
private final RouterContext _context;

View File

@@ -31,6 +31,7 @@ import net.i2p.util.Log;
* Manage the pending jobs according to whatever algorithm is appropriate, giving
* preference to earlier scheduled jobs.
*
* For use by the router only. Not to be used by applications or plugins.
*/
public class JobQueue {
private final Log _log;

View File

@@ -5,6 +5,7 @@ import net.i2p.data.DataHelper;
/**
* Glorified struct to contain basic job stats.
* Public for router console only.
* For use by the router only. Not to be used by applications or plugins.
*/
public class JobStats {
private final String _job;

View File

@@ -13,6 +13,7 @@ import net.i2p.util.Clock;
/**
* Define the timing requirements and statistics for a particular job
*
* For use by the router only. Not to be used by applications or plugins.
*/
public class JobTiming implements Clock.ClockUpdateListener {
private long _start;

View File

@@ -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 = 16;
public final static long BUILD = 17;
/** for example "-test" */
public final static String EXTRA = "";

View File

@@ -14,6 +14,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.app.RouterApp;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer2;
/**
* Run any client applications specified in clients.config. If any clientApp
@@ -51,12 +52,18 @@ public class LoadClientAppsJob extends JobImpl {
runClient(app.className, app.clientName, argVal, getContext(), _log);
} else {
// wait before firing it up
getContext().jobQueue().addJob(new DelayedRunClient(getContext(), app.className, app.clientName, argVal, app.delay));
DelayedRunClient drc = new DelayedRunClient(getContext().simpleTimer2(), getContext(), app.className,
app.clientName, argVal);
drc.schedule(app.delay);
}
}
}
public static class DelayedRunClient extends JobImpl {
/**
* Public for router console only, not for use by others, subject to change
*/
public static class DelayedRunClient extends SimpleTimer2.TimedEvent {
private final RouterContext _ctx;
private final String _className;
private final String _clientName;
private final String _args[];
@@ -64,26 +71,27 @@ public class LoadClientAppsJob extends JobImpl {
private final ThreadGroup _threadGroup;
private final ClassLoader _cl;
public DelayedRunClient(RouterContext enclosingContext, String className, String clientName, String args[], long delay) {
this(enclosingContext, className, clientName, args, delay, null, null);
/** caller MUST call schedule() */
public DelayedRunClient(SimpleTimer2 pool, RouterContext enclosingContext, String className,
String clientName, String args[]) {
this(pool, enclosingContext, className, clientName, args, null, null);
}
public DelayedRunClient(RouterContext enclosingContext, String className, String clientName, String args[],
long delay, ThreadGroup threadGroup, ClassLoader cl) {
super(enclosingContext);
/** caller MUST call schedule() */
public DelayedRunClient(SimpleTimer2 pool, RouterContext enclosingContext, String className, String clientName,
String args[], ThreadGroup threadGroup, ClassLoader cl) {
super(pool);
_ctx = enclosingContext;
_className = className;
_clientName = clientName;
_args = args;
_log = enclosingContext.logManager().getLog(LoadClientAppsJob.class);
_threadGroup = threadGroup;
_cl = cl;
getTiming().setStartAfter(getContext().clock().now() + delay);
}
public String getName() { return "Delayed client job"; }
public void runJob() {
runClient(_className, _clientName, _args, getContext(), _log, _threadGroup, _cl);
public void timeReached() {
runClient(_className, _clientName, _args, _ctx, _log, _threadGroup, _cl);
}
}