]> source.dussan.org Git - vaadin-framework.git/commitdiff
Improved logging to be able to debug push related problems (#111)
authorArtur Signell <artur@vaadin.com>
Thu, 4 Apr 2013 17:10:58 +0000 (20:10 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 5 Apr 2013 07:00:36 +0000 (07:00 +0000)
Change-Id: I630f453891a8a43a4e8ee8d796c9b2c2e0b97254

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

index f87ddf430a09db4822544d123490cace0d7891a7..ca1185b0282d3ab921347fd26a4348d4f0c4a6e0 100644 (file)
@@ -42,7 +42,7 @@ public class PushConnection {
 
     private boolean connected = false;
 
-    private JavaScriptObject config = createConfig();
+    private AtmosphereConfiguration config = createConfig();
 
     public PushConnection() {
     }
@@ -50,11 +50,11 @@ public class PushConnection {
     /**
      * Two-phase construction to allow using GWT.create()
      * 
-     * @param ac
+     * @param connection
      *            The ApplicationConnection
      */
-    public void init(ApplicationConnection ac) {
-        this.connection = ac;
+    public void init(ApplicationConnection connection) {
+        this.connection = connection;
     }
 
     public void connect(String uri) {
@@ -85,7 +85,8 @@ public class PushConnection {
         messageQueue.clear();
     }
 
-    protected void onMessage(String message) {
+    protected void onMessage(AtmosphereResponse response) {
+        String message = response.getResponseBody();
         if (message.startsWith("for(;;);")) {
             VConsole.log("Received Atmosphere message: " + message);
             // "for(;;);[{json}]" -> "{json}"
@@ -94,11 +95,79 @@ public class PushConnection {
         }
     }
 
+    /**
+     * Called if the transport mechanism cannot be used and the fallback will be
+     * tried
+     */
+    protected void onTransportFailure() {
+        VConsole.log("Connection using primary method ("
+                + config.getTransport() + ") failed. Falling back to "
+                + config.getFallbackTransport());
+    }
+
+    /**
+     * Called if the push connection fails. Atmosphere will automatically retry
+     * the connection until successful.
+     * 
+     */
     protected void onError() {
-        VConsole.error("Atmosphere connection failed!");
+        VConsole.error("Atmosphere connection using " + config.getTransport()
+                + " failed!");
+    }
+
+    public static abstract class AbstractJSO extends JavaScriptObject {
+        protected AbstractJSO() {
+
+        }
+
+        protected final native String getStringValue(String key)
+        /*-{
+           return this[key];
+         }-*/;
+
+        protected final native int getIntValue(String key)
+        /*-{
+           return this[key];
+         }-*/;
+
     }
 
-    private static native JavaScriptObject createConfig()
+    public static class AtmosphereConfiguration extends AbstractJSO {
+
+        protected AtmosphereConfiguration() {
+            super();
+        }
+
+        public final String getTransport() {
+            return getStringValue("transport");
+        }
+
+        public final String getFallbackTransport() {
+            return getStringValue("fallbackTransport");
+        }
+    }
+
+    public static class AtmosphereResponse extends AbstractJSO {
+
+        protected AtmosphereResponse() {
+
+        }
+
+        public final String getResponseBody() {
+            return getStringValue("responseBody");
+        }
+
+        public final String getState() {
+            return getStringValue("state");
+        }
+
+        public final String getError() {
+            return getStringValue("error");
+        }
+
+    }
+
+    private static native AtmosphereConfiguration createConfig()
     /*-{
         return {
             transport: 'websocket',
@@ -119,12 +188,14 @@ public class PushConnection {
             self.@com.vaadin.client.communication.PushConnection::onOpen()();
         });
         config.onMessage = $entry(function(response) {
-            self.@com.vaadin.client.communication.PushConnection::onMessage(*)(response.responseBody);
+            self.@com.vaadin.client.communication.PushConnection::onMessage(*)(response);
         });
         config.onError = $entry(function(response) {
-            self.@com.vaadin.client.communication.PushConnection::onError()();
+            self.@com.vaadin.client.communication.PushConnection::onError()(response);
+        });
+        config.onTransportFailure = $entry(function(reason,request) {
+            self.@com.vaadin.client.communication.PushConnection::onTransportFailure(*)(reason);
         });
-                                 
         return $wnd.atmosphere.subscribe(config);
     }-*/;