I use Primefaces 3.5 and atmosphere-runtime-1.1.0-RC4.jar. In a single threaded code, when I do a primefaces push, it works fine. I'm able to see live results. But, in a multi threaded code, doesn't work. The code looks like the one below.
#main
Thread t = new Thread(Runnable obj);
t.start()
#run() method
PushContextFactory.getDefault().getPushContext().push("/Events", ""); //Doesn't work
Is there a limitation where the push doesn't work if executed from within a spawn thread? Thanks.
Push with threads
-
- Posts: 6144
- Joined: 10 Sep 2011, 21:10
do you see 'default' in your code below? did you look at the source code for getDefault()?
maybe the 'default' instance of push context is locked by one thread, and other threads cannot use/access the default instance.
in my app, i created an imitiation session object/POJO and added PushContext to the session info POJO. read the comments in the code below and look at how I instantiate a new push context impl for each instance of the POJO.
the application scoped bean references the pushcontext of the session info POJO, e.g. the method below; look for session.getPushContext() below.
does or will something like this work for/in your app?
i shared this code already in this forum. do you search and read every topic in forum?
Code: Select all
PushContextFactory.getDefault().getPushContext().push("/Events", "");
in my app, i created an imitiation session object/POJO and added PushContext to the session info POJO. read the comments in the code below and look at how I instantiate a new push context impl for each instance of the POJO.
Code: Select all
import org.primefaces.push.PushContext;
import org.primefaces.push.PushContextImpl;
public class SessionInfo {
/*
* org.primefaces.push.PushContextFactory did the following:
*
private final PushContext pushContext;
private PushContextFactory() {
pushContext = new PushContextImpl();
}
*
* so, we will create pushContext per sessionInfo class (smiling)
*/
private final PushContext pushContext = new PushContextImpl();
...
public SessionInfo() {
}
...
public PushContext getPushContext() {
return pushContext;
}
...
}
Code: Select all
/*
* 1. do NOT send to the user 'session' that is pushing the notification
* 2. do NOT send to users logged in via mobile devices
*/
public void pushNotification(String msg, Users userPushingMessage) {
Boolean sendToUser;
for (SessionInfo session : sessions) {
sendToUser = true;
if (userPushingMessage != null &&
session.getUser().getUserName().equals(userPushingMessage.getUserName()) &&
session.getUser().getLastLoginDt().equals(userPushingMessage.getLastLoginDt())) {
sendToUser = false;
}
else if (session.getUser().getLoggedInViaMobile().equals('Y')) {
sendToUser = false;
}
if (sendToUser) {
session.getPushContext().push("/" + session.getPushChannelId(),
new FacesMessage(FacesMessage.SEVERITY_INFO, "", msg));
}
}
}
i shared this code already in this forum. do you search and read every topic in forum?
Howard
PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome
Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache
PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome
Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache
Thanks.
In my run(), I've the following. But, it still doesn't work.
Am I missing something or is there an alternate way to fix this?
I did went through a lot of posts (by searching keywords) and might have missed this.
In my run(), I've the following. But, it still doesn't work.
Code: Select all
private final PushContext pushContext = new PushContextImpl();
pushContext.push("/Events", "");
I did went through a lot of posts (by searching keywords) and might have missed this.
PrimeFaces 3.5, atmosphere-runtime-2.0.3.jar, apache-tomee-jaxrs-1.5.2
-
- Posts: 6144
- Joined: 10 Sep 2011, 21:10
1. do you see my signature, below? add a signature to your user profile, and let us know your test/development and production environment
2. i searched google for
site:forum.primefaces.org thread runnable pushcontext
and found
Embedded Jetty + primepush = not working
is your code + environment similar to that?
3. i searched atmosphere framework google groups mail list for
thread runnable
and i see search results there; you need to 'study' atmosphere framework wiki page and read as many of those search results as possible until you learn how to solve your issue. you can ask your question there too, but please come back here and reply with your code/configuration changes which solves your issue and meet your requirement.
2. i searched google for
site:forum.primefaces.org thread runnable pushcontext
and found
Embedded Jetty + primepush = not working
is your code + environment similar to that?
3. i searched atmosphere framework google groups mail list for
thread runnable
and i see search results there; you need to 'study' atmosphere framework wiki page and read as many of those search results as possible until you learn how to solve your issue. you can ask your question there too, but please come back here and reply with your code/configuration changes which solves your issue and meet your requirement.
Howard
PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome
Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache
PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome
Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache
-
- Posts: 6144
- Joined: 10 Sep 2011, 21:10
@mike, followup to this,
Atmosphere + primefaces push + threads not working
when I 'first' saw this topic, posted a few days ago, I thought it was your topic, but I just realized that Ryan != Mike.
i responded to that topic on atmosphere google groups. take a look, and respond here or on that topic.
I just clicked the atmosphere-mail-list-topics-search URL, above, and found some related topics there, including this topic below,smithh032772 wrote:3. i searched atmosphere framework google groups mail list for
thread runnable
and i see search results there; you need to 'study' atmosphere framework wiki page and read as many of those search results as possible until you learn how to solve your issue. you can ask your question there too, but please come back here and reply with your code/configuration changes which solves your issue and meet your requirement.
Atmosphere + primefaces push + threads not working
when I 'first' saw this topic, posted a few days ago, I thought it was your topic, but I just realized that Ryan != Mike.
i responded to that topic on atmosphere google groups. take a look, and respond here or on that topic.
Howard
PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome
Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache
PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome
Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache
-
- Information
-
Who is online
Users browsing this forum: No registered users and 17 guests