forked from I2P_Developers/i2p.i2p

* Write the native libraries to the current directory when they are loaded from a resource, and load them from that file on subsequent runs (in turn, we no longer *cough* delete the running libraries...) * Added support for a graceful restart. * Added new pseudo-shutdown hook specific to the router, allowing applications to request tasks to be run when the router shuts down. We use this for integration with the service manager, since otherwise a graceful shutdown would cause a timeout, followed by a forced hard shutdown. * Handle a bug in the SimpleTimer with requeued tasks. * Made the capacity calculator a bit more dynamic by not outright ignoring the otherwise valid capacity data for a period with a single rejected tunnel (except for the 10 minute period). In addition, peers with an equal capacity are ordered by speed rather than by their hashes. * Cleaned up the SimpleTimer, addressing some threading and synchronization issues. * When an I2PTunnel client or httpclient is explicitly closed, destroy the associated session (unless there are other clients using it), and deal with a closed session when starting a new I2PTunnel instance. * Refactoring and logging.
110 lines
4.4 KiB
Java
110 lines
4.4 KiB
Java
package net.i2p.router.web;
|
|
|
|
import java.io.IOException;
|
|
|
|
import net.i2p.router.ClientTunnelSettings;
|
|
import net.i2p.router.Router;
|
|
import net.i2p.apps.systray.SysTray;
|
|
import org.tanukisoftware.wrapper.WrapperManager;
|
|
|
|
/**
|
|
* Handler to deal with form submissions from the service config form and act
|
|
* upon the values.
|
|
*
|
|
*/
|
|
public class ConfigServiceHandler extends FormHandler {
|
|
public void ConfigNetHandler() {}
|
|
|
|
private class UpdateWrapperManagerTask implements Runnable {
|
|
private int _exitCode;
|
|
public UpdateWrapperManagerTask(int exitCode) {
|
|
_exitCode = exitCode;
|
|
}
|
|
public void run() {
|
|
try {
|
|
WrapperManager.signalStopped(_exitCode);
|
|
} catch (Throwable t) {
|
|
t.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void processForm() {
|
|
if (_action == null) return;
|
|
|
|
if ("Shutdown gracefully".equals(_action)) {
|
|
_context.router().addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL));
|
|
_context.router().shutdownGracefully();
|
|
addFormNotice("Graceful shutdown initiated");
|
|
} else if ("Shutdown immediately".equals(_action)) {
|
|
_context.router().addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD));
|
|
_context.router().shutdown(Router.EXIT_HARD);
|
|
addFormNotice("Shutdown immediately! boom bye bye bad bwoy");
|
|
} else if ("Cancel graceful shutdown".equals(_action)) {
|
|
_context.router().cancelGracefulShutdown();
|
|
addFormNotice("Graceful shutdown cancelled");
|
|
} else if ("Graceful restart".equals(_action)) {
|
|
_context.router().addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
|
addFormNotice("Graceful restart requested");
|
|
} else if ("Hard restart".equals(_action)) {
|
|
_context.router().addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD_RESTART));
|
|
_context.router().shutdown(Router.EXIT_HARD_RESTART);
|
|
addFormNotice("Hard restart requested");
|
|
} else if ("Run I2P on startup".equals(_action)) {
|
|
installService();
|
|
} else if ("Don't run I2P on startup".equals(_action)) {
|
|
uninstallService();
|
|
} else if ("Dump threads".equals(_action)) {
|
|
try {
|
|
WrapperManager.requestThreadDump();
|
|
} catch (Throwable t) {
|
|
addFormError("Warning: unable to contact the service manager - " + t.getMessage());
|
|
}
|
|
addFormNotice("Threads dumped to wrapper.log");
|
|
} else if ("Show systray icon".equals(_action)) {
|
|
try {
|
|
SysTray tray = SysTray.getInstance();
|
|
if (tray != null) {
|
|
tray.show();
|
|
addFormNotice("Systray enabled");
|
|
} else {
|
|
addFormNotice("Systray not supported on this platform");
|
|
}
|
|
} catch (Throwable t) {
|
|
addFormError("Warning: unable to contact the systray manager - " + t.getMessage());
|
|
}
|
|
} else if ("Hide systray icon".equals(_action)) {
|
|
try {
|
|
SysTray tray = SysTray.getInstance();
|
|
if (tray != null) {
|
|
tray.hide();
|
|
addFormNotice("Systray disabled");
|
|
} else {
|
|
addFormNotice("Systray not supported on this platform");
|
|
}
|
|
} catch (Throwable t) {
|
|
addFormError("Warning: unable to contact the systray manager - " + t.getMessage());
|
|
}
|
|
} else {
|
|
addFormNotice("Blah blah blah. whatever. I'm not going to " + _action);
|
|
}
|
|
}
|
|
|
|
private void installService() {
|
|
try {
|
|
Runtime.getRuntime().exec("install_i2p_service_winnt.bat");
|
|
addFormNotice("Service installed");
|
|
} catch (IOException ioe) {
|
|
addFormError("Warning: unable to install the service - " + ioe.getMessage());
|
|
}
|
|
}
|
|
private void uninstallService() {
|
|
try {
|
|
Runtime.getRuntime().exec("uninstall_i2p_service_winnt.bat");
|
|
addFormNotice("Service removed");
|
|
} catch (IOException ioe) {
|
|
addFormError("Warning: unable to remove the service - " + ioe.getMessage());
|
|
}
|
|
}
|
|
} |