From 15b217d26278471ee713f46340981c862e3839d2 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 12 Jun 2013 14:16:57 +0300 Subject: 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 --- .../communication/AtmospherePushConnection.java | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'client') 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); }-*/; -- cgit v1.2.3