use of org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector 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.server.clientnotification.ClientNotificationCollector in project scout.rt by eclipse.
the class ServiceTunnelServlet method doPost.
protected ServiceTunnelResponse doPost(ServiceTunnelRequest serviceRequest) throws ServletException {
ClientNotificationCollector collector = new ClientNotificationCollector();
ServerRunContext serverRunContext = ServerRunContexts.copyCurrent().withLocale(serviceRequest.getLocale()).withUserAgent(UserAgents.createByIdentifier(serviceRequest.getUserAgent())).withClientNotificationCollector(collector).withClientNodeId(serviceRequest.getClientNodeId());
if (serviceRequest.getSessionId() != null) {
serverRunContext.withSession(lookupServerSessionOnHttpSession(serviceRequest.getSessionId(), serverRunContext));
}
final IRegistrationHandle registrationHandle = registerForCancellation(serverRunContext, serviceRequest);
try {
ServiceTunnelResponse serviceResponse = invokeService(serverRunContext, serviceRequest);
// include client notifications in response (piggyback)
serviceResponse.setNotifications(collector.consume());
return serviceResponse;
} finally {
registrationHandle.unregister();
}
}
Aggregations