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);
}
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());
}
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);
}
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);
}
}
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;
}
Aggregations