users@jax-rs-spec.java.net

[jax-rs-spec users] Re: Server-Sent Events API proposal​ - update

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Fri, 10 Feb 2017 09:41:42 +0000

Ex,

Sse.instance().newBroadcaster();

where

Sse.instance() returns an implementation specific factory, with the
.instance() implemented using a factory finder mechanism or
RuntimeDelegate, the same way it is done for MediaType for example.
Probably better prefer a factory finder approach as for example in CXF
we have a dedicated module for SSE separate from the core though
RuntimeDelegate only will work.
That will be still clean, and implemented in terms of the core JAX-RS
mechanisms.

I honestly believe we must not make the use of @Inject to have SSE
operational a requirement for JAX-RS 2.x.

Thanks, Sergey
On 09/02/17 23:52, Sergey Beryozkin wrote:
> So supporting @Inject is a must now for JAX-RS 2.1 which a minor
> maintenance release ?
>
> What is it ? @Context for one thing, @Inject for another one, both
> parts being related to SSE ?
>
> Can that Sse be rather mapped to RuntimeDelegate ?
>
> I regret I raised that Broadcaster issue...
>
> Sergey
>
> On 09/02/17 21:22, Pavel Bucek wrote:
>>
>> Dear experts,
>>
>> thanks for all the feedback you've provided on presented Server Sent
>> Events proposal.
>>
>> Based on your feedback (and other inputs, most of them from Marek,
>> the original author of SSE proposal), we'd like to present another
>> iteration.
>>
>> *List of changes:*
>>
>> - SseEventInput is gone.
>> - We don't need to be able to receive events in blocking fashion.
>> If a user needs to do that, he still can - using a Deque and onEvent
>> consumer (and some synchronization).
>> - SseClientSubscriber is gone.
>> - replaced by EventSource#subscribe(Consumer<InboundSseEvent>)
>> and other overloads.
>> - SseEventOuput is now SseEventSink (the opposite to SseEventSource).
>> - SseContext is now Sse (its not a context).
>> - Introduced SseSubscription (which will extend Flow.Subsription when
>> we can use Java SE 9).
>> - SseEventSink (used to be SseEventOutput) is now injectable - there
>> is no other way how to create it:
>>
>> @GET @Path("events")
>> @Produces(MediaType.SERVER_SENT_EVENTS)
>> public void itemEvents(@Context SseEventSink serverSink) {
>> serverSink.onNext(sse.newEvent().data("welcome").build());
>> broadcaster.subscribe(serverSink);
>> }
>>
>> please note that the resource method now doesn't return injected
>> SseEventSink - it's more similar to the pattern used in async API and
>> users don't need to repeat "sseContext.newEventOutput();" and "return
>> eventOutput;".
>>
>> All these changes are done in a single commit:
>> https://github.com/jax-rs/api/commit/459ddb615861959e4899b48d0b88498100308bcd
>>
>> We also added couple of helper methods to create an outbound event:
>> https://github.com/jax-rs/api/commit/8a61f14b2797cfa22da1c0fdb1b5a321ca435c8b
>>
>> Please let us know what you think.
>>
>> Thanks and regards,
>> Pavel & Santiago
>
>