List of usage examples for com.vaadin.server VaadinSession hasLock
public boolean hasLock()
From source file:com.haulmont.cuba.web.App.java
License:Apache License
/** * @return Current App instance. Can be invoked anywhere in application code. * @throws IllegalStateException if no application instance is bound to the current {@link VaadinSession} *//* ww w . j ava 2 s. c om*/ public static App getInstance() { VaadinSession vSession = VaadinSession.getCurrent(); if (vSession == null) { throw new IllegalStateException("No VaadinSession found"); } if (!vSession.hasLock()) { throw new IllegalStateException("VaadinSession is not owned by the current thread"); } App app = vSession.getAttribute(App.class); if (app == null) { throw new IllegalStateException("No App is bound to the current VaadinSession"); } return app; }
From source file:com.haulmont.cuba.web.App.java
License:Apache License
/** * @return true if an {@link App} instance is currently bound and can be safely obtained by {@link #getInstance()} *//*from w w w.ja va 2s.c om*/ public static boolean isBound() { VaadinSession vSession = VaadinSession.getCurrent(); return vSession != null && vSession.hasLock() && vSession.getAttribute(App.class) != null; }
From source file:com.haulmont.cuba.web.gui.executors.impl.WebBackgroundWorker.java
License:Apache License
@Override public void checkUIAccess() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession == null || !vaadinSession.hasLock()) { throw new IllegalConcurrentAccessException(); }//from w ww . j a v a 2 s . c om }
From source file:com.haulmont.cuba.web.sys.WebVaadinCompatibleSecurityContextHolder.java
License:Apache License
@Override public SecurityContext get() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null && vaadinSession.hasLock()) { return vaadinSession.getAttribute(SecurityContext.class); }/*from w ww .j av a2 s . c om*/ return super.get(); }
From source file:com.haulmont.cuba.web.sys.WebVaadinCompatibleSecurityContextHolder.java
License:Apache License
@Override public void set(SecurityContext securityContext) { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null && vaadinSession.hasLock()) { vaadinSession.setAttribute(SecurityContext.class, securityContext); } else {//from w w w . j av a 2 s . c o m super.set(securityContext); } }
From source file:de.metas.ui.web.vaadin.session.UserSession.java
License:Open Source License
public static final UserSession getCurrent() { final VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession == null) { return null; }//from w ww .j a v a 2s. c o m if (vaadinSession.hasLock()) { return getCurrent(vaadinSession); } else { final Mutable<UserSession> userSessionRef = new Mutable<UserSession>(); vaadinSession.accessSynchronously(new Runnable() { @Override public void run() { userSessionRef.setValue(getCurrent(vaadinSession)); } }); return userSessionRef.getValue(); } }
From source file:info.magnolia.ui.form.field.factory.AbstractFieldFactoryTestCase.java
License:Open Source License
@Before public void setUp() throws Exception { // Init Message & Providers i18NAuthoringSupport = mock(I18NAuthoringSupport.class); ComponentsTestUtil.setInstance(I18NAuthoringSupport.class, i18NAuthoringSupport); ComponentsTestUtil.setImplementation(TypeMapping.class, TypeMappingImpl.class); ComponentsTestUtil.setImplementation(Node2BeanTransformer.class, Node2BeanTransformerImpl.class); ComponentsTestUtil.setImplementation(Node2BeanProcessor.class, Node2BeanProcessorImpl.class); ComponentsTestUtil.setImplementation(MessagesManager.class, DefaultMessagesManager.class); SystemContext systemContext = mock(SystemContext.class); when(systemContext.getLocale()).thenReturn(DEFAULT_LOCALE); ComponentsTestUtil.setInstance(SystemContext.class, systemContext); VaadinSession vaadinSession = mock(VaadinSession.class); when(vaadinSession.getConverterFactory()).thenReturn(new DefaultConverterFactory()); when(vaadinSession.getLocale()).thenReturn(DEFAULT_LOCALE); when(vaadinSession.hasLock()).thenReturn(true); ComponentsTestUtil.setInstance(VaadinSession.class, vaadinSession); // Init Session session = new MockSession(workspaceName); MockContext ctx = new MockContext(); ctx.addSession(workspaceName, session); MgnlContext.setInstance(ctx);//w w w . ja va 2 s . c om // Create ConfiguredField POJO createConfiguredFieldDefinition(); // Init Node and Item. Node rootNode = session.getRootNode(); baseNode = rootNode.addNode(itemName); baseItem = new JcrNodeAdapter(baseNode); componentProvider = new MockComponentProvider(); componentProvider.setInstance(I18NAuthoringSupport.class, mock(I18NAuthoringSupport.class)); componentProvider.setInstance(UiContext.class, mock(UiContext.class)); }