Search in sources :

Example 6 with IClientSession

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

the class JobListenerBlockedFutureTest method testEventsForBlockingJob.

@Test(timeout = 10000)
public void testEventsForBlockingJob() {
    final IBlockingCondition condition = Jobs.newBlockingCondition(true);
    IClientSession clientSession = mock(IClientSession.class);
    when(clientSession.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    JobEventCaptureListener captureListener = new JobEventCaptureListener();
    Jobs.getJobManager().addListener(ModelJobs.newEventFilterBuilder().toFilter(), captureListener);
    IFuture<Void> outerFuture = null;
    final AtomicReference<IFuture<?>> innerFuture = new AtomicReference<>();
    final JobInput modelJobInput = ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true));
    // start recording of events
    outerFuture = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            innerFuture.set(Jobs.getJobManager().schedule(new IRunnable() {

                @Override
                public void run() throws Exception {
                    condition.setBlocking(false);
                    // Wait until the outer future is re-acquiring the mutex.
                    // 2=outer-job + inner-job
                    JobTestUtil.waitForPermitCompetitors(modelJobInput.getExecutionSemaphore(), 2);
                }
            }, modelJobInput.copy().withName("inner").withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(2, TimeUnit.SECONDS))));
            condition.waitFor();
        }
    }, modelJobInput.copy().withName("outer"));
    Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(outerFuture).toFilter(), 1, TimeUnit.MINUTES);
    Jobs.getJobManager().shutdown();
    // verify events
    int i = -1;
    List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
    List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.SCHEDULED, capturedEvents.get(i));
    assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
    assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.RUNNING, capturedEvents.get(i));
    assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
    // inner
    i++;
    assertStateChangedEvent(innerFuture.get(), JobState.SCHEDULED, capturedEvents.get(i));
    assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
    // inner
    i++;
    assertStateChangedEvent(innerFuture.get(), JobState.PENDING, capturedEvents.get(i));
    assertEquals(JobState.PENDING, capturedFutureStates.get(i));
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.WAITING_FOR_BLOCKING_CONDITION, capturedEvents.get(i));
    assertEquals(JobState.WAITING_FOR_BLOCKING_CONDITION, capturedFutureStates.get(i));
    // inner
    i++;
    assertStateChangedEvent(innerFuture.get(), JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
    assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
    // inner
    i++;
    assertStateChangedEvent(innerFuture.get(), JobState.RUNNING, capturedEvents.get(i));
    assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
    assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
    // inner
    i++;
    assertStateChangedEvent(innerFuture.get(), JobState.DONE, capturedEvents.get(i));
    assertEquals(JobState.DONE, capturedFutureStates.get(i));
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.RUNNING, capturedEvents.get(i));
    assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
    // outer
    i++;
    assertStateChangedEvent(outerFuture, JobState.DONE, capturedEvents.get(i));
    assertEquals(JobState.DONE, capturedFutureStates.get(i));
    assertEquals(i + 1, capturedEvents.size());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IFuture(org.eclipse.scout.rt.platform.job.IFuture) JobInput(org.eclipse.scout.rt.platform.job.JobInput) JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) IClientSession(org.eclipse.scout.rt.client.IClientSession) JobState(org.eclipse.scout.rt.platform.job.JobState) IBlockingCondition(org.eclipse.scout.rt.platform.job.IBlockingCondition) Test(org.junit.Test)

Example 7 with IClientSession

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

the class SessionStore method registerUiSession.

@Override
public void registerUiSession(final IUiSession uiSession) {
    Assertions.assertNotNull(uiSession);
    LOG.debug("Register UI session with ID {} in store (clientSessionId={})", uiSession.getUiSessionId(), uiSession.getClientSessionId());
    m_writeLock.lock();
    try {
        IClientSession clientSession = uiSession.getClientSession();
        // Store UI session
        m_uiSessionMap.put(uiSession.getUiSessionId(), uiSession);
        // Store client session (in case it was not yet stored)
        m_clientSessionMap.put(clientSession.getId(), clientSession);
        // Link to client session
        Set<IUiSession> map = m_uiSessionsByClientSession.get(clientSession);
        if (map == null) {
            map = new HashSet<>();
            m_uiSessionsByClientSession.put(clientSession, map);
        }
        map.add(uiSession);
    } finally {
        m_writeLock.unlock();
    }
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 8 with IClientSession

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

the class SessionStore method unregisterUiSession.

@Override
public void unregisterUiSession(final IUiSession uiSession) {
    if (uiSession == null) {
        return;
    }
    LOG.debug("Unregister UI session with ID {} from store (clientSessionId={})", uiSession.getUiSessionId(), uiSession.getClientSessionId());
    m_writeLock.lock();
    try {
        // Remove uiSession
        m_uiSessionMap.remove(uiSession.getUiSessionId());
        // Unlink uiSession from clientSession
        final IClientSession clientSession = uiSession.getClientSession();
        Set<IUiSession> map = m_uiSessionsByClientSession.get(clientSession);
        if (map != null) {
            map.remove(uiSession);
        }
        // Start housekeeping
        LOG.debug("{} UI sessions remaining for client session {}", (map == null ? 0 : map.size()), clientSession.getId());
        if (map == null || map.isEmpty()) {
            m_uiSessionsByClientSession.remove(clientSession);
            if (uiSession.isPersistent()) {
                // don't start housekeeping for persistent sessions to give the users more time on app switches in ios home screen mode
                return;
            }
            startHousekeeping(clientSession);
        }
    } finally {
        m_writeLock.unlock();
    }
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 9 with IClientSession

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

the class SessionStore method getClientSessionForUse.

@Override
public IClientSession getClientSessionForUse(String clientSessionId) {
    if (clientSessionId == null) {
        return null;
    }
    m_writeLock.lock();
    try {
        // If housekeeping is scheduled for this session, cancel it (session will be used again, so no cleanup necessary)
        IFuture<?> future = m_housekeepingFutures.get(clientSessionId);
        if (future != null) {
            LOG.debug("Client session with ID {} reserved for use - session housekeeping cancelled!", clientSessionId);
            future.cancel(false);
            m_housekeepingFutures.remove(clientSessionId);
        }
        IClientSession clientSession = m_clientSessionMap.get(clientSessionId);
        if (clientSession != null && (!clientSession.isActive() || clientSession.isStopping())) {
            // only return active sessions
            clientSession = null;
        }
        return clientSession;
    } finally {
        m_writeLock.unlock();
    }
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 10 with IClientSession

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

the class AbstractObservableNotificationHandler method notifyListenersOfAllSessions.

/**
 * Notify all listeners independent of the session in the current {@link RunContext}
 */
protected void notifyListenersOfAllSessions(final T notification) {
    // create copy of m_listeners (EventListenerList is thread-safe)
    Map<IClientSession, EventListenerList> listenerMap;
    synchronized (m_listeners) {
        listenerMap = new HashMap<>(m_listeners);
    }
    // schedule model job per session to handle notifications
    for (Entry<IClientSession, EventListenerList> entry : listenerMap.entrySet()) {
        final IClientSession session = entry.getKey();
        final EventListenerList list = entry.getValue();
        scheduleHandlingNotifications(notification, list, session);
    }
}
Also used : EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) IClientSession(org.eclipse.scout.rt.client.IClientSession)

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