summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/PushConfiguration.java
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2014-01-22 15:29:25 +0200
committerArtur Signell <artur@vaadin.com>2014-01-31 09:21:19 +0000
commit3c5644c4a3e0484b7e65a2852d9cedeeab167419 (patch)
tree421bbbb28237c89ab439c36499a0a0663f72a0b5 /server/src/com/vaadin/ui/PushConfiguration.java
parentf52c25fbb87d4c872304323d8ab42ba6d3ea0497 (diff)
downloadvaadin-framework-3c5644c4a3e0484b7e65a2852d9cedeeab167419.tar.gz
vaadin-framework-3c5644c4a3e0484b7e65a2852d9cedeeab167419.zip
Refactor PushConnection handling (#13223)
UIs now always have a PushConnection object if push is enabled, and push reconnections do not create and set a new instance. PushConnection.push can always be called; it internally handles deferring the push until (re)connection if it is currently disconnected. This is very desirable when using long polling, as it reconnects after each push. Change-Id: I478748cc940da86f34a5f55266f6b325682d4585
Diffstat (limited to 'server/src/com/vaadin/ui/PushConfiguration.java')
-rw-r--r--server/src/com/vaadin/ui/PushConfiguration.java42
1 files changed, 27 insertions, 15 deletions
diff --git a/server/src/com/vaadin/ui/PushConfiguration.java b/server/src/com/vaadin/ui/PushConfiguration.java
index a592b39bef..49738c5aff 100644
--- a/server/src/com/vaadin/ui/PushConfiguration.java
+++ b/server/src/com/vaadin/ui/PushConfiguration.java
@@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Collections;
import com.vaadin.server.VaadinSession;
+import com.vaadin.server.communication.AtmospherePushConnection;
import com.vaadin.shared.communication.PushMode;
import com.vaadin.shared.ui.ui.Transport;
import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
@@ -170,20 +171,32 @@ class PushConfigurationImpl implements PushConfiguration {
throw new IllegalArgumentException("Push mode cannot be null");
}
- if (pushMode.isEnabled()) {
- VaadinSession session = ui.getSession();
- if (session != null && !session.getService().ensurePushAvailable()) {
- throw new IllegalStateException(
- "Push is not available. See previous log messages for more information.");
- }
+ VaadinSession session = ui.getSession();
+
+ if (session == null) {
+ throw new UIDetachedException(
+ "Cannot set the push mode for a detached UI");
+ }
+
+ assert session.hasLock();
+
+ if (pushMode.isEnabled() && !session.getService().ensurePushAvailable()) {
+ throw new IllegalStateException(
+ "Push is not available. See previous log messages for more information.");
}
- /*
- * Client-side will open a new connection or disconnect the old
- * connection, so there's nothing more to do on the server at this
- * point.
- */
- getState().mode = pushMode;
+ PushMode oldMode = getState().mode;
+ if (oldMode != pushMode) {
+ getState().mode = pushMode;
+
+ if (!oldMode.isEnabled() && pushMode.isEnabled()) {
+ // The push connection is initially in a disconnected state;
+ // the client will establish the connection
+ ui.setPushConnection(new AtmospherePushConnection(ui));
+ }
+ // Nothing to do here if disabling push;
+ // the client will close the connection
+ }
}
/*
@@ -274,9 +287,8 @@ class PushConfigurationImpl implements PushConfiguration {
@Override
public Collection<String> getParameterNames() {
- return Collections
- .unmodifiableCollection(ui.getState(false).pushConfiguration.parameters
- .keySet());
+ return Collections.unmodifiableCollection(getState(false).parameters
+ .keySet());
}
}