summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2013-06-12 14:16:57 +0300
committerVaadin Code Review <review@vaadin.com>2013-06-12 14:51:27 +0000
commit15b217d26278471ee713f46340981c862e3839d2 (patch)
treeaab44321fef486b7868080ef4372475065defb68 /server
parent5f66766f02b86aeda0089b8bb15da5b2c6e40715 (diff)
downloadvaadin-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 'server')
-rw-r--r--server/src/com/vaadin/server/communication/PushHandler.java30
1 files changed, 23 insertions, 7 deletions
diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java
index 6b853063a7..1c50f79349 100644
--- a/server/src/com/vaadin/server/communication/PushHandler.java
+++ b/server/src/com/vaadin/server/communication/PushHandler.java
@@ -28,6 +28,7 @@ import org.atmosphere.cpr.AtmosphereRequest;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResource.TRANSPORT;
import org.atmosphere.cpr.AtmosphereResourceEvent;
+import org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter;
import org.json.JSONException;
import com.vaadin.server.LegacyCommunicationManager.InvalidUIDLSecurityKeyException;
@@ -51,7 +52,8 @@ import com.vaadin.ui.UI;
* @author Vaadin Ltd
* @since 7.1
*/
-public class PushHandler implements AtmosphereHandler {
+public class PushHandler extends AtmosphereResourceEventListenerAdapter
+ implements AtmosphereHandler {
/**
* Callback interface used internally to process an event with the
@@ -67,12 +69,15 @@ public class PushHandler implements AtmosphereHandler {
* open by calling resource.suspend(). If there is a pending push, send it
* now.
*/
- private static PushEventCallback establishCallback = new PushEventCallback() {
+ private final PushEventCallback establishCallback = new PushEventCallback() {
@Override
public void run(AtmosphereResource resource, UI ui) throws IOException {
getLogger().log(Level.FINER,
"New push connection with transport {0}",
resource.transport());
+
+ resource.addEventListener(PushHandler.this);
+
resource.getResponse().setContentType("text/plain; charset=UTF-8");
VaadinSession session = ui.getSession();
@@ -122,9 +127,12 @@ public class PushHandler implements AtmosphereHandler {
* the request and send changed UI state via the push channel (we do not
* respond to the request directly.)
*/
- private static PushEventCallback receiveCallback = new PushEventCallback() {
+ private final PushEventCallback receiveCallback = new PushEventCallback() {
@Override
public void run(AtmosphereResource resource, UI ui) throws IOException {
+ getLogger().log(Level.FINER, "Received message from resource {0}",
+ resource.uuid());
+
AtmosphereRequest req = resource.getRequest();
AtmospherePushConnection connection = getConnectionForUI(ui);
@@ -167,7 +175,7 @@ public class PushHandler implements AtmosphereHandler {
/**
* Callback used when a connection is closed by the client.
*/
- PushEventCallback disconnectCallback = new PushEventCallback() {
+ private final PushEventCallback disconnectCallback = new PushEventCallback() {
@Override
public void run(AtmosphereResource resource, UI ui) throws IOException {
PushMode pushMode = ui.getPushConfiguration().getPushMode();
@@ -187,7 +195,7 @@ public class PushHandler implements AtmosphereHandler {
* mode has been set to disabled, just clean up some stuff
* and be done with it
*/
- getLogger().log(Level.FINEST,
+ getLogger().log(Level.FINER,
"Connection closed for resource {0}", id);
} else {
/*
@@ -195,7 +203,7 @@ public class PushHandler implements AtmosphereHandler {
* tab.
*/
getLogger()
- .log(Level.FINE,
+ .log(Level.FINER,
"Connection unexpectedly closed for resource {0} with transport {1}",
new Object[] { id, resource.transport() });
}
@@ -316,7 +324,8 @@ public class PushHandler implements AtmosphereHandler {
String id = resource.uuid();
if (event.isCancelled()) {
- callWithUi(resource, disconnectCallback);
+ // Disconnected for whatever reason, handle in onDisconnect() as
+ // it's more reliable
} else if (event.isResuming()) {
// A connection that was suspended earlier was resumed (committed to
// the client.) Should only happen if the transport is JSONP or
@@ -352,6 +361,13 @@ public class PushHandler implements AtmosphereHandler {
}
@Override
+ public void onDisconnect(AtmosphereResourceEvent event) {
+ // Log event on trace level
+ super.onDisconnect(event);
+ callWithUi(event.getResource(), disconnectCallback);
+ }
+
+ @Override
public void destroy() {
}