[ https://issues.jboss.org/browse/RF-12072?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12678906#comment-12678906 ]
Lukáš Fryč commented on RF-12072: --------------------------------- Hey Stian, I have imported your sample, just little modified the bean to get some debugging output: {code:Java} @SessionScoped @ManagedBean public class RichBean { private AtomicInteger count = new AtomicInteger(0); public int getCount() { int c = count.get(); System.out.println("getCount - start " + c); new Thread() { public void run() { try { Thread.sleep(5000); count.incrementAndGet(); TopicKey topicKey = new TopicKey("chat"); TopicsContext topicsContext = TopicsContext.lookup(); System.out.println("push " + count.get()); topicsContext.publish(topicKey, ""); } catch (Exception e) { e.printStackTrace(); } }; }.start(); if (c > 0) { try { Thread.sleep(10000); } catch (InterruptedException e) { } } System.out.println("getCount - end " + c); return c; } } {code} Now, the output from server is: {code} 11:39:33,582 INFO [stdout] (Thread-28) push 1 11:39:33,634 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 1 11:39:38,635 INFO [stdout] (Thread-29) push 2 11:39:43,635 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 1 11:39:43,660 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 2 11:39:48,661 INFO [stdout] (Thread-30) push 3 11:39:53,661 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 2 11:39:53,681 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 3 11:39:58,686 INFO [stdout] (Thread-31) push 4 11:40:03,686 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 3 11:40:03,717 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 4 11:40:08,720 INFO [stdout] (Thread-32) push 5 11:40:13,720 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 4 11:40:13,744 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 5 11:40:18,745 INFO [stdout] (Thread-33) push 6 11:40:23,744 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 5 11:40:23,768 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 6 11:40:28,769 INFO [stdout] (Thread-34) push 7 11:40:33,769 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 6 11:40:33,796 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 7 11:40:38,797 INFO [stdout] (Thread-35) push 8 11:40:43,797 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 7 11:40:43,820 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 8 11:40:48,821 INFO [stdout] (Thread-36) push 9 11:40:53,821 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 8 11:40:53,841 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 9 11:40:58,842 INFO [stdout] (Thread-37) push 10 11:41:03,842 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 9 11:41:03,862 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 10 11:41:08,863 INFO [stdout] (Thread-38) push 11 11:41:13,863 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 10 11:41:13,889 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 11 11:41:18,890 INFO [stdout] (Thread-39) push 12 11:41:23,889 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 11 11:41:23,911 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 12 11:41:28,912 INFO [stdout] (Thread-40) push 13 11:41:33,912 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 12 11:41:33,937 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 13 11:41:38,938 INFO [stdout] (Thread-41) push 14 11:41:43,938 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 13 11:41:43,961 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 14 11:41:48,961 INFO [stdout] (Thread-42) push 15 11:41:53,961 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 14 11:41:53,982 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 15 11:41:58,982 INFO [stdout] (Thread-43) push 16 11:42:03,982 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 15 11:42:03,993 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 16 11:42:08,994 INFO [stdout] (Thread-44) push 17 11:42:13,993 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 16 11:42:14,026 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 17 11:42:19,027 INFO [stdout] (Thread-45) push 18 11:42:24,027 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 17 11:42:24,050 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 18 {code} The AJAX re-render is actually done each 10 seconds, thus it returns stale value, but that's completely expected behavior since the {{getCount}} needs to wait for returning previous value (it's JSF requirement- only one AJAX request at time). When we comment the {{Thread.sleep(10000);}} we get: {code} 11:43:13,067 INFO [stdout] (Thread-50) push 1 11:43:13,123 INFO [stdout] (http--0.0.0.0-8080-3) getCount - start 1 11:43:13,124 INFO [stdout] (http--0.0.0.0-8080-3) getCount - end 1 11:43:18,136 INFO [stdout] (Thread-51) push 2 11:43:18,167 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 2 11:43:18,174 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 2 11:43:23,180 INFO [stdout] (Thread-52) push 3 11:43:23,203 INFO [stdout] (http--0.0.0.0-8080-4) getCount - start 3 11:43:23,203 INFO [stdout] (http--0.0.0.0-8080-4) getCount - end 3 11:43:28,205 INFO [stdout] (Thread-53) push 4 11:43:28,225 INFO [stdout] (http--0.0.0.0-8080-3) getCount - start 4 11:43:28,247 INFO [stdout] (http--0.0.0.0-8080-3) getCount - end 4 11:43:33,254 INFO [stdout] (Thread-54) push 5 11:43:33,277 INFO [stdout] (http--0.0.0.0-8080-3) getCount - start 5 11:43:33,278 INFO [stdout] (http--0.0.0.0-8080-3) getCount - end 5 {code} > Lost event in push > ------------------ > > Key: RF-12072 > URL: https://issues.jboss.org/browse/RF-12072 > Project: RichFaces > Issue Type: Bug > Security Level: Public(Everyone can see) > Components: component-push/poll > Reporter: Stian Thorgersen > Assignee: Lukáš Fryč > > Event can be lost if produced while a response is being prepared. I've > attached an example where a push event is used to refresh a count whenever an > event is fired. It's using Thread.sleep to simulate an event being produced > while the response is being prepared. Note, if the sleep just before > returning the count is removed it all works fine, and the page is refreshed > every 5 seconds, but with the sleep in place the event is lost. > View: > {code} > <?xml version="1.0" encoding="utf-8"?> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB" > xmlns:f="http://java.sun.com/jsf/core" > xmlns:h="http://java.sun.com/jsf/html" > xmlns:a4j="http://richfaces.org/a4j" > xmlns:rich="http://richfaces.org/rich"> > <h:head> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> > </h:head> > <h:body> > <h:form id="myForm"> > <a4j:push address="chat"> > <a4j:ajax event="dataavailable" render="count" /> > </a4j:push> > <h:outputText value="#{myBean.count}" id="count" /> > </h:form> > </h:body> > </html> > {code} > Bean: > {code} > package com.example; > import java.io.Serializable; > import java.util.concurrent.atomic.AtomicInteger; > import javax.enterprise.context.SessionScoped; > import javax.inject.Named; > import org.richfaces.application.push.TopicKey; > import org.richfaces.application.push.TopicsContext; > @Named > @SessionScoped > public class MyBean implements Serializable > { > private AtomicInteger count = new AtomicInteger(); > public int getCount() > { > int c = count.get(); > new Thread() > { > public void run() > { > try > { > Thread.sleep(5000); > count.incrementAndGet(); > TopicKey topicKey = new TopicKey("chat"); > TopicsContext topicsContext = TopicsContext.lookup(); > topicsContext.publish(topicKey, ""); > } > catch (Exception e) > { > e.printStackTrace(); > } > }; > }.start(); > > try > { > Thread.sleep(10000); > } > catch (InterruptedException e) > { > } > return c; > } > } > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira _______________________________________________ richfaces-issues mailing list richfaces-issues@lists.jboss.org https://lists.jboss.org/mailman/listinfo/richfaces-issues