I tried to implement a basic notification system for a basic social network with p:poll at the presentation level and a simple NotificationService class that receives new notifications from the database and updates the NotificationBean notification list, which is viewcoped for each user. The process flow is similar to this:
-Poll calls NotificationBean.getNewNotifications for example every 15 sec. --getNewNotifications calls NotificationService and DAO methods ---notificationList of user is refreshed ----DataTable on view layer shows new notifications
But the p:poll problem is performance because it sends a request every time the interval expires.
PrimeFaces has PrimePush , which is based on the Atmosphere Framework, it opens web sockets and seems more suitable for creating a notification system.
But I do not know what components and what their properties should be used. It has a p:socket component with a channel property. Should I use usernames as channel values? Below is the code coming from the PrimeFaces storefront and summarizes the latest offers:
<p:socket onMessage="handleMessage" channel="/notifications" />
As far as I understood from this example showcase , this p:socket listens on the notifications channel. And the pusher code snippet:
PushContext pushContext = PushContextFactory.getDefault().getPushContext(); pushContext.push("/notifications", new FacesMessage(summary, detail));
But this will notify all user pages, I need a pusher that notifies a specific user. Let's say there are 2 users, and suppose User1 adds User2 as a friend. Must be pcs. eg:
pushContext.push("User2/notifications", new FacesMessage("friendship request", "from User1"));
But I'm not sure if this is the right use for this kind of functional requirement or not. Given the scalability of the application, there can be a costly cost to open as many channels in the process.
Thanks for the help.
jsf jsf-2 primefaces
รmer Faruk Almalฤฑ Apr 09 '13 at 13:52 2013-04-09 13:52
source share