[
https://issues.jboss.org/browse/RF-12072?page=com.atlassian.jira.plugin.s...
]
Stian Thorgersen commented on RF-12072:
---------------------------------------
By wrapping "Thread.sleep(10000);" with "if (c > 0)" the example
doesn't work, as you allow the page to be rendered fully before the first event is
sent, hence bypassing the problem.
In my application I use the push component to refresh the views when new data is
available. The application allows users to "add/change" data asynchronously, so
the data may be already changed when the model values are updated, or it may be changed
later. In certain situations, especially when the server is running on a slow machine, the
client can miss the update events altogether:
* Client presses commandButton
* Asynchronous change to data started
* JSF model values updated
* Data updated + update event is fired
* Page is viewed in browser, but update event is lost
It works fine in either of the following scenarios:
* Client presses commandButton
* Asynchronous change to data started
* Data updated + update event is fired
* JSF model values updated (missed event isn't a problem as data is changed before
model values are updated)
* Page is viewed in browser
and:
* Client presses commandButton
* Asynchronous change to data started
* JSF model values updated
* Page is viewed in browser
* Data updated + update event is fired (page is refreshed by push component and new values
are retrieved from server)
The example tries to force the first scenario where the data is lost by making sure the
page is viewed after the event is fired.
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