javax.ws.rs.sse.SseBroadcaster Java Examples

The following examples show how to use javax.ws.rs.sse.SseBroadcaster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsynchronousResources.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
@Produces(SERVER_SENT_EVENTS)
@Path("/sse/broadcast")
@GET
public void getSseBroadcast(@Context final SseEventSink eventSink,
                            @Context final Sse sse) {
    eventSink.send(sse.newEvent("bar"));
    final SseBroadcaster sseBroadcaster = sse.newBroadcaster();
    sseBroadcaster.register(eventSink);

    scheduleSseEventSend(new SseEmitter() {
        @Override
        public CompletionStage<?> emit(final OutboundSseEvent event) {
            return sseBroadcaster.broadcast(event);
        }

        @Override
        public void close() {
            sseBroadcaster.close();
        }
    }, sse, Refs.of(0), ctx.executionContext().executor());
}
 
Example #2
Source File: SseResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public void subscribe(@Context SseEventSink sink) throws IOException {
    if (sink == null) {
        throw new IllegalStateException("No client connected.");
    }
    SseBroadcaster sseBroadcaster = sse.newBroadcaster();

    sseBroadcaster.register(sink);
    sseBroadcaster.broadcast(sse.newEventBuilder().data("hello").build());
}
 
Example #3
Source File: ServerSentService.java    From javaee8-cookbook with Apache License 2.0 4 votes vote down vote up
SseBroadcaster getSseBroadcaster() {
    return sseBroadcaster;
}
 
Example #4
Source File: MCREventHandler.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
MCRObjectHandler(SseBroadcaster sseBroadcaster, Sse sse,
    Function<URI, URI> uriResolver) {
    this.sseBroadcaster = sseBroadcaster;
    this.sse = sse;
    this.uriResolver = uriResolver;
}
 
Example #5
Source File: MCREventHandler.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
MCRDerivateHandler(SseBroadcaster sseBroadcaster, Sse sse, Function<URI, URI> uriResolver) {
    this.sseBroadcaster = sseBroadcaster;
    this.sse = sse;
    this.uriResolver = uriResolver;
}
 
Example #6
Source File: MCREventHandler.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
MCRPathHandler(SseBroadcaster sseBroadcaster, Sse sse, Function<URI, URI> uriResolver, ServletContext context) {
    this.sseBroadcaster = sseBroadcaster;
    this.sse = sse;
    this.context = context;
    this.uriResolver = uriResolver;
}
 
Example #7
Source File: SseImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public SseBroadcaster newBroadcaster() {
    return new SseBroadcasterImpl();
}