<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Ah, now I get it. &#160;I was thinking of “connected” in the wrong way. &#160;Thank you!
<div><br /></div>
<div>Ryan</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On May 1, 2017, 9:43 PM -0600, Stuart Douglas &lt;sdouglas@redhat.com&gt;, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">If you want to use a pattern like that you can create another thread<br />
inside the connected() method.<br />
<br />
In general though blocking a thread is not a great way to handle this<br />
as you need one thread per connection. You would generally register<br />
the created endpoint somewhere in connected, and then whenever an<br />
event is generated send the message from whatever thread generated the<br />
event.<br />
<br />
Stuart<br />
<br />
On Tue, May 2, 2017 at 11:19 AM, Ryan Dewell &lt;ryan@dewell.org&gt; wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">OK, on connected I could send say the 10 “events” which occurred since<br />
“lastEventId”.<br />
<br />
Once the connection has been established/connected, where do I send the next<br />
N events, that maybe occur minutes after the initial “connected”.<br />
<br />
In my mind I thought this all occurred inside “connected”. Meaning<br />
connected would wait until some new events were available, send those, ad<br />
infinitum.<br />
<br />
Thanks,<br />
<br />
Ryan<br />
<br />
<br />
On May 1, 2017, 6:20 PM -0600, Stuart Douglas &lt;sdouglas@redhat.com&gt;, wrote:<br />
<br />
When you send you are blocking the IO thread, so the events don't<br />
actually get put on the wire till the IO thread returns.<br />
<br />
Stuart<br />
<br />
On Tue, May 2, 2017 at 7:54 AM, Ryan Dewell &lt;ryan@dewell.org&gt; wrote:<br />
<br />
Playing around at the moment, and missing something about the threading<br />
situation as it pertains to sending events.<br />
<br />
In my ServerSentEventConnectionCallback:<br />
<br />
public void connected(ServerSentEventConnection connection, String<br />
lastEventId) {<br />
try {<br />
for (int i = 0; i&lt;10; i++){<br />
connection.send("i="+i);<br />
Thread.sleep(1000);<br />
}<br />
} catch (Exception e) {<br />
throw new RuntimeException(e);<br />
}<br />
}<br />
<br />
Sending events, with one second between each.<br />
<br />
I’d expect the time between events to be reflected in the browser / client.<br />
However what instead happens is all 10 events arrive within the same<br />
millisecond (nanoseconds apart according to Chrome console time).<br />
<br />
So I’m missing something here. But I don’t see anything obvious. For<br />
example, there is nothing like a “flush()” on ServerSentEventConnection that<br />
could be used after each event is sent.<br />
<br />
Ideas/guidance?<br />
<br />
Thanks!<br />
<br />
Ryan<br />
<br />
<br />
_______________________________________________<br />
undertow-dev mailing list<br />
undertow-dev@lists.jboss.org<br />
https://lists.jboss.org/mailman/listinfo/undertow-dev<br /></blockquote>
</blockquote>
</div>
</body>
</html>