Example usage for org.springframework.web.servlet.mvc.method.annotation SseEmitter complete

List of usage examples for org.springframework.web.servlet.mvc.method.annotation SseEmitter complete

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.method.annotation SseEmitter complete.

Prototype

public synchronized void complete() 

Source Link

Document

Complete request processing by performing a dispatch into the servlet container, where Spring MVC is invoked once more, and completes the request processing lifecycle.

Usage

From source file:com.bodybuilding.argos.controller.SseEmitterUtil.java

/**
 * Binds the supplied observable to the SseEmitter. onNext will call the send method on SseEmitter, the Observable
 * subscription will automatically be cancelled when the emitter completes or times out.
 * @param emitter SseEmitter//  www . j a  v a  2  s. co  m
 * @param observable Observable that will supply the data
 * @return Subscription to the Observable
 */
public static <T> Subscription bindObservable(SseEmitter emitter, Observable<T> observable) {
    Subscription subscription = observable.subscribe(new Subscriber<T>() {
        @Override
        public void onCompleted() {
            emitter.complete();
        }

        @Override
        public void onError(Throwable e) {
            LOG.warn("Error from stream observable", e);
            emitter.completeWithError(e);
        }

        @Override
        public void onNext(T t) {
            emitSse(emitter, t);
        }
    });
    bindUnsubscribe(emitter, subscription);
    return subscription;
}