我使用NanoHTTP库创建了一个小型HTTP侦听器,我想将它与Apache Commons Daemon(https://commons.apache.org/proper/commons-daemon/index.html)一起使用,以procrun作为Windows服务进行安装。 我阅读了文档,但我无法理解如何在单独的过程中管理启停工作。如何从另一个单独的Java进程中停止NanoHTTPD?
这是我的课程扩展NanoHTTPD:
public class PrintServer extends NanoHTTPD {
private static final int SERVER_PORT=11100;
private static final String MIMEJSON = "application/json";
public PrintServer() throws IOException {
super(SERVER_PORT);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
log.info("Cinebot PrintServer avviato e in ascolto su porta {}",SERVER_PORT);
}
public static void main(String[] args) {
try {
new PrintServer();
} catch (IOException ioe) {
log.error("Non posso avviare PrintServer", ioe);
}
}
@Override
public Response serve(IHTTPSession session) {
return newFixedLengthResponse(Response.Status.OK, MIMEJSON, null);
}
}