[undertow-dev] SSE: testing time between events

Ryan Dewell ryan at dewell.org
Tue May 2 11:07:43 EDT 2017


Ah, now I get it.  I was thinking of “connected” in the wrong way.  Thank you!

Ryan

On May 1, 2017, 9:43 PM -0600, Stuart Douglas <sdouglas at redhat.com>, wrote:
> If you want to use a pattern like that you can create another thread
> inside the connected() method.
>
> In general though blocking a thread is not a great way to handle this
> as you need one thread per connection. You would generally register
> the created endpoint somewhere in connected, and then whenever an
> event is generated send the message from whatever thread generated the
> event.
>
> Stuart
>
> On Tue, May 2, 2017 at 11:19 AM, Ryan Dewell <ryan at dewell.org> wrote:
> > OK, on connected I could send say the 10 “events” which occurred since
> > “lastEventId”.
> >
> > Once the connection has been established/connected, where do I send the next
> > N events, that maybe occur minutes after the initial “connected”.
> >
> > In my mind I thought this all occurred inside “connected”. Meaning
> > connected would wait until some new events were available, send those, ad
> > infinitum.
> >
> > Thanks,
> >
> > Ryan
> >
> >
> > On May 1, 2017, 6:20 PM -0600, Stuart Douglas <sdouglas at redhat.com>, wrote:
> >
> > When you send you are blocking the IO thread, so the events don't
> > actually get put on the wire till the IO thread returns.
> >
> > Stuart
> >
> > On Tue, May 2, 2017 at 7:54 AM, Ryan Dewell <ryan at dewell.org> wrote:
> >
> > Playing around at the moment, and missing something about the threading
> > situation as it pertains to sending events.
> >
> > In my ServerSentEventConnectionCallback:
> >
> > public void connected(ServerSentEventConnection connection, String
> > lastEventId) {
> > try {
> > for (int i = 0; i<10; i++){
> > connection.send("i="+i);
> > Thread.sleep(1000);
> > }
> > } catch (Exception e) {
> > throw new RuntimeException(e);
> > }
> > }
> >
> > Sending events, with one second between each.
> >
> > I’d expect the time between events to be reflected in the browser / client.
> > However what instead happens is all 10 events arrive within the same
> > millisecond (nanoseconds apart according to Chrome console time).
> >
> > So I’m missing something here. But I don’t see anything obvious. For
> > example, there is nothing like a “flush()” on ServerSentEventConnection that
> > could be used after each event is sent.
> >
> > Ideas/guidance?
> >
> > Thanks!
> >
> > Ryan
> >
> >
> > _______________________________________________
> > undertow-dev mailing list
> > undertow-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/undertow-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20170502/e2e2c413/attachment-0001.html 


More information about the undertow-dev mailing list