Search in sources :

Example 1 with ClientNotificationCollector

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

Example 2 with ClientNotificationCollector

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();
    }
}
Also used : ServerRunContext(org.eclipse.scout.rt.server.context.ServerRunContext) ClientNotificationCollector(org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector) IRegistrationHandle(org.eclipse.scout.rt.server.context.RunMonitorCancelRegistry.IRegistrationHandle) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse)

Aggregations

ClientNotificationCollector (org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector)2 ServerRunContext (org.eclipse.scout.rt.server.context.ServerRunContext)2 ClientNotificationDispatcher (org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1 IRegistrationHandle (org.eclipse.scout.rt.server.context.RunMonitorCancelRegistry.IRegistrationHandle)1 ISession (org.eclipse.scout.rt.shared.ISession)1 ClientNotificationMessage (org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage)1 ServiceTunnelResponse (org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse)1