From 251853dce1e79eceae153ff7a374533b1564abde Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 24 Feb 2015 00:41:15 +0200 Subject: [PATCH] Disconnect push after application has been stopped (#13248) Change-Id: I4b8ca76a530453ee95ff88a1a4bbe3fa7a7958d4 --- .../AtmospherePushConnection.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java index a3a8caa1b4..787da9bc6f 100644 --- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java @@ -24,6 +24,8 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Window.Location; import com.vaadin.client.ApplicationConfiguration; import com.vaadin.client.ApplicationConnection; +import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; +import com.vaadin.client.ApplicationConnection.ApplicationStoppedHandler; import com.vaadin.client.ApplicationConnection.CommunicationErrorHandler; import com.vaadin.client.ResourceLoader; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; @@ -152,6 +154,25 @@ public class AtmospherePushConnection implements PushConnection { this.connection = connection; this.errorHandler = errorHandler; + connection.addHandler(ApplicationStoppedEvent.TYPE, + new ApplicationStoppedHandler() { + + @Override + public void onApplicationStopped( + ApplicationStoppedEvent event) { + if (state == State.DISCONNECT_PENDING + || state == State.DISCONNECTED) { + return; + } + + disconnect(new Command() { + @Override + public void execute() { + } + }); + + } + }); config = createConfig(); String debugParameter = Location.getParameter("debug"); if ("push".equals(debugParameter)) { @@ -324,14 +345,6 @@ 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() { - } - }); - } } /** -- 2.39.5