diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2013-06-12 14:16:57 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-12 14:51:27 +0000 |
commit | 15b217d26278471ee713f46340981c862e3839d2 (patch) | |
tree | aab44321fef486b7868080ef4372475065defb68 /client | |
parent | 5f66766f02b86aeda0089b8bb15da5b2c6e40715 (diff) | |
download | vaadin-framework-15b217d26278471ee713f46340981c862e3839d2.tar.gz vaadin-framework-15b217d26278471ee713f46340981c862e3839d2.zip |
Handle push disconnections and reconnections more reliably (#11831, #11922)
Client-side:
* Call onOpen() also after a successful reconnection
* Reliably call onClose() and try to reconnect after disconnection
* Don't try to reconnect if !isApplicationRunning() after push
* Queue messages while trying to reconnect (state CONNECT_PENDING)
Server-side:
* Implement AtmosphereResourceEventListener.onDisconnect()
* Push marked as pending until client reconnects (if ever)
Change-Id: I1783eb72eb7005b07cae786d8ec8371da3903108
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/communication/AtmospherePushConnection.java | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java index 506716040d..20ccd45173 100644 --- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java @@ -292,6 +292,14 @@ public class AtmospherePushConnection implements PushConnection { message = message.substring(9, message.length() - 1); connection.handlePushMessage(message); } + + if (!connection.isApplicationRunning()) { + disconnect(new Command() { + @Override + public void execute() { + } + }); + } } /** @@ -309,9 +317,21 @@ public class AtmospherePushConnection implements PushConnection { * the connection until successful. * */ - protected void onError() { - VConsole.error("Push connection using " + getConfig().getTransport() - + " failed!"); + protected void onError(AtmosphereResponse response) { + state = State.DISCONNECTED; + errorHandler.onError("Push connection using " + + getConfig().getTransport() + " failed!", + response.getStatusCode()); + } + + protected void onClose(AtmosphereResponse response) { + VConsole.log("Push connection closed, awaiting reconnection"); + state = State.CONNECT_PENDING; + } + + protected void onReconnect(JavaScriptObject request, + final AtmosphereResponse response) { + VConsole.log("Reopening push connection"); } public static abstract class AbstractJSO extends JavaScriptObject { @@ -370,6 +390,10 @@ public class AtmospherePushConnection implements PushConnection { } + public final int getStatusCode() { + return getIntValue("status"); + } + public final String getResponseBody() { return getStringValue("responseBody"); } @@ -394,7 +418,7 @@ public class AtmospherePushConnection implements PushConnection { transport: 'websocket', fallbackTransport: 'streaming', contentType: 'application/json; charset=UTF-8', - reconnectInterval: '5000', + reconnectInterval: 5000, maxReconnectOnClose: 10000000, trackMessageLength: true, messageDelimiter: String.fromCharCode(@com.vaadin.shared.communication.PushConstants::MESSAGE_DELIMITER) @@ -414,11 +438,17 @@ public class AtmospherePushConnection implements PushConnection { self.@com.vaadin.client.communication.AtmospherePushConnection::onMessage(*)(response); }); config.onError = $entry(function(response) { - self.@com.vaadin.client.communication.AtmospherePushConnection::onError()(response); + self.@com.vaadin.client.communication.AtmospherePushConnection::onError(*)(response); }); config.onTransportFailure = $entry(function(reason,request) { self.@com.vaadin.client.communication.AtmospherePushConnection::onTransportFailure(*)(reason); }); + config.onClose = $entry(function(response) { + self.@com.vaadin.client.communication.AtmospherePushConnection::onClose(*)(response); + }); + config.onReconnect = $entry(function(request, response) { + self.@com.vaadin.client.communication.AtmospherePushConnection::onReconnect(*)(request, response); + }); return $wnd.jQueryVaadin.atmosphere.subscribe(config); }-*/; |