Class ServerSentEvents
- java.lang.Object
-
- com.linecorp.armeria.server.streaming.ServerSentEvents
-
public final class ServerSentEvents extends Object
A utility class which helps to create a Server-Sent Events stream from a contentPublisher
orStream
.A user simply creates a streaming
HttpResponse
which emits Server-Sent Events, e.g.Server server = Server.builder() // Emit Server-Sent Events with the SeverSentEvent instances published by a publisher. .service("/sse1", (ctx, req) -> ServerSentEvents.fromPublisher( Flux.just(ServerSentEvent.ofData("foo"), ServerSentEvent.ofData("bar")))) // Emit Server-Sent Events with converting instances published by a publisher into // ServerSentEvent instances. .service("/sse2", (ctx, req) -> ServerSentEvents.fromPublisher( Flux.just("foo", "bar"), ServerSentEvent::ofData)) .build();
-
-
Method Summary
Modifier and Type Method Description static HttpResponse
fromEvent(ResponseHeaders headers, ServerSentEvent sse)
Creates a new Server-Sent Events stream of the specifiedcontent
.static HttpResponse
fromEvent(ResponseHeaders headers, ServerSentEvent sse, HttpHeaders trailers)
Creates a new Server-Sent Events stream of the specifiedcontent
.static HttpResponse
fromEvent(ServerSentEvent sse)
Creates a new Server-Sent Events stream of the specifiedcontent
.static HttpResponse
fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Creates a new Server-Sent Events stream from the specifiedPublisher
.static HttpResponse
fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher, HttpHeaders trailers)
Creates a new Server-Sent Events stream from the specifiedPublisher
.static <T> HttpResponse
fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<T> contentPublisher, HttpHeaders trailers, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedPublisher
andconverter
.static <T> HttpResponse
fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<T> contentPublisher, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedPublisher
andconverter
.static HttpResponse
fromPublisher(org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Creates a new Server-Sent Events stream from the specifiedPublisher
.static <T> HttpResponse
fromPublisher(org.reactivestreams.Publisher<T> contentPublisher, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedPublisher
andconverter
.static HttpResponse
fromStream(ResponseHeaders headers, Stream<? extends ServerSentEvent> contentStream, HttpHeaders trailers, Executor executor)
Creates a new Server-Sent Events stream from the specifiedStream
.static HttpResponse
fromStream(ResponseHeaders headers, Stream<? extends ServerSentEvent> contentStream, Executor executor)
Creates a new Server-Sent Events stream from the specifiedStream
.static <T> HttpResponse
fromStream(ResponseHeaders headers, Stream<T> contentStream, HttpHeaders trailers, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedStream
andconverter
.static <T> HttpResponse
fromStream(ResponseHeaders headers, Stream<T> contentStream, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedStream
andconverter
.static HttpResponse
fromStream(Stream<? extends ServerSentEvent> contentStream, Executor executor)
Creates a new Server-Sent Events stream from the specifiedStream
.static <T> HttpResponse
fromStream(Stream<T> contentStream, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedStream
andconverter
.
-
-
-
Method Detail
-
fromPublisher
public static HttpResponse fromPublisher(org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Creates a new Server-Sent Events stream from the specifiedPublisher
.- Parameters:
contentPublisher
- thePublisher
which publishes the objects supposed to send as contents
-
fromPublisher
public static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Creates a new Server-Sent Events stream from the specifiedPublisher
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contents
-
fromPublisher
public static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher, HttpHeaders trailers)
Creates a new Server-Sent Events stream from the specifiedPublisher
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contentstrailers
- the HTTP trailers
-
fromPublisher
public static <T> HttpResponse fromPublisher(org.reactivestreams.Publisher<T> contentPublisher, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedPublisher
andconverter
.- Parameters:
contentPublisher
- thePublisher
which publishes the objects supposed to send as contentsconverter
- the converter which converts published objects intoServerSentEvent
s
-
fromPublisher
public static <T> HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<T> contentPublisher, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedPublisher
andconverter
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contentsconverter
- the converter which converts published objects intoServerSentEvent
s
-
fromPublisher
public static <T> HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<T> contentPublisher, HttpHeaders trailers, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedPublisher
andconverter
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contentstrailers
- the HTTP trailersconverter
- the converter which converts published objects intoServerSentEvent
s
-
fromStream
public static HttpResponse fromStream(Stream<? extends ServerSentEvent> contentStream, Executor executor)
Creates a new Server-Sent Events stream from the specifiedStream
.- Parameters:
contentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the stream
-
fromStream
public static HttpResponse fromStream(ResponseHeaders headers, Stream<? extends ServerSentEvent> contentStream, Executor executor)
Creates a new Server-Sent Events stream from the specifiedStream
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the stream
-
fromStream
public static HttpResponse fromStream(ResponseHeaders headers, Stream<? extends ServerSentEvent> contentStream, HttpHeaders trailers, Executor executor)
Creates a new Server-Sent Events stream from the specifiedStream
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentstrailers
- the HTTP trailersexecutor
- the executor which iterates the stream
-
fromStream
public static <T> HttpResponse fromStream(Stream<T> contentStream, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedStream
andconverter
.- Parameters:
contentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the streamconverter
- the converter which converts published objects intoServerSentEvent
s
-
fromStream
public static <T> HttpResponse fromStream(ResponseHeaders headers, Stream<T> contentStream, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedStream
andconverter
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the streamconverter
- the converter which converts published objects intoServerSentEvent
s
-
fromStream
public static <T> HttpResponse fromStream(ResponseHeaders headers, Stream<T> contentStream, HttpHeaders trailers, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specifiedStream
andconverter
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentstrailers
- the HTTP trailersexecutor
- the executor which iterates the streamconverter
- the converter which converts published objects intoServerSentEvent
s
-
fromEvent
public static HttpResponse fromEvent(ServerSentEvent sse)
Creates a new Server-Sent Events stream of the specifiedcontent
.- Parameters:
sse
- theServerSentEvent
object supposed to send as contents
-
fromEvent
public static HttpResponse fromEvent(ResponseHeaders headers, ServerSentEvent sse)
Creates a new Server-Sent Events stream of the specifiedcontent
.- Parameters:
headers
- the HTTP headers supposed to sendsse
- theServerSentEvent
object supposed to send as contents
-
fromEvent
public static HttpResponse fromEvent(ResponseHeaders headers, ServerSentEvent sse, HttpHeaders trailers)
Creates a new Server-Sent Events stream of the specifiedcontent
.- Parameters:
headers
- the HTTP headers supposed to sendsse
- theServerSentEvent
object supposed to send as contentstrailers
- the HTTP trailers
-
-