相关疑难解决方法(0)

带p:poll/push的通知系统

我已经尝试为具有p:poll视图层的基本社交网络和一个简单的NotificationService类实现基本通知系统,该类从DB获取新通知并刷新通知列表,NotificationBean其中每个用户都是视图编组.与此类似的流程:

-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
Run Code Online (Sandbox Code Playgroud)

但关注的p:poll是它的性能,因为它在每个间隔到期时发送一个查询.

PrimeFaces有PrimePush,基于Atmosphere Framework,它打开网络套接字,似乎更适合创建通知系统.

但我不知道应该使用哪些组件和属性.它有属性的p:socket组件channel.我应该使用用户名作为channel值吗?以下来自PrimeFaces的代码展示并总结了最后的句子:

<p:socket onMessage="handleMessage" channel="/notifications" /> 
Run Code Online (Sandbox Code Playgroud)

据我所知,从这个展示示例中,这会p:socket监听notifications频道.推送代码片段是:

PushContext pushContext = PushContextFactory.getDefault().getPushContext();       
pushContext.push("/notifications", new FacesMessage(summary, detail));
Run Code Online (Sandbox Code Playgroud)

但这会通知所有用户页面,我需要一个通知特定用户的推送器.假设有2个用户并假设User1将User2添加为朋友.必须有某事.像那样:

pushContext.push("User2/notifications", new FacesMessage("friendship request", "from User1"));
Run Code Online (Sandbox Code Playgroud)

但我不确定这是否是这种功能要求的正确用法.考虑到应用程序的可扩展性,每个进程打开如此多的通道可能会产生昂贵的成本.

谢谢你的帮助.

jsf primefaces jsf-2

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

jsf ×1

jsf-2 ×1

primefaces ×1