You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2019/08/14 12:16:46 UTC
[wicket] branch master updated: WICKET-6692 Page deserialization on
websocket close - possible performance issue
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/master by this push:
new 0b2caa8 WICKET-6692 Page deserialization on websocket close - possible performance issue
0b2caa8 is described below
commit 0b2caa8dfae6cde4e521b708c676e6611ec99b34
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Wed Aug 14 15:15:09 2019 +0300
WICKET-6692 Page deserialization on websocket close - possible performance issue
Introduce WebSocketSettings#setNotifyOnCloseEvent(Function<Integer, Boolean>) that can be used to decide whether to call #broadcastMessage() for close events.
(cherry picked from commit 4425c508d105481da85bbfc8dbee4bf88f62caa4)
---
.../apache/wicket/protocol/ws/WebSocketSettings.java | 18 +++++++++++++++++-
.../protocol/ws/api/AbstractWebSocketProcessor.java | 4 +++-
.../wicket/protocol/ws/javax/WicketEndpoint.java | 8 +++++++-
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java
index 0a30d01..d6967a6 100644
--- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java
+++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java
@@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
/**
* Web Socket related settings.
@@ -49,7 +50,6 @@ import java.util.concurrent.atomic.AtomicReference;
*/
public class WebSocketSettings
{
-
private static final Logger LOG = LoggerFactory.getLogger(WebSocketSettings.class);
private static final MetaDataKey<WebSocketSettings> KEY = new MetaDataKey<>()
@@ -133,6 +133,22 @@ public class WebSocketSettings
private IWebSocketConnectionFilter connectionFilter;
/**
+ * A function that decides whether to notify the page/resource on
+ * web socket connection closed event.
+ * The page notification leads to deserialization of the page instance from
+ * the page store and sometimes this is not wanted.
+ */
+ private Function<Integer, Boolean> notifyOnCloseEvent = (code) -> true;
+
+ public boolean shouldNotifyOnCloseEvent(int closeCode) {
+ return notifyOnCloseEvent == null || notifyOnCloseEvent.apply(closeCode);
+ }
+
+ public void setNotifyOnCloseEvent(Function<Integer, Boolean> notifyOnCloseEvent) {
+ this.notifyOnCloseEvent = notifyOnCloseEvent;
+ }
+
+ /**
* Set the executor for processing websocket push messages broadcasted to all sessions.
* Default executor does all the processing in the caller thread. Using a proper thread pool is adviced
* for applications that send push events from ajax calls to avoid page level deadlocks.
diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
index 1a86128..2505278 100644
--- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
+++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
@@ -185,7 +185,9 @@ public abstract class AbstractWebSocketProcessor implements IWebSocketProcessor
public void onClose(int closeCode, String message)
{
IKey key = getRegistryKey();
- broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key, closeCode, message));
+ if (webSocketSettings.shouldNotifyOnCloseEvent(closeCode)) {
+ broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key, closeCode, message));
+ }
connectionRegistry.removeConnection(getApplication(), getSessionId(), key);
}
diff --git a/wicket-native-websocket/wicket-native-websocket-javax/src/main/java/org/apache/wicket/protocol/ws/javax/WicketEndpoint.java b/wicket-native-websocket/wicket-native-websocket-javax/src/main/java/org/apache/wicket/protocol/ws/javax/WicketEndpoint.java
index 3447617..e93cf86 100644
--- a/wicket-native-websocket/wicket-native-websocket-javax/src/main/java/org/apache/wicket/protocol/ws/javax/WicketEndpoint.java
+++ b/wicket-native-websocket/wicket-native-websocket-javax/src/main/java/org/apache/wicket/protocol/ws/javax/WicketEndpoint.java
@@ -74,9 +74,15 @@ public class WicketEndpoint extends Endpoint
{
super.onClose(session, closeReason);
+ final int closeCode = closeReason.getCloseCode().getCode();
+ final String reasonPhrase = closeReason.getReasonPhrase();
+
+ LOG.debug("Web Socket connection with id '{}' has been closed with code '{}' and reason: {}",
+ session.getId(), closeCode, reasonPhrase);
+
if (isApplicationAlive())
{
- javaxWebSocketProcessor.onClose(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase());
+ javaxWebSocketProcessor.onClose(closeCode, reasonPhrase);
}
}