From 3e18cd61a2018b3750e5456c07eff8715b76ec46 Mon Sep 17 00:00:00 2001 From: wayerr Date: Tue, 21 Mar 2017 19:29:36 +0300 Subject: [PATCH] some improvements for #23 --- .../dm/cluman/ui/tty/TtyProxy.java | 27 ++++++++++++------- .../dm/cluman/ui/tty/WsTtyHandler.java | 6 ++++- .../src/main/resources/static/ui/tty.html | 4 +-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/TtyProxy.java b/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/TtyProxy.java index 6eac83fb..76493775 100644 --- a/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/TtyProxy.java +++ b/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/TtyProxy.java @@ -49,16 +49,21 @@ static TtyProxy get(WebSocketSession session) { return (TtyProxy) session.getAttributes().get(KEY); } - static void close(WebSocketSession session) { - TtyProxy tty = (TtyProxy) session.getAttributes().get(KEY); - if(tty != null) { - tty.close(); - } + void closeCausedBack() { + // split close method for easy resolve cause of closing + log.info("Close caused back of {}", this); + close(); + } + + void closeCausedFront() { + // split close method for easy resolve cause of closing + log.info("Close caused front of {}", this); + close(); } private void close() { - boolean removed = frontend.getAttributes().remove(KEY, this); - log.info("Close {}, attr removed: ", this, removed); + frontend.getAttributes().remove(KEY, this); + // usually this method called twice - at close frontend, and at close backend WebSocketSession localBackend; synchronized (backendLock) { localBackend = this.backend; @@ -77,7 +82,8 @@ void toBackend(WebSocketMessage message) { } try { if(!localBackend.isOpen()) { - close(); + log.warn("Message to closed backend, {}", this); + closeCausedBack(); return; } localBackend.sendMessage(message); @@ -98,7 +104,8 @@ public void afterConnectionEstablished(WebSocketSession session) { public void handleMessage(WebSocketSession session, WebSocketMessage message) { try { if(!frontend.isOpen()) { - close(); + log.warn("Message to closed frontend, {}", this); + closeCausedFront(); return; } frontend.sendMessage(message); @@ -114,7 +121,7 @@ public void handleTransportError(WebSocketSession session, Throwable exception) @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) { - close(); + closeCausedBack(); } @Override diff --git a/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/WsTtyHandler.java b/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/WsTtyHandler.java index 73b87159..247f223e 100644 --- a/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/WsTtyHandler.java +++ b/cluster-manager/src/main/java/com/codeabovelab/dm/cluman/ui/tty/WsTtyHandler.java @@ -107,7 +107,11 @@ public void handleTransportError(WebSocketSession session, Throwable exception) @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) { - TtyProxy.close(session); + TtyProxy tty = TtyProxy.get(session); + if(tty != null) { + tty.closeCausedFront(); + } + } @Override diff --git a/cluster-manager/src/main/resources/static/ui/tty.html b/cluster-manager/src/main/resources/static/ui/tty.html index 628853f4..a4d2e475 100644 --- a/cluster-manager/src/main/resources/static/ui/tty.html +++ b/cluster-manager/src/main/resources/static/ui/tty.html @@ -8,7 +8,7 @@ var ws; //websocket window.onload = function() { term = new Terminal(); - term.open(document.getElementById('#terminal')); + term.open(document.getElementById('terminal')); } function openContainer() { if(ws) { @@ -25,6 +25,6 @@ -
+
\ No newline at end of file