* Router: Cleanup startup jobs and router.config reading; javadocs

This commit is contained in:
zzz
2011-12-18 15:17:09 +00:00
parent 61810b7215
commit 78229227d2
11 changed files with 88 additions and 40 deletions

View File

@@ -382,9 +382,6 @@ public class Router implements RouterClock.ClockShiftListener {
_context.keyManager().startup();
// why are we reading this again, it's read in the constructor
readConfig();
setupHandlers();
//if (ALLOW_DYNAMIC_KEYS) {
// if ("true".equalsIgnoreCase(_context.getProperty(Router.PROP_HIDDEN, "false")))

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 = 23;
public final static long BUILD = 24;
/** for example "-test" */
public final static String EXTRA = "-rc";

View File

@@ -45,7 +45,9 @@ public class BootCommSystemJob extends JobImpl {
// start I2CP
getContext().jobQueue().addJob(new StartAcceptingClientsJob(getContext()));
getContext().jobQueue().addJob(new ReadConfigJob(getContext()));
Job j = new ReadConfigJob(getContext());
j.getTiming().setStartAfter(getContext().clock().now() + 60*1000);
getContext().jobQueue().addJob(j);
((RouterClock) getContext().clock()).addShiftListener(getContext().router());
}

View File

@@ -11,15 +11,15 @@ package net.i2p.router.startup;
import net.i2p.router.Job;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
/**
* For future restricted routes. Does nothing now.
*/
public class BuildTrustedLinksJob extends JobImpl {
private Log _log;
private Job _next;
private final Job _next;
public BuildTrustedLinksJob(RouterContext context, Job next) {
super(context);
_log = getContext().logManager().getLog(BuildTrustedLinksJob.class);
_next = next;
}

View File

@@ -72,29 +72,30 @@ public class ClientAppConfig {
private static final String PREFIX = "clientApp.";
// let's keep this really simple
// Following 4 may be edited in router console
public String className;
public String clientName;
public String args;
public long delay;
public boolean disabled;
public final long delay;
/** @since 0.7.12 */
public String classpath;
public final String classpath;
/** @since 0.7.12 */
public String stopargs;
public final String stopargs;
/** @since 0.7.12 */
public String uninstallargs;
public final String uninstallargs;
public ClientAppConfig(String cl, String client, String a, long d, boolean dis) {
this(cl, client, a, d, dis, null, null, null);
}
/** @since 0.7.12 */
public ClientAppConfig(String cl, String client, String a, long d, boolean dis, String cp, String sa, String ua) {
className = cl;
clientName = client;
args = a;
delay = d;
disabled = dis;
}
/** @since 0.7.12 */
public ClientAppConfig(String cl, String client, String a, long d, boolean dis, String cp, String sa, String ua) {
this(cl, client, a, d, dis);
classpath = cp;
stopargs = sa;
uninstallargs = ua;

View File

@@ -30,12 +30,13 @@ import net.i2p.util.Log;
import net.i2p.util.SecureFileOutputStream;
public class CreateRouterInfoJob extends JobImpl {
private static Log _log = new Log(CreateRouterInfoJob.class);
private final Log _log;
private final Job _next;
public CreateRouterInfoJob(RouterContext ctx, Job next) {
super(ctx);
_next = next;
_log = ctx.logManager().getLog(CreateRouterInfoJob.class);
}
public String getName() { return "Create New Router Info"; }
@@ -124,7 +125,7 @@ public class CreateRouterInfoJob extends JobImpl {
*
*/
static long getCurrentPublishDate(RouterContext context) {
_log.info("Setting published date to /now/");
//_log.info("Setting published date to /now/");
return context.clock().now();
}
}

View File

@@ -17,7 +17,7 @@ import net.i2p.util.Log;
*
*/
public class LoadClientAppsJob extends JobImpl {
private Log _log;
private final Log _log;
private static boolean _loaded = false;
public LoadClientAppsJob(RouterContext ctx) {
@@ -51,12 +51,12 @@ public class LoadClientAppsJob extends JobImpl {
}
public static class DelayedRunClient extends JobImpl {
private String _className;
private String _clientName;
private String _args[];
private Log _log;
private ThreadGroup _threadGroup;
private ClassLoader _cl;
private final String _className;
private final String _clientName;
private final String _args[];
private final Log _log;
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);
@@ -211,11 +211,11 @@ public class LoadClientAppsJob extends JobImpl {
}
private final static class RunApp implements Runnable {
private String _className;
private String _appName;
private String _args[];
private Log _log;
private ClassLoader _cl;
private final String _className;
private final String _appName;
private final String _args[];
private final Log _log;
private final ClassLoader _cl;
public RunApp(String className, String appName, String args[], Log log, ClassLoader cl) {
_className = className;
@@ -246,6 +246,7 @@ public class LoadClientAppsJob extends JobImpl {
public String getName() { return "Load up any client applications"; }
/****
public static void main(String args[]) {
test(null);
test("hi how are you?");
@@ -262,4 +263,5 @@ public class LoadClientAppsJob extends JobImpl {
System.out.print("[" + parsed[i] + "] ");
System.out.println();
}
****/
}

View File

@@ -12,30 +12,45 @@ import java.io.File;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
/**
* Simply read the router config
* Simply read the router config periodically,
* so that the user may make config changes externally.
* This isn't advertised as a feature,
* but it could be used, for example, to change bandwidth limits
* at certain times of day.
*
* Unfortunately it will also read the file back in every time the
* router writes it.
*
* So maybe this should just be disabled.
*/
public class ReadConfigJob extends JobImpl {
private final static long DELAY = 30*1000; // reread every 30 seconds
private long _lastRead = -1;
private long _lastRead;
public ReadConfigJob(RouterContext ctx) {
super(ctx);
_lastRead = ctx.clock().now();
}
public String getName() { return "Read Router Configuration"; }
public void runJob() {
if (shouldReread()) {
File configFile = new File(getContext().router().getConfigFilename());
if (shouldReread(configFile)) {
getContext().router().readConfig();
_lastRead = getContext().clock().now();
Log log = getContext().logManager().getLog(ReadConfigJob.class);
if (log.shouldLog(Log.WARN))
log.warn("Reloaded " + configFile);
}
getTiming().setStartAfter(getContext().clock().now() + DELAY);
getContext().jobQueue().addJob(this);
}
private boolean shouldReread() {
File configFile = new File(getContext().router().getConfigFilename());
private boolean shouldReread(File configFile) {
if (!configFile.exists()) return false;
if (configFile.lastModified() > _lastRead)
return true;

View File

@@ -10,15 +10,12 @@ package net.i2p.router.startup;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
/** start I2CP interface */
public class StartAcceptingClientsJob extends JobImpl {
private Log _log;
public StartAcceptingClientsJob(RouterContext context) {
super(context);
_log = context.logManager().getLog(StartAcceptingClientsJob.class);
}
public String getName() { return "Start Accepting Clients"; }

View File

@@ -6,5 +6,31 @@
<p>
The startup consists of a number of different jobs, like loading data from files for the network database, creating new router information (keypairs), and so on.
</p>
<p><pre>
Calling order:
StartupJob
LoadClientAppsJob
starts clients and queues delayed client jobs
start stats publisher
LoadRouterInfoJob
RebuildRouterInfoJob if necessary
CreateRouterInfoJob if necessary
BootCommSystemJob
allow parallel operation in job queue
BootNetworkDbJob
starts netdb
BuildTrustedLinksJob (never used)
BootPeerManagerJob
starts peer manager
start comm system
start tunnel manager
StartAcceptingClientsJob
starts client manager
ReadConfigJob
loops every 30 seconds
</pre></p>
</body>
</html>