use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class SessionStore method valueUnbound.
@Override
public void valueUnbound(final HttpSessionBindingEvent event) {
if (!m_httpSessionValid) {
// valueUnbound() has already been executed
return;
}
m_httpSessionValid = false;
LOG.info("Detected invalidation of HTTP session {}, cleaning up {} client sessions and {} UI sessions", m_httpSessionId, m_clientSessionMap.size(), m_uiSessionMap.size());
final List<IFuture<?>> futures = new ArrayList<>();
// Stop all client sessions (in parallel model jobs)
try {
int timeout = CONFIG.getPropertyValue(SessionStoreMaxWaitWriteLockProperty.class).intValue();
if (m_writeLock.tryLock(timeout, TimeUnit.SECONDS)) {
try {
for (final IClientSession clientSession : m_clientSessionMap.values()) {
futures.add(ModelJobs.schedule(new IRunnable() {
@Override
public void run() {
LOG.debug("Shutting down client session with ID {} due to invalidation of HTTP session", clientSession.getId());
forceClientSessionShutdown(clientSession);
removeClientSession(clientSession);
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true)).withName("Closing desktop due to HTTP session invalidation")));
}
} finally {
m_writeLock.unlock();
}
} else {
LOG.warn("Could not acquire write lock within {} seconds: [HTTP session: {}, uiSessionMap: {}, clientSessionMap: {}, uiSessionsByClientSession: {}]", timeout, m_uiSessionMap.size(), m_clientSessionMap.size(), m_uiSessionsByClientSession.size());
}
} catch (InterruptedException e) {
LOG.warn("Interrupted while waiting on session store write lock", e);
}
if (futures.isEmpty()) {
return;
}
LOG.debug("Waiting for {} client sessions to stop...", futures.size());
try {
// Wait for all client sessions to stop. This is done in sync to ensure the session is not invalidated before the attached scout session has been stopped.
// Otherwise we would have a running scout session on an invalidated http session.
// Furthermore: on webapp shutdown we must first stop all sessions (scout and http) before we stop the platform. Therefore the stop must be sync!
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(futures).toFilter(), CONFIG.getPropertyValue(SessionStoreMaxWaitAllShutdownProperty.class), TimeUnit.SECONDS);
LOG.info("Session shutdown complete.");
} catch (ThreadInterruptedError e) {
LOG.warn("Interruption encountered while waiting for all client session to stop. Continuing anyway.", e);
} catch (TimedOutError e) {
LOG.warn("Timeout encountered while waiting for all client session to stop. Canceling still running client session shutdown jobs.", e);
// timeout while waiting for the sessions to stop. Force cancel them.
Jobs.getJobManager().cancel(Jobs.newFutureFilterBuilder().andMatchFuture(futures).andMatchNotState(JobState.DONE).toFilter(), true);
}
// Check if everything was cleaned up correctly ("leak detection").
// Read map sizes outside a lock - dirty reads are acceptable here
final int uiSessionMapSize = m_uiSessionMap.size();
final int clientSessionMapSize = m_clientSessionMap.size();
final int uiSessionsByClientSessionSize = m_uiSessionsByClientSession.size();
if (uiSessionMapSize + clientSessionMapSize + uiSessionsByClientSessionSize > 0) {
LOG.warn("Leak detection - Session store not empty after HTTP session invalidation: [uiSessionMap: {}, clientSessionMap: {}, uiSessionsByClientSession: {}]", uiSessionMapSize, clientSessionMapSize, uiSessionsByClientSessionSize);
}
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class UiSession method getOrCreateClientSession.
protected IClientSession getOrCreateClientSession(HttpSession httpSession, HttpServletRequest req, JsonStartupRequest jsonStartupReq) {
String requestedClientSessionId = jsonStartupReq.getClientSessionId();
IClientSession clientSession = sessionStore().getClientSessionForUse(requestedClientSessionId);
if (clientSession != null) {
// Found existing client session
LOG.info("Using cached client session [clientSessionId={}]", clientSession.getId());
return clientSession;
}
// No client session for the requested ID was found, so create one
clientSession = createAndStartClientSession(req.getLocale(), createUserAgent(jsonStartupReq), jsonStartupReq.getSessionStartupParams());
LOG.info("Created new client session [clientSessionId={}, userAgent={}]", clientSession.getId(), clientSession.getUserAgent());
// Ensure session is active
if (!clientSession.isActive()) {
throw new UiException("ClientSession is not active, there must have been a problem with loading or starting [clientSessionId=" + clientSession.getId() + "]");
}
// in parallel.
return clientSession;
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class JsonObjectFactory method createJsonAdapter.
@SuppressWarnings("unchecked")
@Override
public IJsonAdapter<?> createJsonAdapter(Object model, IUiSession session, String id, IJsonAdapter<?> parent) {
// --- form fields ----
if (model instanceof IGroupBox) {
// we must distinct between normal group-boxes and group-boxes in tab-boxes
// the use the same model, but we need different adapters
IGroupBox groupBox = (IGroupBox) model;
if (groupBox.getParentField() instanceof ITabBox) {
return new JsonTabItem<IGroupBox>(groupBox, session, id, parent);
} else {
return new JsonGroupBox<IGroupBox>(groupBox, session, id, parent);
}
}
if (model instanceof ISequenceBox) {
return new JsonSequenceBox<ISequenceBox>((ISequenceBox) model, session, id, parent);
}
if (model instanceof ITabBox) {
return new JsonTabBox<ITabBox>((ITabBox) model, session, id, parent);
}
if (model instanceof IBooleanField) {
return new JsonCheckBoxField<IBooleanField>((IBooleanField) model, session, id, parent);
}
if (model instanceof ILabelField) {
return new JsonLabelField<ILabelField>((ILabelField) model, session, id, parent);
}
if (model instanceof IImageField) {
return new JsonImageField<IImageField>((IImageField) model, session, id, parent);
}
if (model instanceof ITableField<?>) {
return new JsonTableField<ITableField<? extends ITable>>((ITableField<?>) model, session, id, parent);
}
if (model instanceof IListBox<?>) {
return new JsonListBox((IListBox<?>) model, session, id, parent);
}
if (model instanceof ITreeField) {
return new JsonTreeField<ITreeField>((ITreeField) model, session, id, parent);
}
if (model instanceof ITreeBox<?>) {
return new JsonTreeBox<ITreeBox>((ITreeBox<?>) model, session, id, parent);
}
if (model instanceof IRadioButton<?>) {
return new JsonRadioButton<IRadioButton>((IRadioButton<?>) model, session, id, parent);
}
if (model instanceof IRadioButtonGroup<?>) {
return new JsonRadioButtonGroup<IRadioButtonGroup>((IRadioButtonGroup<?>) model, session, id, parent);
}
if (model instanceof IButton) {
return new JsonButton<IButton>((IButton) model, session, id, parent);
}
if (model instanceof IStringField) {
return new JsonStringField<IStringField>((IStringField) model, session, id, parent);
}
if (model instanceof INumberField<?>) {
return new JsonNumberField<INumberField>((INumberField<?>) model, session, id, parent);
}
if (model instanceof IProposalField2<?>) {
return new JsonProposalField2((IProposalField2<?>) model, session, id, parent);
}
if (model instanceof ISmartField2<?>) {
return new JsonSmartField2((ISmartField2<?>) model, session, id, parent);
}
if (model instanceof IContentAssistField<?, ?>) {
return new JsonSmartField((IContentAssistField<?, ?>) model, session, id, parent);
}
if (model instanceof IProposalChooser) {
return new JsonProposalChooser<IProposalChooser>((IProposalChooser) model, session, id, parent);
}
if (model instanceof IDateField) {
return new JsonDateField<IDateField>((IDateField) model, session, id, parent);
}
if (model instanceof ICalendarField<?>) {
return new JsonCalendarField<ICalendarField<? extends ICalendar>>((ICalendarField<?>) model, session, id, parent);
}
if (model instanceof IPlannerField<?>) {
return new JsonPlannerField((IPlannerField<?>) model, session, id, parent);
}
if (model instanceof IWrappedFormField<?>) {
return new JsonWrappedFormField<IWrappedFormField<? extends IForm>>((IWrappedFormField<?>) model, session, id, parent);
}
if (model instanceof ISplitBox) {
return new JsonSplitBox<ISplitBox>((ISplitBox) model, session, id, parent);
}
if (model instanceof IPlaceholderField) {
return new JsonPlaceholderField<IPlaceholderField>((IPlaceholderField) model, session, id, parent);
}
if (model instanceof IWizardProgressField) {
return new JsonWizardProgressField<IWizardProgressField>((IWizardProgressField) model, session, id, parent);
}
if (model instanceof IHtmlField) {
return new JsonHtmlField<IHtmlField>((IHtmlField) model, session, id, parent);
}
if (model instanceof IComposerField) {
return new JsonComposerField<IComposerField>((IComposerField) model, session, id, parent);
}
if (model instanceof IBeanField) {
return new JsonBeanField<IBeanField<?>>((IBeanField) model, session, id, parent);
}
if (model instanceof IFileChooserField) {
return new JsonFileChooserField<IFileChooserField>((IFileChooserField) model, session, id, parent);
}
if (model instanceof IColorField) {
return new JsonColorField<IColorField>((IColorField) model, session, id, parent);
}
if (model instanceof IBrowserField) {
return new JsonBrowserField<IBrowserField>((IBrowserField) model, session, id, parent);
}
if (model instanceof IClipboardField) {
return new JsonClipboardField<IClipboardField>((IClipboardField) model, session, id, parent);
}
// --- other model objects ---
if (model instanceof IDesktop) {
return new JsonDesktop<IDesktop>((IDesktop) model, session, id, parent);
}
if (model instanceof IFormMenu<?>) {
return new JsonFormMenu((IFormMenu<?>) model, session, id, parent);
}
if (model instanceof IMenu) {
return new JsonMenu<IMenu>((IMenu) model, session, id, parent);
}
if (model instanceof IKeyStroke) {
return new JsonKeyStroke<IKeyStroke>((IKeyStroke) model, session, id, parent);
}
if (model instanceof ISearchForm) {
return new JsonSearchForm<ISearchForm>((ISearchForm) model, session, id, parent);
}
if (model instanceof IForm) {
return new JsonForm<IForm>((IForm) model, session, id, parent);
}
if (model instanceof IMessageBox) {
return new JsonMessageBox<IMessageBox>((IMessageBox) model, session, id, parent);
}
if (model instanceof IDesktopNotification) {
return new JsonDesktopNotification<IDesktopNotification>((IDesktopNotification) model, session, id, parent);
}
if (model instanceof IOutlineViewButton) {
return new JsonOutlineViewButton<IOutlineViewButton>((IOutlineViewButton) model, session, id, parent);
}
if (model instanceof IViewButton) {
return new JsonViewButton<IViewButton>((IViewButton) model, session, id, parent);
}
if (model instanceof ISearchOutline) {
return new JsonSearchOutline<ISearchOutline>((ISearchOutline) model, session, id, parent);
}
if (model instanceof IOutline) {
return new JsonOutline<IOutline>((IOutline) model, session, id, parent);
}
if (model instanceof ITree) {
return new JsonTree<ITree>((ITree) model, session, id, parent);
}
if (model instanceof ITable) {
ITable table = (ITable) model;
IPage page = (IPage) table.getProperty(JsonOutlineTable.PROP_PAGE);
if (page != null) {
return new JsonOutlineTable<ITable>(table, session, id, parent, page);
}
return new JsonTable<ITable>(table, session, id, parent);
}
if (model instanceof IClientSession) {
return new JsonClientSession<IClientSession>((IClientSession) model, session, id, parent);
}
if (model instanceof ICalendar) {
return new JsonCalendar<ICalendar>((ICalendar) model, session, id, parent);
}
if (model instanceof CalendarComponent) {
return new JsonCalendarComponent<CalendarComponent>((CalendarComponent) model, session, id, parent);
}
if (model instanceof IPlanner<?, ?>) {
return new JsonPlanner<IPlanner>((IPlanner<?, ?>) model, session, id, parent);
}
if (model instanceof IFileChooser) {
return new JsonFileChooser<IFileChooser>((IFileChooser) model, session, id, parent);
}
if (model instanceof IAggregateTableControl) {
// needs to be before ITableControl
return new JsonAggregateTableControl<IAggregateTableControl>((IAggregateTableControl) model, session, id, parent);
}
if (model instanceof IFormTableControl) {
// needs to be before ITableControl
return new JsonFormTableControl<IFormTableControl>((IFormTableControl) model, session, id, parent);
}
if (model instanceof ITableControl) {
return new JsonTableControl<ITableControl>((ITableControl) model, session, id, parent);
}
if (model instanceof IStatusMenuMapping) {
return new JsonStatusMenuMapping<IStatusMenuMapping>((IStatusMenuMapping) model, session, id, parent);
}
return null;
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class ModelJobFutureFilterTest method test.
@Test
public void test() {
IClientSession session1 = mock(IClientSession.class);
when(session1.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
IClientSession session2 = mock(IClientSession.class);
when(session2.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
IFilter<IFuture<?>> filter = ModelJobFutureFilter.INSTANCE;
// not a model job (no Future)
assertFalse(filter.accept(null));
// not a model job (no ClientRunContext)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
// not a model job (no ClientRunContext)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
// not a model job (no mutex and not session on ClientRunContext)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty()))));
// not a model job (no mutex)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)))));
// not a model job (wrong mutex type)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(Jobs.newExecutionSemaphore(1)))));
// not a model job (different session on ClientRunContext and mutex)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(session2.getModelJobSemaphore()))));
// not a model job (no session on ClientRunContext)
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(null, false)).withExecutionSemaphore(session1.getModelJobSemaphore()))));
// this is a model job (same session on ClientRunContext and mutex)
assertTrue(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(session1.getModelJobSemaphore()))));
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class SessionFutureFilterTest method test.
@Test
public void test() {
IClientSession session1 = mock(IClientSession.class);
IClientSession session2 = mock(IClientSession.class);
SessionFutureFilter filter = new SessionFutureFilter(session1);
// Tests a Future of a job without RunContext
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
// Tests a Future of a job with RunContext
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
// Tests a Future of a job with ClientRunContext without session
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty()))));
// Tests a Future of a job with ClientRunContext with correct session
assertTrue(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)))));
// Tests a Future of a job with ClientRunContext with wrong session
assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session2, false)))));
// Test adaptable to the session
assertSame(session1, filter.getAdapter(ISession.class));
}
Aggregations