From edca4095d2e75d73f9d6a5acb2da9009129b4db2 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 5 Jun 2013 14:27:09 +0300 Subject: Allow customizing client-side push config on server side (#11867) Change-Id: I212067aa0bd04e3e73844ef57963b5622291986a --- client/src/com/vaadin/client/ApplicationConnection.java | 7 +++++-- .../client/communication/AtmospherePushConnection.java | 15 ++++++++++----- .../com/vaadin/client/communication/PushConnection.java | 2 ++ client/src/com/vaadin/client/ui/ui/UIConnector.java | 5 +++-- 4 files changed, 20 insertions(+), 9 deletions(-) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index a3279e5631..ac058b5536 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -95,6 +95,7 @@ import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; /** * This is the client side communication "engine", managing client-server @@ -3359,9 +3360,11 @@ public class ApplicationConnection { * false to disable the push connection. */ public void setPushEnabled(boolean enabled) { + final PushConfigurationState pushState = uIConnector.getState().pushConfiguration; + if (enabled && push == null) { push = GWT.create(PushConnection.class); - push.init(this, new CommunicationErrorHandler() { + push.init(this, pushState, new CommunicationErrorHandler() { @Override public boolean onError(String details, int statusCode) { showCommunicationError(details, statusCode); @@ -3378,7 +3381,7 @@ public class ApplicationConnection { * the old connection to disconnect, now is the right time * to open a new connection */ - if (uIConnector.getState().pushMode.isEnabled()) { + if (pushState.mode.isEnabled()) { setPushEnabled(true); } diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java index 997e84145c..f7936f8717 100644 --- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java @@ -30,6 +30,7 @@ import com.vaadin.client.VConsole; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.communication.PushConstants; import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; /** * The default {@link PushConnection} implementation that uses Atmosphere for @@ -133,15 +134,22 @@ public class AtmospherePushConnection implements PushConnection { * (non-Javadoc) * * @see - * com.vaadin.client.communication.PushConenction#init(com.vaadin.client - * .ApplicationConnection) + * com.vaadin.client.communication.PushConnection#init(ApplicationConnection + * , Map, CommunicationErrorHandler) */ @Override public void init(final ApplicationConnection connection, + final PushConfigurationState pushConfiguration, CommunicationErrorHandler errorHandler) { this.connection = connection; this.errorHandler = errorHandler; + config = createConfig(); + for (String param : pushConfiguration.parameters.keySet()) { + config.setStringValue(param, + pushConfiguration.parameters.get(param)); + } + runWhenAtmosphereLoaded(new Command() { @Override public void execute() { @@ -216,9 +224,6 @@ public class AtmospherePushConnection implements PushConnection { } protected AtmosphereConfiguration getConfig() { - if (config == null) { - config = createConfig(); - } return config; } diff --git a/client/src/com/vaadin/client/communication/PushConnection.java b/client/src/com/vaadin/client/communication/PushConnection.java index a4a3bbc0cc..bc2af98f1a 100644 --- a/client/src/com/vaadin/client/communication/PushConnection.java +++ b/client/src/com/vaadin/client/communication/PushConnection.java @@ -19,6 +19,7 @@ package com.vaadin.client.communication; import com.google.gwt.user.client.Command; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ApplicationConnection.CommunicationErrorHandler; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; /** * Represents the client-side endpoint of a bidirectional ("push") communication @@ -39,6 +40,7 @@ public interface PushConnection { * The ApplicationConnection */ public void init(ApplicationConnection connection, + PushConfigurationState pushConfigurationState, CommunicationErrorHandler errorHandler); /** diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 1c2c6ddeb8..45b0a7ab9d 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -644,8 +644,9 @@ public class UIConnector extends AbstractSingleComponentContainerConnector configurePolling(); } - if (stateChangeEvent.hasPropertyChanged("pushMode")) { - getConnection().setPushEnabled(getState().pushMode.isEnabled()); + if (stateChangeEvent.hasPropertyChanged("pushConfiguration")) { + getConnection().setPushEnabled( + getState().pushConfiguration.mode.isEnabled()); } if (stateChangeEvent.hasPropertyChanged("overlayContainerLabel")) { -- cgit v1.2.3