如何在GlassFish上从JAX-WS构建推送通知到Swing客户端? [英] How to architect push notifications to a Swing client from JAX-WS on GlassFish?

查看:159
本文介绍了如何在GlassFish上从JAX-WS构建推送通知到Swing客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个广泛分布的java swing应用程序,它是来自Glassfish 3.1.2服务器上的JAX WebService EJB的Web服务客户端。

I have a widely distributed java swing application that is a web service client from a JAX WebService EJB on a Glassfish 3.1.2 server.

我希望能够将String通知分发给所有保持活动状态的用户,直到他们读取它为止。通知只需要存在于Swing客户端中。

I want to be able to distribute a String notification to all users that stays active until they have read it. The notifications only need to exist within the Swing client.

我创建了一个超级用户Web门户,用于输入String数据并将其保存到数据库中。

I have created a superuser web portal to enter the String data and save it to a database.

我的问题是


  1. 什么是最好的技术( push)将此数据字符串通知分发给我的客户?

  2. 我应该如何对数据库进行验证,以了解是否已查看通知? (所以我可以停止在客户端上显示新通知)

或者是否有对指南的引用这会非常好用,我找不到。

我的想法:


  • 让客户端每隔10分钟调用一次web服务来检查是否有新的通知

  • 对于数据库,创建一个通知表并看到通知。将我的用户表链接到通知看表。看到的通知是非常基本的,只有3列:NotificationID,UserID,TimeSeen。

推荐答案

一个模拟推送通知的方法是长轮询。这种
技术称为 Comet或Reverse AJAX 。虽然在基于REST的服务中它更常见
,但它可以在
JAX-WS中轻松完成。

One way of simulating push notifications is long polling. This technique is called Comet or Reverse AJAX. While it's more common in REST based services, it can be just as easily accomplished in JAX-WS.

对于JAX-WS,你将会想调查:

For JAX-WS you will want to investigate:

  • asynchronous web service invocation
  • JAX-WS client APIs ... Using the JAX-WS asynchronous programming model

让客户每10分钟拨打一次网络服务,检查是否有新通知

Have the client call a webservice every 10 minutes to check if there are any new notifications

使用长轮询,您可以立即建立初始客户端连接
。但是,不是服务器立即响应,而是将
挂起到连接上(异步)。然后,当通知需要推送
时,它会回复现有连接。

Instead with long polling, you make the initial client connection right away. But instead of the server responding immediately, it hangs onto the connection (asynchronously). Then when a notification needs to be pushed, it responds back on the existing connection.

使用此技术,只要$ b上有信息可用$ b服务器,它将被推送到客户端。

With this technique, as soon as information is available on the server, it will be "pushed" to the client.


为数据库创建一个通知表和通知。将我的用户表链接到通知看表。看到的通知是非常基本的,只有3列:NotificationID,UserID,TimeSeen。

For the database create a notification table and notifications seen. Link my users table to notifications seen table. Notifications seen is very basic with just 3 columns: NotificationID, UserID, TimeSeen.

听起来不错。将其公开为JAX-WS服务。当客户收到消息
时,请让他们使用NotificationID调用它。

Sounds good. Expose it as a JAX-WS service. When the client receives the message, have them invoke it with the NotificationID.

类似于:

NotificationService svc = ...;
UserId userId = ...;

AsyncHandler<Notification> handler = new AsyncHandler<Notification>()
{
    public void handleResponse (Response<Notification> response)
    {
       Notification notification = response.get();

       // update swing gui

       NotificationID notificationId = notifcation.getId();

       svc.markNotificationAsSeen(userId, notificationId);

       // continue polling forever (or put in some logic to stop)
       svc.getNotificationAsync(userId, this);
    }
};

Future<?> invocation = svc.getNotificationAsync(userId, handler);

这篇关于如何在GlassFish上从JAX-WS构建推送通知到Swing客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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