Skip to content

Commit

Permalink
[ZEPPELIN-1480] rework websocket sending to prevent partial frontend …
Browse files Browse the repository at this point in the history
…hangup (apache#4800)

* [ZEPPELIN-1480] synchronize websocket sync to prevent issues with blocked websockets due to multithreading

* [ZEPPELIN-1480] use async call to websocket for sending

also add debug logging to the class

* [ZEPPELIN-1480] improve error logging

* [ZEPPELIN-1480] re-add license text

* [ZEPPELIN-1480] remove debug logging from getters

* [ZEPPELIN-1480] fix indentation
  • Loading branch information
johannesschillinger-dm authored Sep 17, 2024
1 parent 7ae8980 commit a985c56
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.zeppelin.utils.ServerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Map;
Expand All @@ -28,6 +30,8 @@
* Notebook websocket.
*/
public class NotebookSocket {
private static final Logger LOGGER = LoggerFactory.getLogger(NotebookSocket.class);

private Session session;
private Map<String, Object> headers;
private String user;
Expand All @@ -36,21 +40,27 @@ public NotebookSocket(Session session, Map<String, Object> headers) {
this.session = session;
this.headers = headers;
this.user = StringUtils.EMPTY;
LOGGER.debug("NotebookSocket created for session: {}", session.getId());
}

public String getHeader(String key) {
return String.valueOf(headers.get(key));
}

public void send(String serializeMessage) throws IOException {
session.getBasicRemote().sendText(serializeMessage);
session.getAsyncRemote().sendText(serializeMessage, result -> {
if (result.getException() != null) {
LOGGER.error("Failed to send async message for User {} in Session {}: {}", this.user, this.session.getId(), result.getException());
}
});
}

public String getUser() {
return user;
}

public void setUser(String user) {
LOGGER.debug("Setting user: {}", user);
this.user = user;
}

Expand Down

0 comments on commit a985c56

Please sign in to comment.