/** * Returns whether the given session is active or whether it can be closed. * <p> * A session is active if and only if its {@link VaadinSession#getState()} * returns {@link State#OPEN} 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) { if (session.getState() != State.OPEN || session.getSession() == null) { return false; } else { long now = System.currentTimeMillis(); int timeout = 1000 * getUidlRequestTimeout(session); return timeout < 0 || now - session.getLastRequestTimestamp() < timeout; } }
if (session.getState() == State.OPEN) { closeSession(session); if (session.getSession() != null) { getLogger().log(Level.FINE, "Closing inactive session {0}", session.getSession().getId()); if (session.getSession() != null) { removeSession(session.getSession());
/** * Returns the number of seconds that must pass without a valid UIDL request * being received for the given session before the session is closed, even * though heartbeat requests are received. This is a lower bound; it might * take longer to close an inactive session. * <p> * Returns a negative number if there is no timeout. In this case heartbeat * requests suffice to keep the session alive, but it will still eventually * expire in the regular manner if there are no requests at all (see * {@link WrappedSession#getMaxInactiveInterval()}). * * @see DeploymentConfiguration#isCloseIdleSessions() * @see #getHeartbeatTimeout() * * @since 7.0.0 * * @return The UIDL request timeout in seconds, or a negative number if * timeout never occurs. */ private int getUidlRequestTimeout(VaadinSession session) { return getDeploymentConfiguration().isCloseIdleSessions() ? session.getSession().getMaxInactiveInterval() : -1; }
&& messages.getSessionExpiredCaption() == null && messages.isSessionExpiredNotificationEnabled() && ui.getSession().getSession() != null) { int newTimeoutInterval = ui.getSession().getSession() .getMaxInactiveInterval(); if (repaintAll || (timeoutInterval != newTimeoutInterval)) {
/** * Closes those UIs in the given session for which {@link #isUIActive} * yields false. * * @since 7.0.0 */ private void closeInactiveUIs(VaadinSession session) { final String sessionId = session.getSession().getId(); for (final UI ui : session.getUIs()) { if (!isUIActive(ui) && !ui.isClosing()) { ui.accessSynchronously(() -> { getLogger().log(Level.FINE, "Closing inactive UI #{0} in session {1}", new Object[] { ui.getUIId(), sessionId }); ui.close(); }); } } }
private static WrappedSession getSession() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null) { return vaadinSession.getSession(); } else { return null; } }
private static WrappedSession getSession() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null) { return vaadinSession.getSession(); } else { return null; } }
/** * Returns the HTTP session.<p> * * @return the HTTP session */ public HttpSession getHttpSession() { return ((WrappedHttpSession)getSession().getSession()).getHttpSession(); }
@Override public String getConversationId() { return getVaadinSession().getSession().getId(); } }
public static ZoneId extractUserTimeZoneIdOrNull(){ if(VaadinSession.getCurrent() != null && VaadinSession.getCurrent().getSession() !=null){ return (ZoneId) VaadinSession.getCurrent().getSession().getAttribute(CentralizedDateTimeFormat.SESSION_PROPERTY_TIMEZONE_ID); } return null; } }
public static ZoneId extractUserTimeZoneIdOrNull(final UI ui) { // Verify if a ui is provided, still attached and has a session if (ui != null && ui.isAttached() && ui.getSession() != null && ui.getSession().getSession() != null) { // Only the wrapped session has the attribute set, the VaadinSession does not! return (ZoneId) ui.getSession().getSession().getAttribute(CentralizedDateTimeFormat.SESSION_PROPERTY_TIMEZONE_ID); } return null; } }
@Override public String getConversationId() { return getVaadinSession().getSession().getId() + getUIID(); } }
@Override public void sessionInit(SessionInitEvent event) throws ServiceException { vaadinSessionIdMap.put(event.getSession(), event.getSession().getSession().getId()); for (SessionListener eachListener : getSessionListeners()) { eachListener.sessionInitialized(vaadinSessionIdMap.get(event.getSession())); } }
@Override public String getConversationId() { if (VaadinSession.getCurrent() == null || !VaadinSession.getCurrent().hasLock()) { throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread"); } return VaadinSession.getCurrent().getSession().getId(); } }
@Override public void sessionInit(SessionInitEvent event) throws ServiceException { vaadinSessionIdMap.put(event.getSession(), event.getSession().getSession().getId()); for (SessionListener eachListener : getSessionListeners()) { eachListener.sessionInitialized(vaadinSessionIdMap.get(event.getSession())); } }
/** * Reads the error attributes from current session.<p> */ private void readErrorAttributes() { WrappedSession session = getSession().getSession(); m_requestedPage = (String)session.getAttribute(PATH); m_throwable = (Throwable)session.getAttribute(THROWABLE); // remove the attributes after read to keep the session clean session.removeAttribute(THROWABLE); session.removeAttribute(PATH); } }
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); if (isPersistentSessionCookie()) { getState().persistentSessionTimeout = VaadinSession.getCurrent() .getSession().getMaxInactiveInterval(); } else { getState().persistentSessionTimeout = null; } }
SessionAwareBeanStore(VaadinSession session) { super("Session:" + session.getSession().getId()); this.session = session; this.session.getService().addSessionDestroyListener(this); this.session.getService().addServiceDestroyListener(this); this.session.setAttribute(BeanStore.class, this); }
UIStore(VaadinSession session) { this.sessionId = session.getSession().getId(); this.session = session; this.session.getService().addSessionDestroyListener(this); this.session.getService().addServiceDestroyListener(this); this.session.setAttribute(UIStore.class, this); }
@Override protected void init(VaadinRequest request) { initLogging(); // store the webservice URL property explicitly in the session in order to // access it from the "external" servlets getSession().getSession().setAttribute(WEBSERVICEURL_KEY, getSession().getAttribute(Helper.KEY_WEB_SERVICE_URL)); getSession().setAttribute(CONTEXT_PATH, request.getContextPath()); alreadyAddedCSS.clear(); initPlugins(); checkIfRemoteLoggedIn(request); getSession().addRequestHandler(new RemoteUserRequestHandler()); }