use of org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher in project scout.rt by eclipse.
the class ClientHttpServiceTunnel method dispatchClientNotifications.
/**
* dispatch notifications in a client job and ensure to wait for dispatched notifications
*
* @param notifications
* the notifications to dispatch
*/
protected void dispatchClientNotifications(final List<ClientNotificationMessage> notifications) {
if (CollectionUtility.isEmpty(notifications)) {
return;
}
final IBlockingCondition cond = Jobs.newBlockingCondition(true);
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
ClientNotificationDispatcher notificationDispatcher = BEANS.get(ClientNotificationDispatcher.class);
notificationDispatcher.dispatchNotifications(notifications);
}
}, Jobs.newInput().withRunContext(ClientRunContexts.copyCurrent())).whenDone(new IDoneHandler<Void>() {
@Override
public void onDone(DoneEvent<Void> event) {
cond.setBlocking(false);
}
}, null);
cond.waitFor();
}
use of org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher 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;
}
use of org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher in project scout.rt by eclipse.
the class NotificationDispatcherTest method testStringNotification.
@Test
public void testStringNotification() {
final IBlockingCondition cond = Jobs.newBlockingCondition(true);
final String stringNotification = "A simple string notification";
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
final ClientNotificationDispatcher dispatcher = BEANS.get(ClientNotificationDispatcher.class);
dispatcher.dispatchForSession((IClientSession) IClientSession.CURRENT.get(), stringNotification, mock(ClientNotificationAddress.class));
waitForPendingNotifications(dispatcher);
}
}, Jobs.newInput().withRunContext(ClientRunContexts.copyCurrent())).whenDone(new IDoneHandler<Void>() {
@Override
public void onDone(DoneEvent<Void> event) {
cond.setBlocking(false);
}
}, null);
cond.waitFor();
Mockito.verify(m_globalNotificationHanlder, Mockito.times(1)).handleNotification(Mockito.any(Serializable.class));
Mockito.verify(m_groupNotificationHanlder, Mockito.times(0)).handleNotification(Mockito.any(INotificationGroup.class));
}
use of org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher in project scout.rt by eclipse.
the class NotificationDispatcherTest method testSuperClassNotification.
@Test
public void testSuperClassNotification() {
final IBlockingCondition cond = Jobs.newBlockingCondition(true);
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
ClientNotificationDispatcher dispatcher = BEANS.get(ClientNotificationDispatcher.class);
dispatcher.dispatchForSession((IClientSession) IClientSession.CURRENT.get(), new Notification01(), mock(ClientNotificationAddress.class));
dispatcher.dispatchForSession((IClientSession) IClientSession.CURRENT.get(), new Notification02(), mock(ClientNotificationAddress.class));
dispatcher.dispatchForSession((IClientSession) IClientSession.CURRENT.get(), new Notification02(), mock(ClientNotificationAddress.class));
waitForPendingNotifications(dispatcher);
}
}, Jobs.newInput().withRunContext(ClientRunContexts.copyCurrent())).whenDone(new IDoneHandler<Void>() {
@Override
public void onDone(DoneEvent<Void> event) {
cond.setBlocking(false);
}
}, null);
cond.waitFor();
Mockito.verify(m_globalNotificationHanlder, Mockito.times(3)).handleNotification(Mockito.any(Serializable.class));
Mockito.verify(m_groupNotificationHanlder, Mockito.times(2)).handleNotification(Mockito.any(INotificationGroup.class));
}
Aggregations