Browse Source

Support suspend timeout for long polling (#18550)

Change-Id: I1dc35f060b255baff4d28a815414836d4852218b
tags/7.6.0.alpha5
Artur Signell 8 years ago
parent
commit
f3f3a74d57

+ 15
- 0
WebContent/WEB-INF/web.xml View File

<async-supported>true</async-supported> <async-supported>true</async-supported>
</servlet> </servlet>


<servlet>
<servlet-name>VaadinApplicationRunnerWithPushTimeout</servlet-name>
<servlet-class>com.vaadin.launcher.ApplicationRunnerServlet</servlet-class>
<init-param>
<param-name>pushLongPollingSuspendTimeout</param-name>
<param-value>10000</param-value>
</init-param>
<async-supported>true</async-supported>
</servlet>

<!-- For testing GAE - the deployment script changes this to use GAEVaadinServlet --> <!-- For testing GAE - the deployment script changes this to use GAEVaadinServlet -->
<servlet> <servlet>
<servlet-name>IntegrationTest</servlet-name> <servlet-name>IntegrationTest</servlet-name>
<url-pattern>/run-push/*</url-pattern> <url-pattern>/run-push/*</url-pattern>
</servlet-mapping> </servlet-mapping>


<servlet-mapping>
<servlet-name>VaadinApplicationRunnerWithPushTimeout</servlet-name>
<url-pattern>/run-push-timeout/*</url-pattern>
</servlet-mapping>

<servlet-mapping> <servlet-mapping>
<servlet-name>VaadinApplicationRunnerWithJSR356</servlet-name> <servlet-name>VaadinApplicationRunnerWithJSR356</servlet-name>
<url-pattern>/run-jsr356/*</url-pattern> <url-pattern>/run-jsr356/*</url-pattern>

+ 1
- 0
server/src/com/vaadin/server/Constants.java View File

static final String SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING = "legacyPropertyToString"; static final String SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING = "legacyPropertyToString";
static final String SERVLET_PARAMETER_SYNC_ID_CHECK = "syncIdCheck"; static final String SERVLET_PARAMETER_SYNC_ID_CHECK = "syncIdCheck";
static final String SERVLET_PARAMETER_SENDURLSASPARAMETERS = "sendUrlsAsParameters"; static final String SERVLET_PARAMETER_SENDURLSASPARAMETERS = "sendUrlsAsParameters";
static final String SERVLET_PARAMETER_PUSH_SUSPEND_TIMEOUT_LONGPOLLING = "pushLongPollingSuspendTimeout";


// Configurable parameter names // Configurable parameter names
static final String PARAMETER_VAADIN_RESOURCES = "Resources"; static final String PARAMETER_VAADIN_RESOURCES = "Resources";

+ 40
- 1
server/src/com/vaadin/server/communication/PushHandler.java View File

*/ */
public class PushHandler { public class PushHandler {


private int longPollingSuspendTimeout = -1;

/** /**
* Callback interface used internally to process an event with the * Callback interface used internally to process an event with the
* corresponding UI properly locked. * corresponding UI properly locked.
return; return;
} }


resource.suspend();
suspend(resource);


AtmospherePushConnection connection = getConnectionForUI(ui); AtmospherePushConnection connection = getConnectionForUI(ui);
assert (connection != null); assert (connection != null);
this.service = service; this.service = service;
} }


/**
* 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. * Find the UI for the atmosphere resource, lock it and invoke the callback.
* *
resource.transport() == TRANSPORT.WEBSOCKET); 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;
}
} }

+ 23
- 2
server/src/com/vaadin/server/communication/PushRequestHandler.java View File

final ServletConfig vaadinServletConfig = service.getServlet() final ServletConfig vaadinServletConfig = service.getServlet()
.getServletConfig(); .getServletConfig();


pushHandler = new PushHandler(service);
pushHandler = createPushHandler(service);


atmosphere = getPreInitializedAtmosphere(vaadinServletConfig); atmosphere = getPreInitializedAtmosphere(vaadinServletConfig);
if (atmosphere == null) { if (atmosphere == null) {
"Using pre-initialized Atmosphere for servlet " "Using pre-initialized Atmosphere for servlet "
+ vaadinServletConfig.getServletName()); + vaadinServletConfig.getServletName());
} }

pushHandler
.setLongPollingSuspendTimeout(atmosphere
.getAtmosphereConfig()
.getInitParameter(
com.vaadin.server.Constants.SERVLET_PARAMETER_PUSH_SUSPEND_TIMEOUT_LONGPOLLING,
-1));
for (AtmosphereHandlerWrapper handlerWrapper : atmosphere for (AtmosphereHandlerWrapper handlerWrapper : atmosphere
.getAtmosphereHandlers().values()) { .getAtmosphereHandlers().values()) {
AtmosphereHandler handler = handlerWrapper.atmosphereHandler; AtmosphereHandler handler = handlerWrapper.atmosphereHandler;
} }
} }


/**
* 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() { private static final Logger getLogger() {
return Logger.getLogger(PushRequestHandler.class.getName()); return Logger.getLogger(PushRequestHandler.class.getName());
} }

+ 14
- 0
uitest/src/com/vaadin/tests/push/BasicPushLongPollingTest.java View File

*/ */
package com.vaadin.tests.push; package com.vaadin.tests.push;


import org.junit.Test;

public class BasicPushLongPollingTest extends BasicPushTest { public class BasicPushLongPollingTest extends BasicPushTest {

@Test
public void pushAfterServerTimeout() throws InterruptedException {
getDriver().get(
getTestUrl().replace("/run/", "/run-push-timeout/")
+ "?debug=push");
sleep(11000); // Wait for server timeout (10s)

getServerCounterStartButton().click();
waitUntilServerCounterChanges();
}

} }

+ 4
- 4
uitest/src/com/vaadin/tests/push/BasicPushTest.java View File

return Integer.parseInt(clientCounterElem.getText()); return Integer.parseInt(clientCounterElem.getText());
} }


private WebElement getIncrementButton() {
protected WebElement getIncrementButton() {
return getIncrementButton(this); return getIncrementButton(this);
} }


private WebElement getServerCounterStartButton() {
protected WebElement getServerCounterStartButton() {
return getServerCounterStartButton(this); return getServerCounterStartButton(this);
} }


return t.vaadinElementById(BasicPush.INCREMENT_BUTTON_ID); return t.vaadinElementById(BasicPush.INCREMENT_BUTTON_ID);
} }


private void waitUntilClientCounterChanges(final int expectedValue) {
protected void waitUntilClientCounterChanges(final int expectedValue) {
waitUntil(new ExpectedCondition<Boolean>() { waitUntil(new ExpectedCondition<Boolean>() {


@Override @Override
}, 10); }, 10);
} }


private void waitUntilServerCounterChanges() {
protected void waitUntilServerCounterChanges() {
final int counter = BasicPushTest.getServerCounter(this); final int counter = BasicPushTest.getServerCounter(this);
waitUntil(new ExpectedCondition<Boolean>() { waitUntil(new ExpectedCondition<Boolean>() {



+ 1
- 1
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java View File

* @return * @return
*/ */
public WebElement vaadinElementById(String id) { public WebElement vaadinElementById(String id) {
return driver.findElement(vaadinLocatorById(id));
return driver.findElement(By.id(id));
} }


/** /**

Loading…
Cancel
Save