From be311962cb515e74f31a8f249df1fa28e3137ebe Mon Sep 17 00:00:00 2001 From: AKurakin Date: Sat, 23 Sep 2023 20:21:42 +0300 Subject: [PATCH] imdg http://git.mfd.msk/mfd/clearing/-/issues/22 debug reload --- .../services/controller/ImdgController.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/controller/ImdgController.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/controller/ImdgController.java index 1cfc6b262..3c7652305 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/controller/ImdgController.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/controller/ImdgController.java @@ -69,38 +69,44 @@ public class ImdgController implements InitializingBean, DisposableBean { public void handle(HttpExchange t) throws IOException { log.info("Reload request by user \"{}\"", t.getRemoteAddress().getAddress()); t.sendResponseHeaders(200, 0); - t.setAttribute("Content-Type", "text/plain; charset=utf-8"); // or "text/html; charset=utf-8" + t.setAttribute("Content-Type", "text/html; charset=windows-1251"); // or "text/plain или text/html; charset=windows-1251" try (OutputStream os = t.getResponseBody()) { - // writeHead(os); - writeLine(os, "Wait, reload all maps from DB... " + LocalDateTime.now()); - os.flush(); - try { - long clock = System.currentTimeMillis(); - int count = imdgService.reloadMapFromDB(); - clock = System.currentTimeMillis() - clock; - writeLine(os, count + " map per " + clock + " ms"); - } catch (Throwable e) { - String msg = "Error reload: " + ExceptionUtils.getStackTrace(e); - log.error(msg); - writeLine(os, msg); + writeHead(os); + writeLine(os, "Wait, reload all maps from DB...
"); + synchronized (ImdgController.this) { + os.flush(); + try { + long clock = System.currentTimeMillis(); + int count = imdgService.reloadMapFromDB(); + clock = System.currentTimeMillis() - clock; + writeLine(os, count + " map per " + clock + " ms
"); + } catch (Throwable e) { + String msg = "Error reload: " + ExceptionUtils.getStackTrace(e); + log.error(msg); + writeLine(os, msg); + } } - writeLine(os, "Done. " + LocalDateTime.now()); - // writeEnd(os) + writeLine(os, "Done. " + LocalDateTime.now() + "
"); + writeLine(os, " Reload again. "); + writeEnd(os); } //os.close(); + log.trace("HTTP Request done."); } void writeHead(OutputStream os) throws IOException { - //writeLine(os, ""); + writeLine(os, "\n\n"); + writeLine(os, "
"); } void writeLine(OutputStream os, String text) throws IOException { if (text != null) - os.write(text.getBytes(StandardCharsets.UTF_8)); - os.write("\n".getBytes(StandardCharsets.UTF_8)); + os.write(text.getBytes("windows-1251")); + os.write("\n".getBytes("windows-1251")); } void writeEnd(OutputStream os) throws IOException { - //writeLine(os, ""); + writeLine(os, "
"); + writeLine(os, ""); } } }