/** * Creates a new instance for the given {@code session}. * * @param session * a vaadin session */ BeanStore(VaadinSession session) { assert session.hasLock(); this.session = session; }
/** * Creates a new instance for the given {@code session}. * * @param session * a vaadin session */ BeanStore(VaadinSession session) { assert session.hasLock(); this.session = session; }
Void doDestroy() { assert session.hasLock(); for (Runnable destructionCallback : destructionCallbacks.values()) { try { destructionCallback.run(); } catch (Exception e) { LOGGER.error("BeanStore destruction callback failed", e); } } destructionCallbacks.clear(); objects.clear(); return null; }
Void doDestroy() { assert session.hasLock(); for (Runnable destructionCallback : destructionCallbacks.values()) { try { destructionCallback.run(); } catch (Exception e) { LOGGER.error( "BeanStore destruction callback failed", e); } } destructionCallbacks.clear(); objects.clear(); return null; }
/** * Called when the VaadinSession should be removed from the underlying HTTP * session. * * @param wrappedSession * the underlying HTTP session */ public void removeSession(WrappedSession wrappedSession) { assert VaadinSession.hasLock(this, wrappedSession); removeFromHttpSession(wrappedSession); }
/** * Potentially checks whether this session is currently locked by the * current thread, and fails with the given message if not. * <p> * When production mode is enabled, the check is only done if assertions are * also enabled. This is done to avoid the small performance impact of * continuously checking the lock status. The check is always done when * production mode is not enabled. * * @param message * the error message to include when failing if the check is done * and the session is not locked */ public void checkHasLock(String message) { if (configuration == null || configuration.isProductionMode()) { assert hasLock() : message; } else if (!hasLock()) { throw new IllegalStateException(message); } }
/** * Checks whether there might be some {@link VaadinSession} other than the * provided one for which the current thread holds a lock. This method might * not detect all cases where some other session is locked, but it should * cover the most typical situations. * * @param session * the session that is expected to be locked * @return <code>true</code> if another session is also locked by the * current thread; <code>false</code> if no such session was found */ public static boolean isOtherSessionLocked(VaadinSession session) { VaadinSession otherSession = VaadinSession.getCurrent(); if (otherSession == null || otherSession == session) { return false; } return otherSession.hasLock(); }
private <T> T execute(Supplier<T> supplier) { if (session.hasLock()) { return supplier.get(); } else { session.lock(); try { return supplier.get(); } finally { session.unlock(); } } }
private <T> T execute(Supplier<T> supplier) { if (session.hasLock()) { return supplier.get(); } else { session.lock(); try { return supplier.get(); } finally { session.unlock(); } } }
/** * Updates the transient session lock from VaadinService. */ private void refreshLock() { assert lock == null || lock == service.getSessionLock( session) : "Cannot change the lock from one instance to another"; assert hasLock(service, session); lock = service.getSessionLock(session); }
@Override public void onComponentEvent(DetachEvent event) { assert session.hasLock(); UI ui = event.getUI(); BeanStore beanStore = uiStores.remove(ui.getUIId()); if (beanStore != null) { beanStore.destroy(); } }
/** * Called when the VaadinSession should be stored. * <p> * By default stores the VaadinSession in the underlying HTTP session. * * @param session * the VaadinSession to store * @param wrappedSession * the underlying HTTP session */ protected void storeSession(VaadinSession session, WrappedSession wrappedSession) { assert VaadinSession.hasLock(this, wrappedSession); writeToHttpSession(wrappedSession, session); session.refreshTransients(wrappedSession, this); }
@Override public void onComponentEvent(DetachEvent event) { assert session.hasLock(); UI ui = event.getUI(); BeanStore beanStore = uiStores.remove(ui.getUIId()); if (beanStore != null) { beanStore.destroy(); } }
/** * Called when the VaadinSession should be loaded from the underlying HTTP * session. * * @param wrappedSession * the underlying HTTP session * @return the VaadinSession in the HTTP session or null if not found */ protected VaadinSession loadSession(WrappedSession wrappedSession) { assert VaadinSession.hasLock(this, wrappedSession); VaadinSession vaadinSession = readFromHttpSession(wrappedSession); if (vaadinSession == null) { return null; } vaadinSession.refreshTransients(wrappedSession, this); return vaadinSession; }
/** * Sets the navigation {@code handler} and the navigation {@code event} * for this action. * * @param handler * the navigation handler * @param event * the navigation event */ public void setReferences(NavigationHandler handler, NavigationEvent event) { if (event != null) { event.getUI().getSession().hasLock(); } else { assert UI.getCurrent() != null && UI.getCurrent().getSession().hasLock(); } this.handler = handler; this.event = event; }
/** * Resumes the page transition associated with the postponed event. */ public void proceed() { BeforeLeaveEvent.this.continueNavigationAction = null; if (handler != null && event != null) { if (!event.getUI().getSession().hasLock()) { throw new IllegalStateException( "The method 'proceed' may not be called without the session lock. " + "Use UI.access() to execute any UI related code from a separate thread properly"); } handler.handle(event); setReferences(null, null); } } }
private UIStoreWrapper(VaadinSession session) { assert session.hasLock(); uiStores = new HashMap<>(); this.session = session; if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
private UIStoreWrapper(VaadinSession session) { assert session.hasLock(); uiStores = new HashMap<>(); this.session = session; if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }