diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java index c909a112f011aa4de23efb4014c80eba3b89803a..d0d9a3bd8476d59c95c291ca3ddcc66016ab7683 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java +++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java @@ -40,6 +40,8 @@ public class SnarkManager implements Snark.CompleteListener { private I2PSnarkUtil _util; private PeerCoordinatorSet _peerCoordinatorSet; private ConnectionAcceptor _connectionAcceptor; + private Thread _monitor; + private boolean _running; public static final String PROP_I2CP_HOST = "i2psnark.i2cpHost"; public static final String PROP_I2CP_PORT = "i2psnark.i2cpPort"; @@ -78,15 +80,22 @@ public class SnarkManager implements Snark.CompleteListener { * for i2cp host/port or i2psnark.dir */ public void start() { + _running = true; _peerCoordinatorSet = new PeerCoordinatorSet(); _connectionAcceptor = new ConnectionAcceptor(_util); int minutes = getStartupDelayMinutes(); _messages.add(_("Adding torrents in {0} minutes", minutes)); - I2PAppThread monitor = new I2PAppThread(new DirMonitor(), "Snark DirMonitor"); - monitor.setDaemon(true); - monitor.start(); + _monitor = new I2PAppThread(new DirMonitor(), "Snark DirMonitor", true); + _monitor.start(); _context.addShutdownTask(new SnarkManagerShutdown()); } + + public void stop() { + _running = false; + _monitor.interrupt(); + _connectionAcceptor.halt(); + (new SnarkManagerShutdown()).run(); + } /** hook to I2PSnarkUtil for the servlet */ public I2PSnarkUtil util() { return _util; } diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 013d70a94c3b2e87fc6104415557203f043e87ba..2a113051315d87de105b43b91dae212884fc6a40 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -59,6 +59,12 @@ public class I2PSnarkServlet extends HttpServlet { _manager.start(); } + @Override + public void destroy() { + _manager.stop(); + super.destroy(); + } + @Override public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8");