Search in sources :

Example 16 with ISession

use of org.eclipse.scout.rt.shared.ISession in project scout.rt by eclipse.

the class ServerTestRunnerSameSessionTest method test2.

@Test
public void test2() {
    ISession serverSession = IServerSession.CURRENT.get();
    assertTrue(serverSession instanceof JUnitServerSession);
    assertEquals("anna", serverSession.getUserId());
    m_serverSessions.add(serverSession);
    ITransaction transaction = ITransaction.CURRENT.get();
    assertNotNull(transaction);
    m_transactions.add(transaction);
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) ITransaction(org.eclipse.scout.rt.platform.transaction.ITransaction) JUnitServerSession(org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerSameSessionTest.JUnitServerSession) Test(org.junit.Test)

Example 17 with ISession

use of org.eclipse.scout.rt.shared.ISession in project scout.rt by eclipse.

the class ServerTestRunnerSameSessionTest method afterClass.

@AfterClass
public static void afterClass() {
    ISession serverSession = IServerSession.CURRENT.get();
    assertTrue(serverSession instanceof JUnitServerSession);
    assertEquals("anna", serverSession.getUserId());
    m_serverSessions.add(serverSession);
    ITransaction transaction = ITransaction.CURRENT.get();
    assertNotNull(transaction);
    m_transactions.add(transaction);
    assertEquals(1, m_serverSessions.size());
    // (beforeClass), (before,test1,after), (before,test2,after), (afterClass)
    assertEquals(4, m_transactions.size());
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) ITransaction(org.eclipse.scout.rt.platform.transaction.ITransaction) JUnitServerSession(org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerSameSessionTest.JUnitServerSession) AfterClass(org.junit.AfterClass)

Example 18 with ISession

use of org.eclipse.scout.rt.shared.ISession in project scout.rt by eclipse.

the class ServerTestRunnerSameSessionTest method test1.

@Test
public void test1() {
    ISession serverSession = IServerSession.CURRENT.get();
    assertTrue(serverSession instanceof JUnitServerSession);
    assertEquals("anna", serverSession.getUserId());
    m_serverSessions.add(serverSession);
    ITransaction transaction = ITransaction.CURRENT.get();
    assertNotNull(transaction);
    m_transactions.add(transaction);
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) ITransaction(org.eclipse.scout.rt.platform.transaction.ITransaction) JUnitServerSession(org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerSameSessionTest.JUnitServerSession) Test(org.junit.Test)

Example 19 with ISession

use of org.eclipse.scout.rt.shared.ISession in project scout.rt by eclipse.

the class ClientNotificationDispatcher method dispatchForSession.

/**
 * Dispatch notifications within the context of a session.<br>
 * Dispatching is always done asynchronously to ensure that it is not handled within a model thread.
 *
 * @param session
 *          the session describes the runcontext in which the notification should be processed.
 * @param notification
 *          the notification to process.
 */
public void dispatchForSession(IClientSession session, final Serializable notification, final IClientNotificationAddress address) {
    ISession currentSession = ISession.CURRENT.get();
    // sync dispatch if session is equal
    if (session == currentSession) {
        dispatchSync(notification, address);
    } else {
        IFuture<Void> future = Jobs.schedule(new IRunnable() {

            @Override
            public void run() throws Exception {
                dispatchSync(notification, address);
            }
        }, Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session, true).withCorrelationId(CorrelationId.CURRENT.get())).withName("Dispatching client notification"));
        addPendingNotification(future);
        future.whenDone(new P_NotificationFutureCallback(future), null);
    }
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable)

Example 20 with ISession

use of org.eclipse.scout.rt.shared.ISession in project scout.rt by eclipse.

the class BridgeToServerBeanDecorator method ensureRunInServerContext.

protected Object ensureRunInServerContext(final IBeanInvocationContext<T> context) {
    if (PropertyMap.isSet(PropertyMap.PROP_SERVER_SCOPE)) {
        // already in a server scope
        return continueCall(context);
    }
    // bridge to server scope
    ClientNotificationCollector collector = new ClientNotificationCollector();
    ServerRunContext bridgeRunContext = ServerRunContexts.copyCurrent().withClientNotificationCollector(collector).withClientNodeId(INode.ID);
    ISession currentSession = ISession.CURRENT.get();
    IServerSession bridgeSession = null;
    if (currentSession != null) {
        bridgeSession = BEANS.get(ServerSessionProviderWithCache.class).provide(currentSession.getId(), bridgeRunContext);
    }
    Object result = bridgeRunContext.withSession(bridgeSession).call(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                return continueCall(context);
            } catch (Exception e) {
                ITransaction.CURRENT.get().addFailure(e);
                throw e;
            }
        }
    });
    ClientNotificationDispatcher clientNotificationDispatcher = BEANS.get(ClientNotificationDispatcher.class);
    List<ClientNotificationMessage> values = collector.consume();
    if (!values.isEmpty()) {
        clientNotificationDispatcher.dispatchNotifications(values);
    }
    return result;
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) ServerRunContext(org.eclipse.scout.rt.server.context.ServerRunContext) IServerSession(org.eclipse.scout.rt.server.IServerSession) ClientNotificationCollector(org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) ClientNotificationDispatcher(org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)

Aggregations

ISession (org.eclipse.scout.rt.shared.ISession)33 Test (org.junit.Test)14 ITransaction (org.eclipse.scout.rt.platform.transaction.ITransaction)13 AfterClass (org.junit.AfterClass)6 BeforeClass (org.junit.BeforeClass)6 JUnitClientSession1 (org.eclipse.scout.rt.testing.client.runner.ClientTestRunnerDifferentSessionTest.JUnitClientSession1)4 JUnitClientSession (org.eclipse.scout.rt.testing.client.runner.ClientTestRunnerDifferentSubjectTest.JUnitClientSession)4 JUnitClientSession (org.eclipse.scout.rt.testing.client.runner.ClientTestRunnerSameSessionTest.JUnitClientSession)4 JUnitServerSession1 (org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerDifferentSessionTest.JUnitServerSession1)4 JUnitServerSession (org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerDifferentSubjectTest.JUnitServerSession)4 JUnitServerSession (org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerSameSessionTest.JUnitServerSession)4 RunWithSubject (org.eclipse.scout.rt.testing.platform.runner.RunWithSubject)2 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 ClientNotificationDispatcher (org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)1 RunContext (org.eclipse.scout.rt.platform.context.RunContext)1 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1 ClientNotificationCollector (org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector)1 ServerRunContext (org.eclipse.scout.rt.server.context.ServerRunContext)1 ClusterNotificationProperties (org.eclipse.scout.rt.server.services.common.clustersync.internal.ClusterNotificationProperties)1