VaadinRequest request, Class<? extends UI> uiClass);
/**
- * Closes the VaadinServiceSession and discards all associated UI state.
+ * Sets the given session to be closed and all its UI state to be discarded
+ * at the end of the current request, or at the end of the next request if
+ * there is no ongoing one.
+ * <p>
* After the session has been discarded, any UIs that have been left open
- * will give an Out of sync error (
- * {@link SystemMessages#getOutOfSyncCaption()}) error and a new session
- * will be created for serving new UIs.
+ * will give a Session Expired error and a new session will be created for
+ * serving new UIs.
* <p>
* To avoid causing out of sync errors, you should typically redirect to
* some other page using {@link Page#setLocation(String)} to make the
* browser unload the invalidated UI.
*
+ * @see SystemMessages#getSessionExpiredCaption()
+ *
* @param session
* the session to close
*/
public void closeSession(VaadinSession session) {
- session.removeFromSession(this);
+ session.close();
}
/**
closeInactiveUIs(session);
removeClosedUIs(session);
} else {
- getLogger().fine(
- "Closed inactive session " + session.getSession().getId());
- closeSession(session);
+ if (!session.isClosing()) {
+ getLogger().fine(
+ "Closing inactive session "
+ + session.getSession().getId());
+ closeSession(session);
+ }
+ session.removeFromSession(this);
}
}
/**
* Returns whether the given session is active or whether it can be closed.
* <p>
- * A session is always active if
- * {@link #getUidlRequestTimeout(VaadinSession) getUidlRequestTimeout} is
- * negative. Otherwise, it is active if and only if the timeout has not
- * expired.
+ * A session is active if and only if its {@link #isClosing} returns false
+ * and {@link #getUidlRequestTimeout(VaadinSession) getUidlRequestTimeout}
+ * is negative or has not yet expired.
*
* @param session
* The session whose status to check
+ *
* @return true if the session is active, false if it could be closed.
*/
private boolean isSessionActive(VaadinSession session) {
- long now = System.currentTimeMillis();
- int timeout = 1000 * getUidlRequestTimeout(session);
- return timeout < 0 || now - session.getLastRequestTimestamp() < timeout;
+ if (session.isClosing()) {
+ return false;
+ } else {
+ long now = System.currentTimeMillis();
+ int timeout = 1000 * getUidlRequestTimeout(session);
+ return timeout < 0
+ || now - session.getLastRequestTimestamp() < timeout;
+ }
}
private static final Logger getLogger() {
private long lastRequestTimestamp = System.currentTimeMillis();
+ private boolean closing = false;
+
private transient WrappedSession session;
private final Map<String, Object> attributes = new HashMap<String, Object>();
@Deprecated
public void removeFromSession(VaadinService service) {
assert (getForSession(service, session) == this);
-
session.setAttribute(
VaadinSession.class.getName() + "." + service.getServiceName(),
null);
}
/**
- * Closes this session and discards all associated UI state. After the
- * session has been discarded, any UIs that have been left open will give an
- * Out of sync error ({@link SystemMessages#getOutOfSyncCaption()}) error
- * and a new session will be created for serving new UIs.
+ * Sets this session to be closed and all UI state to be discarded at the
+ * end of the current request, or at the end of the next request if there is
+ * no ongoing one.
+ * <p>
+ * After the session has been discarded, any UIs that have been left open
+ * will give a Session Expired error and a new session will be created for
+ * serving new UIs.
* <p>
* To avoid causing out of sync errors, you should typically redirect to
* some other page using {@link Page#setLocation(String)} to make the
* browser unload the invalidated UI.
- * <p>
- * This method is just a shorthand to
- * {@link VaadinService#closeSession(VaadinSession)}
*
- * @see VaadinService#closeSession(VaadinSession)
+ * @see SystemMessages#getSessionExpiredCaption()
*
*/
public void close() {
- getService().closeSession(this);
+ closing = true;
}
+ /**
+ * Returns whether this session is marked to be closed.
+ *
+ * @see #close()
+ *
+ * @return
+ */
+ public boolean isClosing() {
+ return closing;
+ }
}