Monitor for stopping the Jetty server.
| 371 | |
| 372 | /** Monitor for stopping the Jetty server. */ |
| 373 | private final class StopServer extends Thread { |
| 374 | /** Server socket. */ |
| 375 | private final ServerSocket socket; |
| 376 | /** Stop file. */ |
| 377 | private final IOFile stopFile; |
| 378 | /** Port. */ |
| 379 | private final int stopPort; |
| 380 | |
| 381 | /** |
| 382 | * Constructor. |
| 383 | * @param port port to stop server |
| 384 | * @throws IOException I/O exception |
| 385 | */ |
| 386 | StopServer(final int port) throws IOException { |
| 387 | stopPort = port; |
| 388 | |
| 389 | final String host = soptions.get(StaticOptions.SERVERHOST); |
| 390 | final InetAddress addr = host.isEmpty() ? null : InetAddress.getByName(host); |
| 391 | socket = new ServerSocket(); |
| 392 | socket.setReuseAddress(true); |
| 393 | socket.bind(new InetSocketAddress(addr, stopPort)); |
| 394 | stopFile = stopFile(BaseXHTTP.class, stopPort); |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public void run() { |
| 399 | try { |
| 400 | while(true) { |
| 401 | Util.println(HTTP + " STOP " + SRV_STARTED_PORT_X, stopPort); |
| 402 | try(Socket s = socket.accept()) { /* no action */ } |
| 403 | if(stopFile.exists()) { |
| 404 | socket.close(); |
| 405 | Util.println(HTTP + " STOP " + SRV_STOPPED_PORT_X, stopPort); |
| 406 | jetty.stop(); |
| 407 | hc.close(); |
| 408 | Prop.clear(); |
| 409 | if(!stopFile.delete()) { |
| 410 | context.log.writeServer(LogType.ERROR, Util.info(FILE_NOT_DELETED_X, stopFile)); |
| 411 | } |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | } catch(final Exception ex) { |
| 416 | Util.stack(ex); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } |
nothing calls this directly
no outgoing calls
no test coverage detected