increased the delay to 2 minutes after startup before running client apps
tabs/spaces
This commit is contained in:
@ -29,136 +29,136 @@ public class StartAcceptingClientsJob extends JobImpl {
|
|||||||
public String getName() { return "Start Accepting Clients"; }
|
public String getName() { return "Start Accepting Clients"; }
|
||||||
|
|
||||||
public void runJob() {
|
public void runJob() {
|
||||||
// start up the network database
|
// start up the network database
|
||||||
|
|
||||||
ClientManagerFacade.getInstance().startup();
|
ClientManagerFacade.getInstance().startup();
|
||||||
|
|
||||||
JobQueue.getInstance().addJob(new ReadConfigJob());
|
JobQueue.getInstance().addJob(new ReadConfigJob());
|
||||||
JobQueue.getInstance().addJob(new RebuildRouterInfoJob());
|
JobQueue.getInstance().addJob(new RebuildRouterInfoJob());
|
||||||
AdminManager.getInstance().startup();
|
AdminManager.getInstance().startup();
|
||||||
JobQueue.getInstance().allowParallelOperation();
|
JobQueue.getInstance().allowParallelOperation();
|
||||||
JobQueue.getInstance().addJob(new LoadClientAppsJob());
|
JobQueue.getInstance().addJob(new LoadClientAppsJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
test(null);
|
test(null);
|
||||||
test("hi how are you?");
|
test("hi how are you?");
|
||||||
test("hi how are you? ");
|
test("hi how are you? ");
|
||||||
test(" hi how are you? ");
|
test(" hi how are you? ");
|
||||||
test(" hi how are \"y\"ou? ");
|
test(" hi how are \"y\"ou? ");
|
||||||
test("-nogui -e \"config localhost 17654\" -e \"httpclient 4544\"");
|
test("-nogui -e \"config localhost 17654\" -e \"httpclient 4544\"");
|
||||||
test("-nogui -e 'config localhost 17654' -e 'httpclient 4544'");
|
test("-nogui -e 'config localhost 17654' -e 'httpclient 4544'");
|
||||||
}
|
}
|
||||||
private static void test(String args) {
|
private static void test(String args) {
|
||||||
String parsed[] = LoadClientAppsJob.parseArgs(args);
|
String parsed[] = LoadClientAppsJob.parseArgs(args);
|
||||||
System.out.print("Parsed [" + args + "] into " + parsed.length + " elements: ");
|
System.out.print("Parsed [" + args + "] into " + parsed.length + " elements: ");
|
||||||
for (int i = 0; i < parsed.length; i++)
|
for (int i = 0; i < parsed.length; i++)
|
||||||
System.out.print("[" + parsed[i] + "] ");
|
System.out.print("[" + parsed[i] + "] ");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadClientAppsJob extends JobImpl {
|
class LoadClientAppsJob extends JobImpl {
|
||||||
private final static Log _log = new Log(LoadClientAppsJob.class);
|
private final static Log _log = new Log(LoadClientAppsJob.class);
|
||||||
/** wait a minute before starting up client apps */
|
/** wait 2 minutes before starting up client apps */
|
||||||
private final static long STARTUP_DELAY = 60*1000;
|
private final static long STARTUP_DELAY = 2*60*1000;
|
||||||
public LoadClientAppsJob() {
|
public LoadClientAppsJob() {
|
||||||
super();
|
super();
|
||||||
getTiming().setStartAfter(STARTUP_DELAY + Clock.getInstance().now());
|
getTiming().setStartAfter(STARTUP_DELAY + Clock.getInstance().now());
|
||||||
}
|
}
|
||||||
public void runJob() {
|
public void runJob() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
String className = Router.getInstance().getConfigSetting("clientApp."+i+".main");
|
String className = Router.getInstance().getConfigSetting("clientApp."+i+".main");
|
||||||
String clientName = Router.getInstance().getConfigSetting("clientApp."+i+".name");
|
String clientName = Router.getInstance().getConfigSetting("clientApp."+i+".name");
|
||||||
String args = Router.getInstance().getConfigSetting("clientApp."+i+".args");
|
String args = Router.getInstance().getConfigSetting("clientApp."+i+".args");
|
||||||
if (className == null) break;
|
if (className == null) break;
|
||||||
|
|
||||||
String argVal[] = parseArgs(args);
|
String argVal[] = parseArgs(args);
|
||||||
_log.info("Loading up the client application " + clientName + ": " + className + " " + args);
|
_log.info("Loading up the client application " + clientName + ": " + className + " " + args);
|
||||||
runClient(className, clientName, argVal);
|
runClient(className, clientName, argVal);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String[] parseArgs(String args) {
|
static String[] parseArgs(String args) {
|
||||||
List argList = new ArrayList(4);
|
List argList = new ArrayList(4);
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
char data[] = args.toCharArray();
|
char data[] = args.toCharArray();
|
||||||
StringBuffer buf = new StringBuffer(32);
|
StringBuffer buf = new StringBuffer(32);
|
||||||
boolean isQuoted = false;
|
boolean isQuoted = false;
|
||||||
for (int i = 0; i < data.length; i++) {
|
for (int i = 0; i < data.length; i++) {
|
||||||
switch (data[i]) {
|
switch (data[i]) {
|
||||||
case '\'':
|
case '\'':
|
||||||
case '\"':
|
case '\"':
|
||||||
if (isQuoted) {
|
if (isQuoted) {
|
||||||
String str = buf.toString().trim();
|
String str = buf.toString().trim();
|
||||||
if (str.length() > 0)
|
if (str.length() > 0)
|
||||||
argList.add(str);
|
argList.add(str);
|
||||||
buf = new StringBuffer(32);
|
buf = new StringBuffer(32);
|
||||||
} else {
|
} else {
|
||||||
isQuoted = true;
|
isQuoted = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
case '\t':
|
case '\t':
|
||||||
// whitespace - if we're in a quoted section, keep this as part of the quote,
|
// whitespace - if we're in a quoted section, keep this as part of the quote,
|
||||||
// otherwise use it as a delim
|
// otherwise use it as a delim
|
||||||
if (isQuoted) {
|
if (isQuoted) {
|
||||||
buf.append(data[i]);
|
buf.append(data[i]);
|
||||||
} else {
|
} else {
|
||||||
String str = buf.toString().trim();
|
String str = buf.toString().trim();
|
||||||
if (str.length() > 0)
|
if (str.length() > 0)
|
||||||
argList.add(str);
|
argList.add(str);
|
||||||
buf = new StringBuffer(32);
|
buf = new StringBuffer(32);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
buf.append(data[i]);
|
buf.append(data[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buf.length() > 0) {
|
if (buf.length() > 0) {
|
||||||
String str = buf.toString().trim();
|
String str = buf.toString().trim();
|
||||||
if (str.length() > 0)
|
if (str.length() > 0)
|
||||||
argList.add(str);
|
argList.add(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String rv[] = new String[argList.size()];
|
String rv[] = new String[argList.size()];
|
||||||
for (int i = 0; i < argList.size(); i++)
|
for (int i = 0; i < argList.size(); i++)
|
||||||
rv[i] = (String)argList.get(i);
|
rv[i] = (String)argList.get(i);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runClient(String className, String clientName, String args[]) {
|
private void runClient(String className, String clientName, String args[]) {
|
||||||
I2PThread t = new I2PThread(new RunApp(className, clientName, args));
|
I2PThread t = new I2PThread(new RunApp(className, clientName, args));
|
||||||
t.setName(clientName);
|
t.setName(clientName);
|
||||||
t.setDaemon(true);
|
t.setDaemon(true);
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static class RunApp implements Runnable {
|
private final static class RunApp implements Runnable {
|
||||||
private String _className;
|
private String _className;
|
||||||
private String _appName;
|
private String _appName;
|
||||||
private String _args[];
|
private String _args[];
|
||||||
public RunApp(String className, String appName, String args[]) {
|
public RunApp(String className, String appName, String args[]) {
|
||||||
_className = className;
|
_className = className;
|
||||||
_appName = appName;
|
_appName = appName;
|
||||||
if (args == null)
|
if (args == null)
|
||||||
_args = new String[0];
|
_args = new String[0];
|
||||||
else
|
else
|
||||||
_args = args;
|
_args = args;
|
||||||
}
|
}
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Class cls = Class.forName(_className);
|
Class cls = Class.forName(_className);
|
||||||
Method method = cls.getMethod("main", new Class[] { String[].class });
|
Method method = cls.getMethod("main", new Class[] { String[].class });
|
||||||
method.invoke(cls, new Object[] { _args });
|
method.invoke(cls, new Object[] { _args });
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
_log.log(Log.CRIT, "Error starting up the client class " + _className, t);
|
_log.log(Log.CRIT, "Error starting up the client class " + _className, t);
|
||||||
}
|
}
|
||||||
_log.info("Done running client application " + _appName);
|
_log.info("Done running client application " + _appName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() { return "Load up any client applications"; }
|
public String getName() { return "Load up any client applications"; }
|
||||||
|
Reference in New Issue
Block a user