aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-08-03 12:30:34 +0300
committerVaadin Code Review <review@vaadin.com>2015-09-03 08:27:51 +0000
commitf3f3a74d5779b5ff0270700a998b1b62c60a45b9 (patch)
tree6fbcc1482880f94fd9cffaf680d963910290a1ec /server
parent724f55912045f67ee77867c84554f2312e784e6e (diff)
downloadvaadin-framework-f3f3a74d5779b5ff0270700a998b1b62c60a45b9.tar.gz
vaadin-framework-f3f3a74d5779b5ff0270700a998b1b62c60a45b9.zip
Support suspend timeout for long polling (#18550)
Change-Id: I1dc35f060b255baff4d28a815414836d4852218b
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/Constants.java1
-rw-r--r--server/src/com/vaadin/server/communication/PushHandler.java41
-rw-r--r--server/src/com/vaadin/server/communication/PushRequestHandler.java25
3 files changed, 64 insertions, 3 deletions
diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java
index 5a0d852299..77a1a3134e 100644
--- a/server/src/com/vaadin/server/Constants.java
+++ b/server/src/com/vaadin/server/Constants.java
@@ -137,6 +137,7 @@ public interface Constants {
static final String SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING = "legacyPropertyToString";
static final String SERVLET_PARAMETER_SYNC_ID_CHECK = "syncIdCheck";
static final String SERVLET_PARAMETER_SENDURLSASPARAMETERS = "sendUrlsAsParameters";
+ static final String SERVLET_PARAMETER_PUSH_SUSPEND_TIMEOUT_LONGPOLLING = "pushLongPollingSuspendTimeout";
// Configurable parameter names
static final String PARAMETER_VAADIN_RESOURCES = "Resources";
diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java
index 01077c3f86..994415a0b4 100644
--- a/server/src/com/vaadin/server/communication/PushHandler.java
+++ b/server/src/com/vaadin/server/communication/PushHandler.java
@@ -55,6 +55,8 @@ import elemental.json.JsonException;
*/
public class PushHandler {
+ private int longPollingSuspendTimeout = -1;
+
/**
* Callback interface used internally to process an event with the
* corresponding UI properly locked.
@@ -107,7 +109,7 @@ public class PushHandler {
return;
}
- resource.suspend();
+ suspend(resource);
AtmospherePushConnection connection = getConnectionForUI(ui);
assert (connection != null);
@@ -174,6 +176,21 @@ public class PushHandler {
}
/**
+ * Suspends the given resource
+ *
+ * @since
+ * @param resource
+ * the resource to suspend
+ */
+ protected void suspend(AtmosphereResource resource) {
+ if (resource.transport() == TRANSPORT.LONG_POLLING) {
+ resource.suspend(getLongPollingSuspendTimeout());
+ } else {
+ resource.suspend(-1);
+ }
+ }
+
+ /**
* Find the UI for the atmosphere resource, lock it and invoke the callback.
*
* @param resource
@@ -493,4 +510,26 @@ public class PushHandler {
resource.transport() == TRANSPORT.WEBSOCKET);
}
+ /**
+ * Sets the timeout used for suspend calls when using long polling.
+ *
+ * If you are using a proxy with a defined idle timeout, set the suspend
+ * timeout to a value smaller than the proxy timeout so that the server is
+ * aware of a reconnect taking place.
+ *
+ * @param suspendTimeout
+ * the timeout to use for suspended AtmosphereResources
+ */
+ public void setLongPollingSuspendTimeout(int longPollingSuspendTimeout) {
+ this.longPollingSuspendTimeout = longPollingSuspendTimeout;
+ }
+
+ /**
+ * Gets the timeout used for suspend calls when using long polling.
+ *
+ * @return the timeout to use for suspended AtmosphereResources
+ */
+ public int getLongPollingSuspendTimeout() {
+ return longPollingSuspendTimeout;
+ }
}
diff --git a/server/src/com/vaadin/server/communication/PushRequestHandler.java b/server/src/com/vaadin/server/communication/PushRequestHandler.java
index c01c74e5cd..c44fcd9ef3 100644
--- a/server/src/com/vaadin/server/communication/PushRequestHandler.java
+++ b/server/src/com/vaadin/server/communication/PushRequestHandler.java
@@ -77,7 +77,7 @@ public class PushRequestHandler implements RequestHandler,
final ServletConfig vaadinServletConfig = service.getServlet()
.getServletConfig();
- pushHandler = new PushHandler(service);
+ pushHandler = createPushHandler(service);
atmosphere = getPreInitializedAtmosphere(vaadinServletConfig);
if (atmosphere == null) {
@@ -100,7 +100,12 @@ public class PushRequestHandler implements RequestHandler,
"Using pre-initialized Atmosphere for servlet "
+ vaadinServletConfig.getServletName());
}
-
+ pushHandler
+ .setLongPollingSuspendTimeout(atmosphere
+ .getAtmosphereConfig()
+ .getInitParameter(
+ com.vaadin.server.Constants.SERVLET_PARAMETER_PUSH_SUSPEND_TIMEOUT_LONGPOLLING,
+ -1));
for (AtmosphereHandlerWrapper handlerWrapper : atmosphere
.getAtmosphereHandlers().values()) {
AtmosphereHandler handler = handlerWrapper.atmosphereHandler;
@@ -113,6 +118,22 @@ public class PushRequestHandler implements RequestHandler,
}
}
+ /**
+ * Creates a push handler for this request handler.
+ * <p>
+ * Create your own request handler and override this method if you want to
+ * customize the {@link PushHandler}, e.g. to dynamically decide the suspend
+ * timeout.
+ *
+ * @since
+ * @param service
+ * the vaadin service
+ * @return the push handler to use for this service
+ */
+ protected PushHandler createPushHandler(VaadinServletService service) {
+ return new PushHandler(service);
+ }
+
private static final Logger getLogger() {
return Logger.getLogger(PushRequestHandler.class.getName());
}