private void destroy() { session.lock(); try { session.setAttribute(UIStoreWrapper.class, null); uiStores.values().forEach(BeanStore::destroy); uiStores.clear(); } finally { session.unlock(); if (sessionDestroyListenerRegistration != null) { sessionDestroyListenerRegistration.remove(); } } }
private void destroy() { session.lock(); try { session.setAttribute(UIStoreWrapper.class, null); uiStores.values().forEach(BeanStore::destroy); uiStores.clear(); } finally { session.unlock(); if (sessionDestroyListenerRegistration != null) { sessionDestroyListenerRegistration.remove(); } } }
@Override public boolean remove(String resourceKey) throws UnsupportedOperationException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("Current VaadinSession not available"); } Object exist = session.getAttribute(resourceKey); session.setAttribute(resourceKey, null); return exist != null; }
public void setLayoutToSession() { UI.getCurrent().getSession().setAttribute(SESSION_ATTRIBUTE_APP_LAYOUT, appLayout); }
@SuppressWarnings("unchecked") @Override public <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("Current VaadinSession not available"); } Object exist = session.getAttribute(resourceKey); session.setAttribute(resourceKey, value); try { T previous = (T) exist; return Optional.ofNullable(previous); } catch (@SuppressWarnings("unused") Exception e) { // ignore return Optional.empty(); } }
@SuppressWarnings("unchecked") @Override public <T> Optional<T> putIfAbsent(String resourceKey, T value) throws UnsupportedOperationException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("Current VaadinSession not available"); } if (value != null) { synchronized (session) { Object exist = session.getAttribute(resourceKey); if (exist == null) { session.setAttribute(resourceKey, value); } else { return Optional.of((T) exist); } } } return Optional.empty(); }
/** * Get the session registry for VaadinSession. If no SessionRegistry exists * then one will be created for given VaadinSession. * * @param session * vaadin session to get registry for * @return session registry for given session */ public static RouteRegistry getSessionRegistry(VaadinSession session) { Objects.requireNonNull(session, "Null session is not supported for session route registry"); SessionRouteRegistry registry = session .getAttribute(SessionRouteRegistry.class); if (registry == null) { registry = new SessionRouteRegistry(session, session.getService()); session.setAttribute(SessionRouteRegistry.class, registry); } if (!registry.session.equals(session)) { throw new IllegalStateException( "Session has as the attribute a route registered to another session"); } return registry; }
@Override Void doDestroy() { try { getVaadinSession().setAttribute(BeanStore.class, null); super.doDestroy(); } finally { if (sessionDestroyListenerRegistration != null) { sessionDestroyListenerRegistration.remove(); } } return null; } }
@Override protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) { VaadinSession session = VaadinSession.getCurrent(); ContextualStorage storage = findContextualStorage(session); if (storage == null && createIfNotExist) { storage = new ContextualStorage(beanManager, false, true); session.setAttribute(ATTRIBUTE_NAME, storage); } return storage; }
@Override protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) { VaadinSession session = VaadinSession.getCurrent(); ContextualStorage storage = findContextualStorage(session); if (storage == null && createIfNotExist) { storage = new ContextualStorage(beanManager, false, true); session.setAttribute(ATTRIBUTE_NAME, storage); } return storage; }
@Override protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) { VaadinSession session = VaadinSession.getCurrent(); ContextualStorage storage = findContextualStorage(session); if (storage == null && createIfNotExist) { storage = new ContextualStorage(beanManager, false, true); session.setAttribute(ATTRIBUTE_NAME, storage); } return storage; }
@Override Void doDestroy() { try { getVaadinSession().setAttribute(BeanStore.class, null); super.doDestroy(); } finally { if (sessionDestroyListenerRegistration != null) { sessionDestroyListenerRegistration.remove(); } } return null; } }
serviceSession.setAttribute(PRESERVE_UNBOUND_SESSION_ATTRIBUTE, Boolean.TRUE); .setAttribute(PRESERVE_UNBOUND_SESSION_ATTRIBUTE, null);
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { BeanStore beanStore = session.getAttribute(BeanStore.class); if (beanStore == null) { beanStore = new SessionBeanStore(session); session.setAttribute(BeanStore.class, beanStore); } return beanStore; } finally { session.unlock(); } }
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { BeanStore beanStore = session.getAttribute(BeanStore.class); if (beanStore == null) { beanStore = new SessionBeanStore(session); session.setAttribute(BeanStore.class, beanStore); } return beanStore; } finally { session.unlock(); } }
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { UIStoreWrapper wrapper = session.getAttribute(UIStoreWrapper.class); if (wrapper == null) { wrapper = new UIStoreWrapper(session); session.setAttribute(UIStoreWrapper.class, wrapper); } return wrapper.getBeanStore(getUI()); } finally { session.unlock(); } }
public void scope2() { // tag::scope2[] VaadinSession.getCurrent().setAttribute(LocalizationContext.class, // <1> LocalizationContext.builder().withInitialLocale(Locale.US).build()); Optional<LocalizationContext> localizationContext = Context.get().resource(LocalizationContext.class); // <2> localizationContext = LocalizationContext.getCurrent(); // <3> // end::scope2[] }
public void i18nprovider2() { // tag::i18nprovider2[] LocalizationContext localizationContext = LocalizationContext.builder() .withMessageProvider(MessageProvider.fromProperties("messages").build()).withInitialLocale(Locale.US) .build(); // <1> VaadinSession.getCurrent().setAttribute(LocalizationContext.class, localizationContext); // <2> I18NProvider i18nProvider = LocalizationContextI18NProvider.create(); // <3> // end::i18nprovider2[] }
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { UIStoreWrapper wrapper = session.getAttribute(UIStoreWrapper.class); if (wrapper == null) { wrapper = new UIStoreWrapper(session); session.setAttribute(UIStoreWrapper.class, wrapper); } return wrapper.getBeanStore(getUI()); } finally { session.unlock(); } }
@Override public void serviceInit(ServiceInitEvent event) { // Session event.getSource().addSessionInitListener(e -> { // DeviceInfo registry is available if (e.getSession().getAttribute(DeviceInfoRegistry.class) == null) { e.getSession().setAttribute(DeviceInfoRegistry.class, new DefaultDeviceInfoRegistry()); } }); // UI init event.getSource().addUIInitListener(e -> { if (e.getUI().getSession() != null) { // configure DeviceInfo final DeviceInfoRegistry registry = e.getUI().getSession().getAttribute(DeviceInfoRegistry.class); if (registry != null && !registry.hasDeviceInfo(e.getUI())) { final VaadinRequest request = VaadinRequest.getCurrent(); if (request != null) { registry.setDeviceInfo(e.getUI(), DeviceInfo.create(e.getUI(), request)); // log LOGGER.debug(() -> "A DeviceInfo was configured for UI with id [" + e.getUI().getUIId() + "]"); } } } }); }