Search in sources :

Example 11 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class AbstractObservableNotificationHandler method sessionChanged.

/**
 * Automatically removes listeners for stopped sessions.
 */
@Override
public void sessionChanged(SessionEvent event) {
    if (event.getType() == SessionEvent.TYPE_STOPPED) {
        // only interested in session stopped
        ISession session = Assertions.assertNotNull(event.getSource());
        if (session instanceof IClientSession) {
            IClientSession clientSession = (IClientSession) session;
            synchronized (m_listeners) {
                for (INotificationListener<T> notificationListener : getListeners(clientSession)) {
                    removeListener(clientSession, notificationListener);
                    LOG.warn("Auto fallback removal of session listener due to stopped session. This must be done explicitly by the one that registered the listener: {}", notificationListener);
                }
            }
        }
    }
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 12 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class ClientSessionRegistry method sessionStopped.

/**
 * this method is expected to be called in the context of the specific session.
 *
 * @param session
 */
protected void sessionStopped(final IClientSession session) {
    checkSession(session);
    final String sessionId = session.getId();
    final String userId = session.getUserId();
    LOG.debug("Unregister client session [sessionid={}, userId={}].", sessionId, userId);
    // client session household
    synchronized (m_cacheLock) {
        m_sessionIdToSession.remove(session.getId());
        List<WeakReference<IClientSession>> userSessions = m_userToSessions.get(userId);
        if (userSessions != null) {
            for (Iterator<WeakReference<IClientSession>> it = userSessions.iterator(); it.hasNext(); ) {
                WeakReference<IClientSession> ref = it.next();
                IClientSession clientSession = ref.get();
                if (clientSession == null || ObjectUtility.equals(clientSession.getId(), session.getId())) {
                    it.remove();
                }
            }
            if (userSessions.isEmpty()) {
                m_userToSessions.remove(userId);
            }
        }
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 13 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class BookmarkService method getServiceState.

private ServiceState getServiceState() {
    IClientSession session = ClientSessionProvider.currentSession();
    if (session == null) {
        throw new IllegalStateException("null client session in current job context");
    }
    ServiceState data = (ServiceState) session.getData(SESSION_DATA_KEY);
    if (data == null) {
        data = new ServiceState();
        data.m_model = new BookmarkData();
        session.setData(SESSION_DATA_KEY, data);
    }
    return data;
}
Also used : BookmarkData(org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkData) IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 14 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class SharedContextNotificationHandler method handleNotification.

@Override
public void handleNotification(SharedContextChangedNotification notification) {
    // the client session must be available for shared context variable updates otherwise it is a wrong usage of the notification.
    IClientSession session = (IClientSession) Assertions.assertNotNull(IClientSession.CURRENT.get());
    session.replaceSharedVariableMapInternal(notification.getSharedVariableMap());
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 15 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class PageDataExtensionTest method before.

@Before
public void before() {
    final IClientSession session = Mockito.mock(IClientSession.class);
    System.setProperty("user.area", "${user.home}/test");
    Mockito.when(session.getUserId()).thenReturn("userid");
    Mockito.when(session.getUserAgent()).thenReturn(UserAgents.createDefault());
    ISession.CURRENT.set(session);
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession) Before(org.junit.Before)

Aggregations

IClientSession (org.eclipse.scout.rt.client.IClientSession)30 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)11 Test (org.junit.Test)11 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)4 Subject (javax.security.auth.Subject)3 HttpSession (javax.servlet.http.HttpSession)3 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)3 IFuture (org.eclipse.scout.rt.platform.job.IFuture)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 ISession (org.eclipse.scout.rt.shared.ISession)3 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)3 WeakReference (java.lang.ref.WeakReference)2 Locale (java.util.Locale)2 Callable (java.util.concurrent.Callable)2 IMessageBox (org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)2 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)2 JobEventData (org.eclipse.scout.rt.platform.job.listener.JobEventData)2 NlsLocale (org.eclipse.scout.rt.platform.nls.NlsLocale)2 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)2 SessionStoreTestForm (org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm)2