如何为webapp创建客户端通知服务,还是应该使用Observer Pattern? [英] How to create a client notification service for a webapp or should I use an Observer Pattern?

查看:96
本文介绍了如何为webapp创建客户端通知服务,还是应该使用Observer Pattern?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完全实现的DAO,所有的bean都继承了一个Entity对象。
现在,我想创建一个客户端通知系统,当用户创建/更新/删除持久存储的实体时,通过电子邮件将自动发送通知给客户端。



我有一个DAO经理使用工厂模式根据实体类型返回给我一个DAO的经理。

 例如EntityManager manager = EntityManagerFactory.createEntityManager(Product.class);每个经理都有一个create(),remove(),update()方法.... 





我的第一个想法是让我所有的实体经理继承一个Observer接口,并在函数调用(创建,删除,更新等)后发送通知。 p>

这是一个明智的主意吗?如果没有,我可以做什么来发送通知给客户端?



我正在运行JBoss 5或Tomcat 6(或两者兼容部署)和Apache Struts (虽然我没有看到我提到的原因)。



提前感谢

解决方案

考虑使用装饰模式,让您的实体经理仍然幸福地不知道谁需要被通知和如何发送他们的电子邮件。这种方法将改善现有的管理员代码和您打算编写的消息代码的维护,如果您需要编写新的实体管理员,将您的实体存储在JCR中,或者通过Web服务等进行转发,将会得到很大的回报。 / p>

I have a fully implemented DAO and all my beans inherit an Entity object. Now, I want to create a client notification system whereby, when a user creates/updates/delete an entity to/from a persistence storage, a notification is automatically sent to the client via email.

I have a DAO manager that uses a Factory Pattern to return to me a manager of the DAO based on the entity type.

e.g EntityManager manager = EntityManagerFactory.createEntityManager(Product.class);

each manager has a create(), remove(), update() method....

My first idea is to have all my entity managers inherit an Observer interface and after the function calls (create, remove, update, etc.) a notification is sent.

Is that a wise idea? If not, what can I do in order to send a notification to client?

I'm running JBoss 5 or Tomcat 6 (or both for easy deployment) and Apache Struts (though I don't see the reason why I mentioned it).

Thanks in advance.

解决方案

Consider using a decorator pattern to allow your entity managers to remain blissfully unaware of who needs to be notified and how to send them emails. This approach will improve maintenance of both the existing manager code and the messaging code you intend to write, and will pay off hugely if you ever need to write new entity managers what store your entities in JCR or tranmit them via web services, etc.

这篇关于如何为webapp创建客户端通知服务,还是应该使用Observer Pattern?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆