@Override public boolean isActive() { return VaadinSession.getCurrent() != null; }
@Override public boolean isActive() { return VaadinSession.getCurrent() != null; }
@Override public boolean isActive() { return VaadinSession.getCurrent() != null; }
public RouteRegistry getRegistry() { // If we have a session then return the session registry // else return router registry if (VaadinSession.getCurrent() != null) { return SessionRouteRegistry .getSessionRegistry(VaadinSession.getCurrent()); } return registry; }
@Override public boolean isActive() { return VaadinSession.getCurrent() != null && UI.getCurrent() != null && contextualStorageManager != null; }
/** * Get the {@link DeviceInfoRegistry} associated with current session, if available. * @return Optional session registry */ static Optional<DeviceInfoRegistry> getSessionRegistry() { VaadinSession session = VaadinSession.getCurrent(); if (session != null) { return Optional.ofNullable(session.getAttribute(DeviceInfoRegistry.class)); } return Optional.empty(); }
@Override public boolean isActive() { return VaadinSession.getCurrent() != null && UI.getCurrent() != null && contextualStorageManager != null; }
@Override public boolean isActive() { return VaadinSession.getCurrent() != null && UI.getCurrent() != null && contextualStorageManager != null; }
private static RouteRegistry getSessionRegistry() { return SessionRouteRegistry .getSessionRegistry(VaadinSession.getCurrent()); }
/** * Guess whether this context is undeployed. * * Tomcat expires sessions after contexts are undeployed. * Need this guess to prevent exceptions when try to * properly destroy contexts on session expiration. * * @return true when context is not active, but sure it should */ public static boolean guessContextIsUndeployed() { // Given there is a current VaadinSession, we should have an active context, // except we get here after the application is undeployed. return (VaadinSession.getCurrent() != null && !ContextUtils.isContextActive(VaadinSessionScoped.class)); }
/** * Guess whether this context is undeployed. * * Tomcat expires sessions after contexts are undeployed. * Need this guess to prevent exceptions when try to * properly destroy contexts on session expiration. * * @return true when context is not active, but sure it should */ public static boolean guessContextIsUndeployed() { // Given there is a current VaadinSession, we should have an active context, // except we get here after the application is undeployed. return (VaadinSession.getCurrent() != null && !ContextUtils.isContextActive(VaadinSessionScoped.class)); }
/** * Guess whether this context is undeployed. * * Tomcat expires sessions after contexts are undeployed. * Need this guess to prevent exceptions when try to * properly destroy contexts on session expiration. * * @return true when context is not active, but sure it should */ public static boolean guessContextIsUndeployed() { // Given there is a current VaadinSession, we should have an active context, // except we get here after the application is undeployed. return (VaadinSession.getCurrent() != null && !ContextUtils.isContextActive(VaadinSessionScoped.class)); }
/** * 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(); }
@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; }
@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(); } }
@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; }
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[] }