VaadinService implements Serializable { public void fireSessionDestroy(VaadinSession vaadinSession) { final VaadinSession session = vaadinSession; session.access(() -> { if (session.getState() == VaadinSessionState.CLOSED) { return; } if (session.getState() == VaadinSessionState.OPEN) { closeSession(session); } List<UI> uis = new ArrayList<>(session.getUIs()); for (final UI ui : uis) { ui.accessSynchronously(() -> { if (!ui.isClosing()) { ui.close(); } session.removeUI(ui); }); } SessionDestroyEvent event = new SessionDestroyEvent( VaadinService.this, session); for (SessionDestroyListener listener : sessionDestroyListeners) { try { listener.sessionDestroy(event); } catch (Exception e) { session.getErrorHandler().error(new ErrorEvent(e)); } } session.setState(VaadinSessionState.CLOSED); }); } VaadinService(DeploymentConfiguration deploymentConfiguration); protected  VaadinService(); void init(); abstract String getContextRootRelativePath(VaadinRequest request); Instantiator getInstantiator(); ClassLoader getClassLoader(); void setClassLoader(ClassLoader classLoader); abstract String getMimeType(String resourceName); DeploymentConfiguration getDeploymentConfiguration(); void setSystemMessagesProvider(
            SystemMessagesProvider systemMessagesProvider); SystemMessagesProvider getSystemMessagesProvider(); SystemMessages getSystemMessages(Locale locale,
            VaadinRequest request); Registration addSessionInitListener(SessionInitListener listener); Registration addUIInitListener(UIInitListener listener); Registration addSessionDestroyListener(
            SessionDestroyListener listener); @Deprecated void modifyBootstrapPage(BootstrapPageResponse response); void modifyIndexHtmlResponse(IndexHtmlResponse response); void fireSessionDestroy(VaadinSession vaadinSession); VaadinSession findVaadinSession(VaadinRequest request); static VaadinService getCurrent(); void setCurrentInstances(VaadinRequest request,
            VaadinResponse response); static void setCurrent(VaadinService service); static VaadinRequest getCurrentRequest(); static VaadinResponse getCurrentResponse(); abstract String getServiceName(); UI findUI(VaadinRequest request); static void reinitializeSession(VaadinRequest request); abstract String getMainDivId(VaadinSession session,
            VaadinRequest request); void closeSession(VaadinSession session); boolean isUIActive(UI ui); void requestStart(VaadinRequest request, VaadinResponse response); void requestEnd(VaadinRequest request, VaadinResponse response,
            VaadinSession session); Iterable<RequestHandler> getRequestHandlers(); Iterable<DependencyFilter> getDependencyFilters(); void handleRequest(VaadinRequest request, VaadinResponse response); void writeStringResponse(VaadinResponse response, String contentType,
            String responseString); void writeUncachedStringResponse(VaadinResponse response,
            String contentType, String responseString); static String createCriticalNotificationJSON(String caption,
            String message, String details, String url); static String createCriticalNotificationJSON(String caption,
            String message, String details, String url, String querySelector); static String createSessionExpiredJSON(boolean async); static String createUINotFoundJSON(boolean async); boolean ensurePushAvailable(); static void verifyNoOtherSessionLocked(VaadinSession session); static boolean isOtherSessionLocked(VaadinSession session); static boolean isCsrfTokenValid(UI ui, String requestToken); Future<Void> accessSession(VaadinSession session, Command command); void ensureAccessQueuePurged(VaadinSession session); void runPendingAccessTasks(VaadinSession session); Registration addServiceDestroyListener(
            ServiceDestroyListener listener); void destroy(); void removeSession(WrappedSession wrappedSession); Router getRouter(); void fireUIInitListeners(UI ui); abstract URL getStaticResource(String url); abstract URL getResource(String url); abstract InputStream getResourceAsStream(String url); boolean isResourceAvailable(String url); abstract String resolveResource(String url); VaadinContext getContext(); BootstrapInitialPredicate getBootstrapInitialPredicate(); void setBootstrapInitialPredicate(
            BootstrapInitialPredicate bootstrapInitialPredicate); BootstrapUrlPredicate getBootstrapUrlPredicate(); void setBootstrapUrlPredicate(
            BootstrapUrlPredicate bootstrapUrlPredicate); static String getCsrfTokenAttributeName(); static final String INVALID_ATMOSPHERE_VERSION_WARNING; static final String ATMOSPHERE_MISSING_ERROR; static final String CANNOT_ACQUIRE_CLASSLOADER_SEVERE; }
@Test public void testFireSessionDestroy() throws ServletException { VaadinService service = createService(); TestSessionDestroyListener listener = new TestSessionDestroyListener(); service.addSessionDestroyListener(listener); MockVaadinSession vaadinSession = new MockVaadinSession(service); service.fireSessionDestroy(vaadinSession); Assert.assertEquals( "'fireSessionDestroy' method doesn't call 'close' for the session", 1, vaadinSession.getCloseCount()); vaadinSession.valueUnbound( EasyMock.createMock(HttpSessionBindingEvent.class)); Assert.assertEquals( "'fireSessionDestroy' method may not call 'close' " + "method for closing session", 1, vaadinSession.getCloseCount()); Assert.assertEquals("SessionDestroyListeners not called exactly once", 1, listener.callCount); }