title: Notification system with p:poll/push
body: <p>I've tried to implement the basic notification system for a basic social network with <code>p:poll</code> on view layer and a simple <code>NotificationService</code> class which gets the new notifications from DB and refreshes the notifications list of <code>NotificationBean</code> which is viewscoped for each user. Process flow similar to this:</p>
  
  <pre><code>-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
  </code></pre>
  
  <p>But the concern of <code>p:poll</code> is about it's performance because it sends a query at every interval expiration.</p>
  
  <p>PrimeFaces has <a href="http://www.primefaces.org/showcase/push/index.jsf" rel="noreferrer">PrimePush</a> which based on Atmosphere Framework, it opens web-sockets and seems like more suitable for creating notifications system.</p>
  
  <p>But I don't know which components and which properties of them should be used. It has <code>p:socket</code> component with <code>channel</code> property. Should I use usernames as a <code>channel</code> values? Below code coming from PrimeFaces showcase and summarizes the last sentences:</p>
  
  <pre><code>&lt;p:socket onMessage="handleMessage" channel="/notifications" /&gt; 
  </code></pre>
  
  <p>As far as I understood from <a href="http://www.primefaces.org/showcase/push/facesmessage.jsf;jsessionid=9n9hhm0k1nb11ls01of3lla91" rel="noreferrer">this showcase example</a> this <code>p:socket</code> listens <code>notifications</code> channel. And pusher code snippet is:</p>
  
  <pre><code>PushContext pushContext = PushContextFactory.getDefault().getPushContext();       
  pushContext.push("/notifications", new FacesMessage(summary, detail));
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>pushContext.push("User2/notifications", new FacesMessage("friendship request", "from User1"));
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks for helping. </p>