+ @Override
+ protected Response stop(WLoginResult login) {
+ if (!login.isRw()) {
+ return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
+ NanoHTTPD.MIME_PLAINTEXT, "Exit not allowed");
+ }
+
+ if (exiting) {
+ return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE,
+ NanoHTTPD.MIME_PLAINTEXT, "Server is already exiting...");
+ }
+
+ exiting = true;
+ Instance.getInstance().getTraceHandler().trace("Exiting");
+
+ boolean ok;
+ do {
+ synchronized (imprts) {
+ ok = imprts.isEmpty();
+ }
+ if (!ok) {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ Instance.getInstance().getTraceHandler()
+ .trace("Waiting to exit...");
+ }
+ }
+ } while (!ok);
+
+ doStop();
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(1500);
+ } catch (InterruptedException e) {
+ }
+
+ Instance.getInstance().getTraceHandler()
+ .trace("Exit timeout: force-quit");
+ System.exit(0);
+ }
+ }, "Exit program after timeout of 1500 ms").start();
+
+ return NanoHTTPD.newFixedLengthResponse(Status.OK,
+ NanoHTTPD.MIME_PLAINTEXT, "Exited");
+ }
+