/** * 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 (getState() == State.OPEN) { close();
|| session.getState() != State.OPEN); getRpcProxy(UIClientRpc.class).uiClosed(sessionExpired); if (getPushConnection() != null) {
removeClosedUIs(session); } else { if (session.getState() == State.OPEN) { closeSession(session); if (session.getSession() != null) {
private VaadinSession getVaadinSession() { VaadinSession current = VaadinSession.getCurrent(); if (current == null) { throw new IllegalStateException("No VaadinSession bound to current thread"); } if (current.getState() != VaadinSession.State.OPEN) { throw new IllegalStateException("Current VaadinSession is not open"); } return current; }
private VaadinSession getVaadinSession() { VaadinSession current = VaadinSession.getCurrent(); if (current == null) { throw new IllegalStateException("No VaadinSession bound to current thread"); } if (current.getState() != VaadinSession.State.OPEN) { throw new IllegalStateException("Current VaadinSession is not open"); } return current; }
/** * Create a VaadinSession * @param locale Client locale * @return VaadinSession instance * @throws Exception Failed to create session */ protected VaadinSession createVaadinSession(Locale locale) throws Exception { WrappedSession wrappedSession = mock(WrappedSession.class); VaadinServletService vaadinService = mock(VaadinServletService.class); when(vaadinService.getDeploymentConfiguration()) .thenReturn(new DefaultDeploymentConfiguration(VaadinServletService.class, getDeploymentProperties())); VaadinSession session = mock(VaadinSession.class); when(session.getState()).thenReturn(VaadinSession.State.OPEN); when(session.getSession()).thenReturn(wrappedSession); when(session.getService()).thenReturn(vaadinService); when(session.getSession().getId()).thenReturn(TEST_SESSION_ID); when(session.hasLock()).thenReturn(true); when(session.getLocale()).thenReturn(locale != null ? locale : Locale.US); return session; }
/** * Create a VaadinSession * @param locale Client locale * @return VaadinSession instance * @throws Exception Failed to create session */ protected VaadinSession createVaadinSession(Locale locale) throws Exception { WrappedSession wrappedSession = mock(WrappedSession.class); VaadinServletService vaadinService = mock(VaadinServletService.class); when(vaadinService.getDeploymentConfiguration()) .thenReturn(new DefaultDeploymentConfiguration(VaadinServletService.class, getDeploymentProperties())); VaadinSession session = mock(VaadinSession.class); when(session.getState()).thenReturn(VaadinSession.State.OPEN); when(session.getSession()).thenReturn(wrappedSession); when(session.getService()).thenReturn(vaadinService); when(session.getSession().getId()).thenReturn(TEST_SESSION_ID); when(session.hasLock()).thenReturn(true); when(session.getLocale()).thenReturn(locale != null ? locale : Locale.US); return session; }
/** * Returns whether the given session is active or whether it can be closed. * <p> * 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) { if (session.getState() != VaadinSessionState.OPEN || session.getSession() == null) { return false; } else { long now = System.currentTimeMillis(); int timeout = 1000 * getUidlRequestTimeout(session); return timeout < 0 || now - session.getLastRequestTimestamp() < timeout; } }
private void doDispatch(final List<TenantAwareEvent> events, final WrappedSession wrappedSession) { final SecurityContext userContext = (SecurityContext) wrappedSession .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); final SecurityContext oldContext = SecurityContextHolder.getContext(); try { SecurityContextHolder.setContext(userContext); final List<EventContainer<TenantAwareEvent>> groupedEvents = groupEvents(events, userContext, eventProvider); vaadinUI.access(() -> { if (vaadinSession.getState() != State.OPEN) { return; } LOG.debug("UI EventBus aggregator of UI {} got lock on session.", vaadinUI.getUIId()); groupedEvents.forEach(holder -> eventBus.publish(vaadinUI, holder)); LOG.debug("UI EventBus aggregator of UI {} left lock on session.", vaadinUI.getUIId()); }).get(); } catch (InterruptedException | ExecutionException e) { LOG.warn("Wait for Vaadin session for UI {} interrupted!", vaadinUI.getUIId(), e); Thread.currentThread().interrupt(); } finally { SecurityContextHolder.setContext(oldContext); } }
private void doDispatch(final List<TenantAwareEvent> events, final WrappedSession wrappedSession) { final SecurityContext userContext = (SecurityContext) wrappedSession .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); final SecurityContext oldContext = SecurityContextHolder.getContext(); try { SecurityContextHolder.setContext(userContext); final List<EventContainer<TenantAwareEvent>> groupedEvents = groupEvents(events, userContext, eventProvider); vaadinUI.access(() -> { if (vaadinSession.getState() != State.OPEN) { return; } LOG.debug("UI EventBus aggregator of UI {} got lock on session.", vaadinUI.getUIId()); groupedEvents.forEach(holder -> eventBus.publish(vaadinUI, holder)); LOG.debug("UI EventBus aggregator of UI {} left lock on session.", vaadinUI.getUIId()); }).get(); } catch (InterruptedException | ExecutionException e) { LOG.warn("Wait for Vaadin session for UI {} interrupted!", vaadinUI.getUIId(), e); } finally { SecurityContextHolder.setContext(oldContext); } }
if (getState() == VaadinSessionState.OPEN) { close();
removeClosedUIs(session); } else { if (session.getState() == VaadinSessionState.OPEN) { closeSession(session); if (session.getSession() != null) {