问题描述
我有一个广泛分布的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.
我的问题是:
- 什么是最好的技术( push)将此数据字符串通知分发给我的客户?
- 我应该如何对数据库进行验证,以了解是否已查看通知? (所以我可以停止在客户端上显示新通知)
或者是否有对指南的引用这会非常好用,我找不到。
我的想法:
- 让客户端每隔10分钟调用一次web服务来检查是否有新的通知
- 对于数据库,创建一个通知表并看到通知。将我的用户表链接到通知看表。看到的通知是非常基本的,只有3列:NotificationID,UserID,TimeSeen。
推荐答案
一个模拟推送通知的方法是。这种
技术称为。虽然在基于REST的服务中它更常见
,但它可以在
JAX-WS中轻松完成。
One way of simulating push notifications is long polling. Thistechnique is called Comet or Reverse AJAX. While it's more commonin REST based services, it can be just as easily accomplished inJAX-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
使用长轮询,您可以立即建立初始客户端连接
。但是,不是服务器立即响应,而是将
挂起到连接上(异步)。然后,当通知需要推送
时,它会回复现有连接。
Instead with long polling, you make the initial client connectionright away. But instead of the server responding immediately, it hangsonto the connection (asynchronously). Then when a notification needsto be pushed, it responds back on the existing connection.
使用此技术,只要$ b上有信息可用$ b服务器,它将被推送到客户端。
With this technique, as soon as information is available on theserver, it will be "pushed" to the client.
听起来不错。将其公开为JAX-WS服务。当客户收到消息
时,请让他们使用NotificationID调用它。
Sounds good. Expose it as a JAX-WS service. When the client receivesthe 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客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!