EJB 和 AJAX 中观察者模式的使用

发布于 2024-07-14 13:57:04 字数 225 浏览 7 评论 0原文

我想构建一个 Ajax gui,它会在我的 ejb 应用程序中发生的任何状态更改时收到通知。 为了实现这个目标,我想构建一个有状态的 ejb (3.0),它实现 Observable 接口,Ajax 客户端作为观察者添加到该接口中。 首先,这可以通过 Ajax 实现吗? 如果是,这是一个好的设计理念还是有更合适的方法来做到这一点?

提前致谢!

干杯,

安德烈亚斯

I want to build an Ajax gui, that is notified on any state changes happening in my ejb application. To achieve this, I thought I build an stateful ejb (3.0) that implements the Observable interface to which the Ajax client is added as an observer.
First, is this possible with Ajax. If yes, is this a good design idea or is there a more propriate way to do this?

Thanks in advance!

Cheers,

Andreas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千と千尋 2024-07-21 13:57:04

听起来您对“反向 Ajax”感兴趣,当服务器端发生事件时,客户端会收到通知。 这与标准 Ajax 不同,标准 Ajax 会根据某些客户端操作将异步事件发送到服务器。 反向 Ajax 是可能的,DWR 是一个能够很好地实现这一点并简化底层复杂性的框架。

http://directwebremoting.org/dwr/reverse-ajax

您需要阅读无论您使用哪种框架,都可以根据您的预期负载、webapp 容器等来了解各种实施方式对性能的影响。

至于这是否是好的做法,这实际上取决于您的应用程序。 如果将近乎实时的数据推送回客户端很重要,并且您不想使用 Flex 或其他较重的框架之类的东西,那么我会说您走在正确的道路上。 如果数据不需要是实时的,或者如果您的负载非常高,那么也许更简单的方法(例如计划页面刷新)将为您节省一些复杂性并有助于提高性能。

It sounds like you are interested in 'Reverse-Ajax', where the client is notified when an event happens server side. This is different than standard Ajax, where an asynchronous event is sent to the server based on some client action. Reverse Ajax is possible, and one framework that does a very good job of allowing this is and simplifying the underlying complexity is DWR.

http://directwebremoting.org/dwr/reverse-ajax

You'll want to read up on the performance implications of the various ways to implement based on your expected load, webapp container, etc. regardless of which framework you use.

As for whether or not it is good practice, that really depends on your application. If it is important to get near-real time data pushed back to the client and you don't want to use something like Flex or other heavier frameworks, then I'd say you are on the right track. If the data does not need to be real time, or if your load is extremely high, then perhaps a more simple approach like a scheduled page refresh will save you some complexity and help with performance.

一个人的夜不怕黑 2024-07-21 13:57:04

现在,一段时间后,您的问题可能会有一个新的答案:Websockets 的使用

来自之前的 链接网站< /a> by Pete:“网络的设计初衷并不是允许网络服务器与网络浏览器建立连接......”现在 HTML5 正在改变这种情况。

http://en.wikipedia.org/wiki/WebSockets

Now, some time later there is a new possible answer to your question: Usage of Websockets

From the previously linked website by Pete: "The web was not designed to allow web servers to make connections to web browsers..." That is changing now with html5.

http://en.wikipedia.org/wiki/WebSockets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文