Push with threads

UI Components for JSF
Post Reply
mikegates
Posts: 3
Joined: 30 Oct 2013, 09:21

30 Oct 2013, 09:25

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.
PrimeFaces 3.5, atmosphere-runtime-2.0.3.jar, apache-tomee-jaxrs-1.5.2

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

30 Oct 2013, 18:54

do you see 'default' in your code below? did you look at the source code for getDefault()?

Code: Select all

PushContextFactory.getDefault().getPushContext().push("/Events", "");
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.

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;
    }

    ...

}
the application scoped bean references the pushcontext of the session info POJO, e.g. the method below; look for session.getPushContext() below.

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));
            }
        }
    }
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? :)
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

mikegates
Posts: 3
Joined: 30 Oct 2013, 09:21

31 Oct 2013, 08:31

Thanks.

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", "");
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.
PrimeFaces 3.5, atmosphere-runtime-2.0.3.jar, apache-tomee-jaxrs-1.5.2

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

31 Oct 2013, 09:48

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.
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

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

04 Nov 2013, 14:25

@mike, followup to this,
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.
I just clicked the atmosphere-mail-list-topics-search URL, above, and found some related topics there, including this topic below,

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

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 17 guests