diff options
author | Artur Signell <artur@vaadin.com> | 2013-04-04 20:10:58 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-04-05 07:00:36 +0000 |
commit | e09a33d0135f6ca34cf7ee98cafa61e4925f4b4e (patch) | |
tree | b08b976d8b79538b318e65014a54adb754981ee4 | |
parent | 9b7b7edc5f54c6e33defed41dc4874df52496247 (diff) | |
download | vaadin-framework-e09a33d0135f6ca34cf7ee98cafa61e4925f4b4e.tar.gz vaadin-framework-e09a33d0135f6ca34cf7ee98cafa61e4925f4b4e.zip |
Improved logging to be able to debug push related problems (#111)
Change-Id: I630f453891a8a43a4e8ee8d796c9b2c2e0b97254
-rw-r--r-- | client/src/com/vaadin/client/communication/PushConnection.java | 91 |
1 files changed, 81 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/communication/PushConnection.java b/client/src/com/vaadin/client/communication/PushConnection.java index f87ddf430a..ca1185b028 100644 --- a/client/src/com/vaadin/client/communication/PushConnection.java +++ b/client/src/com/vaadin/client/communication/PushConnection.java @@ -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); }-*/; |