imdg http://git.mfd.msk/mfd/clearing/-/issues/22 debug reload
This commit is contained in:
parent
91cc82f154
commit
be311962cb
1 changed files with 25 additions and 19 deletions
|
|
@ -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... </br>");
|
||||
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</br>");
|
||||
} 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, "<b title=\":)\">Done.</b> " + LocalDateTime.now() + "</br>");
|
||||
writeLine(os, " <a href=\"\">Reload again.</a> ");
|
||||
writeEnd(os);
|
||||
} //os.close();
|
||||
log.trace("HTTP Request done.");
|
||||
}
|
||||
|
||||
void writeHead(OutputStream os) throws IOException {
|
||||
//writeLine(os, "<doctype html><html><body>");
|
||||
writeLine(os, "<!DOCTYPE html>\n<html><head></head>\n<body style=\"background-color:lightgray; font-size:14pt;color:black;\">");
|
||||
writeLine(os, "<div>");
|
||||
}
|
||||
|
||||
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, "</body></html>");
|
||||
writeLine(os, "</div>");
|
||||
writeLine(os, "</body></html>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue