Skip to content

Commit

Permalink
some improvements for #23
Browse files Browse the repository at this point in the history
  • Loading branch information
wayerr committed Mar 21, 2017
1 parent e5b9e1b commit 3e18cd6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -114,7 +121,7 @@ public void handleTransportError(WebSocketSession session, Throwable exception)

@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
close();
closeCausedBack();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cluster-manager/src/main/resources/static/ui/tty.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -25,6 +25,6 @@
</head>
<body>
<input id="containerId" type="text" /> <button onclick="openContainer()">connect</button>
<div id="terminal"></div>
<div id="terminal" style="font-family:monospace;"></div>
</body>
</html>

0 comments on commit 3e18cd6

Please sign in to comment.