]> source.dussan.org Git - vaadin-framework.git/commitdiff
Disconnect push after application has been stopped (#13248)
authorArtur Signell <artur@vaadin.com>
Mon, 23 Feb 2015 22:41:15 +0000 (00:41 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 2 Mar 2015 12:25:06 +0000 (12:25 +0000)
Change-Id: I4b8ca76a530453ee95ff88a1a4bbe3fa7a7958d4

client/src/com/vaadin/client/communication/AtmospherePushConnection.java

index a3a8caa1b42f29beb29337ea2da73f75c4eecde3..787da9bc6fd31a8747e7778d0c36d0453395a28f 100644 (file)
@@ -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() {
-                }
-            });
-        }
     }
 
     /**