I've tried to implement the basic notification system for a basic social network with p:poll
on view layer and a simple NotificationService
class which gets the new notifications from DB and refreshes the notifications list of NotificationBean
which is viewscoped for each user. Process flow 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 concern of p:poll
is about it's performance because it sends a query at every interval expiration.
PrimeFaces has PrimePush which based on Atmosphere Framework, it opens web-sockets and seems like more suitable for creating notifications system.
But I don't know which components and which properties of them should be used. It has p:socket
component with channel
property. Should I use usernames as a channel
values? Below code coming from PrimeFaces showcase and summarizes the last sentences:
<p:socket onMessage="handleMessage" channel="/notifications" />
As far as I understood from this showcase example this p:socket
listens notifications
channel. And pusher code snippet is:
PushContext pushContext = PushContextFactory.getDefault().getPushContext();
pushContext.push("/notifications", new FacesMessage(summary, detail));
But this will notify all user pages, I need a pusher which notifies specific user. Let say there are 2 users and assume that User1 adds User2 as a friend. There must be sth. like that:
pushContext.push("User2/notifications", new FacesMessage("friendship request", "from User1"));
But I am not sure this is the correct usage for this kind of functional requirement or not. Considering scalability of the app there can be expensive cost of opening so many channels per a process.
Thanks for helping.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…