diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2014-04-10 16:47:52 +0300 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2014-04-10 16:47:52 +0300 |
commit | ca90352bf4cb737512cfe01240fcf1e09283a0e3 (patch) | |
tree | bad89ddea5477541c7784f1706f56a2e1e2606fb /server | |
parent | a452badd69632d9159081755b7519ffb743fcb03 (diff) | |
parent | 3d0ff32bea81c3e3c64bd044276ff04a4f8555ed (diff) | |
download | vaadin-framework-ca90352bf4cb737512cfe01240fcf1e09283a0e3.tar.gz vaadin-framework-ca90352bf4cb737512cfe01240fcf1e09283a0e3.zip |
Merge commit '3d0ff32bea81c3e3c64bd044276ff04a4f8555ed'
Conflicts:
server/src/com/vaadin/server/communication/AtmospherePushConnection.java
server/src/com/vaadin/server/communication/PushHandler.java
Change-Id: I93b5c3f3017aaa1ba2a231028c808d6e56fe1c11
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/server/communication/AtmospherePushConnection.java | 10 | ||||
-rw-r--r-- | server/src/com/vaadin/server/communication/PushHandler.java | 78 |
2 files changed, 87 insertions, 1 deletions
diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index 65ea43ddd4..a4290a31cf 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -260,6 +260,16 @@ public class AtmospherePushConnection implements PushConnection { @Override public void disconnect() { assert isConnected(); + + if (resource.isResumed()) { + // Calling disconnect may end up invoking it again via + // resource.resume and PushHandler.onResume. Bail out here if + // the resource is already resumed; this is a bit hacky and should + // be implemented in a better way in 7.2. + resource = null; + return; + } + if (outgoingMessage != null) { // Wait for the last message to be sent before closing the // connection (assumes that futures are completed in order) diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java index 1557ae9b19..e028968494 100644 --- a/server/src/com/vaadin/server/communication/PushHandler.java +++ b/server/src/com/vaadin/server/communication/PushHandler.java @@ -365,7 +365,83 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter { } private void disconnect(AtmosphereResourceEvent event) { - callWithUi(event.getResource(), disconnectCallback); + // We don't want to use callWithUi here, as it assumes there's a client + // request active and does requestStart and requestEnd among other + // things. + + AtmosphereResource resource = event.getResource(); + VaadinServletRequest vaadinRequest = new VaadinServletRequest( + resource.getRequest(), service); + VaadinSession session = null; + + try { + session = service.findVaadinSession(vaadinRequest); + } catch (ServiceException e) { + getLogger().log(Level.SEVERE, + "Could not get session. This should never happen", e); + return; + } catch (SessionExpiredException e) { + getLogger() + .log(Level.SEVERE, + "Session expired before push was disconnected. This should never happen", + e); + return; + } + + UI ui = null; + session.lock(); + try { + VaadinSession.setCurrent(session); + // Sets UI.currentInstance + ui = service.findUI(vaadinRequest); + if (ui == null) { + getLogger().log(Level.SEVERE, + "Could not get UI. This should never happen"); + return; + } + + PushMode pushMode = ui.getPushConfiguration().getPushMode(); + AtmospherePushConnection pushConnection = getConnectionForUI(ui); + + String id = resource.uuid(); + + if (pushConnection == null) { + getLogger() + .log(Level.WARNING, + "Could not find push connection to close: {0} with transport {1}", + new Object[] { id, resource.transport() }); + } else { + if (!pushMode.isEnabled()) { + /* + * The client is expected to close the connection after push + * mode has been set to disabled. + */ + getLogger().log(Level.FINER, + "Connection closed for resource {0}", id); + } else { + /* + * Unexpected cancel, e.g. if the user closes the browser + * tab. + */ + getLogger() + .log(Level.FINER, + "Connection unexpectedly closed for resource {0} with transport {1}", + new Object[] { id, resource.transport() }); + } + ui.setPushConnection(null); + } + + } catch (final Exception e) { + callErrorHandler(session, e); + } finally { + try { + session.unlock(); + } catch (Exception e) { + getLogger().log(Level.WARNING, "Error while unlocking session", + e); + // can't call ErrorHandler, we (hopefully) don't have a lock + } + } } /** |